久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 12706|回復: 15
打印 上一主題 下一主題
收起左側

基于stm32f103R6 LCD12864顯示程序+Proteus仿真圖

  [復制鏈接]
跳轉到指定樓層
樓主
基于stm32f103R6 lcd12864 顯示 福利 加仿真



單片機源程序如下:

  1. #include "main.h"
  2. #include "stm32f1xx_hal.h"
  3. //#include "stm32f1xx_hal_gpio.h"

  4. #define uchar unsigned char
  5. #define uint unsigned int




  6. //#define         databus         P1
  7. #define     databus     GPIOB


  8. //sbit                 cs1 = P3^3;                   //左屏幕選擇,低電平有效
  9. #define     cs1     GPIO_PIN_3
  10. #define    set_cs1     GPIO_SetBits(GPIOC,   cs1)
  11. #define    clr_cs1     GPIO_ResetBits(GPIOC, cs1)

  12. //sbit                 cs2 = P3^4;                   //右屏幕選擇
  13. #define     cs2     GPIO_PIN_4
  14. #define    set_cs2     GPIO_SetBits(GPIOC,   cs2)
  15. #define    clr_cs2     GPIO_ResetBits(GPIOC, cs2)


  16. //sbit                 e = P3^5;                    //指令數據控制
  17. #define     e      GPIO_PIN_5
  18. #define    set_e     GPIO_SetBits(GPIOC,   e)
  19. #define    clr_e     GPIO_ResetBits(GPIOC, e)


  20. //sbit                   wr = P3^6;                    //讀寫控制
  21. #define           wr     GPIO_PIN_6
  22. #define    set_wr     GPIO_SetBits(GPIOC,   wr)
  23. #define    clr_wr     GPIO_ResetBits(GPIOC, wr)


  24. //sbit                 rs = P3^7;                    //指令數據選擇
  25. #define     rs     GPIO_PIN_7
  26. #define    set_rs     GPIO_SetBits(GPIOC,   rs)
  27. #define    clr_rs     GPIO_ResetBits(GPIOC, rs)



  28. void LcdDelay(uint time)
  29. {
  30.         while(time--);
  31. }

  32. void _NOP_(void)
  33. {
  34.     uint i = 200;
  35.     while(i > 0)
  36.                 {
  37.         i--;
  38.     }
  39. }

  40. /**********************************
  41. 寫指令
  42. **********************************/
  43. void SendCommand(uchar command)
  44. {
  45.         set_e;                 //e=1;       
  46.         clr_wr;         //wr=0;       
  47.         clr_rs;         //rs=0;       
  48.         databus->ODR = (databus->ODR & 0xff00)|command;  //databus=command;
  49.   _NOP_();
  50.         clr_e;                 //e=0;
  51.   _NOP_();
  52. }

  53. /**********************************
  54. 寫數據
  55. **********************************/
  56. void WriteData(uchar dat)
  57. {
  58.         set_e;                //e=1;
  59.         clr_wr;                //wr=0;
  60.         set_rs;                //rs=1;
  61.         databus->ODR =        (databus->ODR & 0xff00)|dat;        //databus=dat;
  62.   _NOP_();
  63.         clr_e;                //e=0;
  64.   _NOP_();
  65. }

  66. /**********************************
  67. 顯示開/關
  68. **********************************/
  69. void SetOnOff(uchar onoff)
  70. {
  71.         if(onoff==1)
  72.         {
  73.                 SendCommand(0x3f);       
  74.         }       
  75.         else
  76.         {
  77.                 SendCommand(0x3e);
  78.         }
  79. }


  80. /**********************************
  81. 選擇頁
  82. **********************************/
  83. void SetLine(uchar line)         //12864總共有8頁(0~7),每頁有8行
  84. {
  85.         line=line&0x07;                          //只取后三位xxxx x111  ,這3個是要改變位置的數據
  86.         line=line|0xb8;                          //頁設置的固定格式
  87.         SendCommand(line);
  88. }


  89. /**********************************
  90. 選擇列
  91. **********************************/
  92. void SetColum(uchar colum)        //12864每半屏有64列(0~63),分為左右2屏
  93. {
  94.         colum=colum&0x3f;         //xx11 1111,這個是要改變Y位置的數據
  95.         colum=colum|0x40;         //固定格式
  96.         SendCommand(colum);
  97. }


  98. /**********************************
  99. 選擇起始行
  100. **********************************/
  101. void SetStartLine(uchar startline)
  102. {
  103.         startline=startline&0x3f;                //xx11 1111,這個是要改變x位置的數據
  104.         startline=startline|0xc0;                //11xxxxxx,是起始行設置的固定指令
  105.         SendCommand(startline);
  106. }


  107. /**********************************
  108. 選擇左右屏                0:左屏,1:右屏,2:全屏
  109. **********************************/
  110. void SelectScreen(uchar screen)
  111. {
  112.         switch(screen)
  113.         {
  114.                 case 0:
  115.                                 clr_cs1;        //cs1=0;
  116.                                 LcdDelay(2);
  117.                                 set_cs2;        //cs2=1;
  118.                                 LcdDelay(2);
  119.                                 break;
  120.                 case 1:
  121.                                 set_cs1;        //cs1=1;
  122.                                 LcdDelay(2);
  123.                                 clr_cs2;        //cs2=0;
  124.                                 LcdDelay(2);
  125.                                 break;
  126.                 case 2:
  127.                                 clr_cs1;        //cs1=0;
  128.                                 LcdDelay(2);
  129.                                 clr_cs2;        //cs2=0;
  130.                                 LcdDelay(2);
  131.                                 break;
  132.         }
  133. }


  134. /**********************************
  135. 顯示一個英文字符
  136. **********************************/
  137. void Show_english(uchar line,uchar column,uchar *address)
  138. {
  139.         uchar i;
  140.         SetLine(line);
  141.         SetColum(column);
  142.         for(i=0;i<8;i++)
  143.         {
  144.                 WriteData(*address);
  145.                 address++;       
  146.         }
  147.        
  148.         SetLine(line+1);
  149.         SetColum(column);
  150.         for(i=0;i<8;i++)
  151.         {
  152.                 WriteData(*address);
  153.                 address++;       
  154.         }
  155. }


  156. /**********************************
  157. 清屏
  158. **********************************/
  159. void ClearScreen(uchar screen)
  160. {
  161.         uchar i,j;
  162.         SelectScreen(screen);
  163.         for(i=0;i<8;i++)
  164.         {
  165.                 SetLine(i);
  166.                 SetColum(0);
  167.                 for(j=0;j<64;j++)
  168.                 {
  169.                         WriteData(0);                       
  170.                 }       
  171.         }
  172. }

  173. /**********************************
  174. 12864初始化
  175. **********************************/
  176. void InitLcd()
  177. {
  178.         SetOnOff(0);                //顯示關
  179.         ClearScreen(2);                //清屏
  180.         SetLine(0);                        //頁設置
  181.         SetColum(0);                //列設置
  182.         SetStartLine(0);        //設置起始頁
  183.         SetOnOff(1);                //顯示開
  184. }



  185. TIM_HandleTypeDef htim1;

  186. void SystemClock_Config(void);
  187. void Error_Handler(void);
  188. static void MX_TIM1_Init(void);


  189. static void MX_GPIO_Init(void)
  190. {
  191.   GPIO_InitTypeDef GPIO_InitStruct;

  192.   __HAL_RCC_GPIOA_CLK_ENABLE();
  193.         __HAL_RCC_GPIOB_CLK_ENABLE();
  194.   __HAL_RCC_GPIOC_CLK_ENABLE();

  195.   //HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

  196.         //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
  197.   GPIO_InitStruct.Pin = GPIO_PIN_0;
  198.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  199.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  200.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  201.        
  202.         //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
  203.         GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;;
  204.         HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  205.        

  206.         //HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
  207.         GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  208.         HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  209.        
  210.        
  211. }

  212.   uchar hzk[]=
  213. {
  214. /*--  文字:  I  --*/
  215. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  216. 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

  217. /*--  文字:     --*/
  218. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  219. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  220. /*--  文字:  c  --*/
  221. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  222. 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,

  223. /*--  文字:  a  --*/
  224. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  225. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,

  226. /*--  文字:  n  --*/
  227. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  228. 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,

  229. /*--  文字:     --*/
  230. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  231. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  232. /*--  文字:  m  --*/
  233. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  234. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,

  235. /*--  文字:  a  --*/
  236. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  237. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,

  238. /*--  文字:  k  --*/
  239. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  240. 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,

  241. /*--  文字:  e  --*/
  242. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  243. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,

  244. /*--  文字:     --*/
  245. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  246. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  247. /*--  文字:  i  --*/
  248. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  249. 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

  250. /*--  文字:  t  --*/
  251. /*--  宋體12;  此字體下對應的點陣為:寬x高=8x16   --*/
  252. 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,
  253. };

  254. int main(void)
  255. {
  256.         uchar i,line,colum,j ;
  257.         uchar *address ;
  258.        
  259.   HAL_Init();

  260.   SystemClock_Config();

  261.   MX_GPIO_Init();
  262.   
  263.   while (1)
  264.   {
  265.                
  266.                 line=4;                               
  267.                 colum=0;                       
  268.                 address=hzk;               
  269.                 SetOnOff(1);               
  270.        
  271.                 for(i=0;i<13;i++)       
  272.                 {
  273.                         if(i<8)                               
  274.                         {
  275.                                 SelectScreen(0);                                                
  276.                                 Show_english(line,colum,address);               
  277.                                 address+=16;                                                         
  278.                                 colum+=8;                                                                 
  279.                         }       
  280.                         else                                                 
  281.                         {               
  282.                                 SelectScreen(1);
  283.                                 Show_english(line,colum,address);
  284.                                 address+=16;
  285.                                 colum+=8;                                               
  286.                         }
  287.                 }       
  288.                
  289.                 for(i = 0;i < 50;i ++)  LcdDelay(30000);        //延時
  290.   }
  291.   

  292. }


  293. void SystemClock_Config(void)
  294. {

  295.   RCC_OscInitTypeDef RCC_OscInitStruct;
  296.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  297.     /**Initializes the CPU, AHB and APB busses clocks
  298.     */
  299.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  300.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  301.   RCC_OscInitStruct.HSICalibrationValue = 16;
  302.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  303.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  304.   {
  305.     Error_Handler();
  306.   }

  307.     /**Initializes the CPU, AHB and APB busses clocks
  308.     */
  309.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  310.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  311.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  312.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  313.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  314.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  315.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  316.   {
  317.     Error_Handler();
  318.   }

  319.     /**Configure the Systick interrupt time
  320.     */
  321.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  322.     /**Configure the Systick
  323.     */
  324.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  325.   /* SysTick_IRQn interrupt configuration */
  326.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  327. }

  328. /* TIM1 init function */
  329. static void MX_TIM1_Init(void)
  330. {

  331.   TIM_ClockConfigTypeDef sClockSourceConfig;
  332.   TIM_MasterConfigTypeDef sMasterConfig;

  333.   htim1.Instance = TIM1;
  334.   htim1.Init.Prescaler = 0;
  335.   htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  336.   htim1.Init.Period = 0;
  337.   htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  338.   htim1.Init.RepetitionCounter = 0;
  339.   if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
  340.   {
  341.     Error_Handler();
  342.   }

  343.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  344.   if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
  345.   {
  346.     Error_Handler();
  347.   }

  348.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  349.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  350.   if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
  351.   {
  352.     Error_Handler();
  353.   }

  354. }






  355. void Error_Handler(void)
  356. {
  357.   /* USER CODE BEGIN Error_Handler */
  358.   /* User can add his own implementation to report the HAL error return state */
  359.   while(1)
  360.   {
  361.   }
  362.   /* USER CODE END Error_Handler */
  363. }

  364. #ifdef USE_FULL_ASSERT

  365. /**
  366.    * @brief Reports the name of the source file and the source line number
  367.    * where the assert_param error has occurred.
  368.    * @param file: pointer to the source file name
  369.    * @param line: assert_param error line source number
  370.    * @retval None
  371.    */
  372. void assert_failed(uint8_t* file, uint32_t line)
  373. {
  374.   /* USER CODE BEGIN 6 */
  375.   /* User can add his own implementation to report the file name and line number,
  376.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  377.   /* USER CODE END 6 */

  378. }

  379. #endif
復制代碼

所有資料51hei提供下載:
stm32_12864.7z (1.16 MB, 下載次數: 712)


評分

參與人數 1黑幣 +100 收起 理由
admin + 100 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏10 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:482998 發表于 2019-3-2 21:18 | 只看該作者
謝謝!!!!!
回復

使用道具 舉報

板凳
ID:375838 發表于 2019-3-2 22:53 | 只看該作者
能用PLL作為系統時鐘源嗎
回復

使用道具 舉報

地板
ID:527022 發表于 2019-5-4 16:09 | 只看該作者
感謝感謝
回復

使用道具 舉報

5#
ID:242969 發表于 2019-5-14 10:34 | 只看該作者
仿真呢
回復

使用道具 舉報

6#
ID:739190 發表于 2020-4-27 14:29 | 只看該作者
有仿真圖嗎
回復

使用道具 舉報

7#
ID:747496 發表于 2020-5-9 12:38 | 只看該作者
謝謝樓主,找了幾天,總算找到一個能夠仿真的
回復

使用道具 舉報

8#
ID:751363 發表于 2020-5-14 08:38 | 只看該作者
謝謝,找到了
回復

使用道具 舉報

9#
ID:766129 發表于 2020-6-1 00:36 | 只看該作者
請問有仿真圖嗎 謝謝
回復

使用道具 舉報

10#
ID:766129 發表于 2020-6-1 02:44 | 只看該作者
請問使用的是hal庫還是標準庫呢
回復

使用道具 舉報

11#
ID:302325 發表于 2020-6-1 12:04 | 只看該作者
好資料,51黑有你更精彩!!!
回復

使用道具 舉報

12#
ID:724141 發表于 2020-6-22 19:31 | 只看該作者
十分感謝,解燃眉之急
回復

使用道具 舉報

13#
ID:788533 發表于 2020-6-24 15:41 | 只看該作者
hex文件在哪里的,樓主
回復

使用道具 舉報

14#
ID:387687 發表于 2022-3-14 17:42 | 只看該作者
W1715967210 發表于 2020-6-24 15:41
hex文件在哪里的,樓主

沒有看到仿真圖。
回復

使用道具 舉報

15#
ID:1031439 發表于 2022-6-1 08:40 | 只看該作者
可以自己自定義顯示文字嗎 在哪修改
回復

使用道具 舉報

16#
ID:1031384 發表于 2022-6-2 16:13 來自手機 | 只看該作者
好資料,51黑有你更精彩!!!
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 妹子干综合 | 亚洲天堂久久 | 国产亚洲精品精品国产亚洲综合 | 国产精品免费一区二区三区四区 | av黄色在线 | 色综合一区二区三区 | 先锋资源在线 | 欧美成人精品一区二区三区 | 欧产日产国产精品99 | 视频一区二区在线观看 | 欧美日韩最新 | 日韩精品久久一区二区三区 | 在线色网| 国产精品性做久久久久久 | 色爱综合网 | 国产大片黄色 | 午夜影院普通用户体验区 | 亚洲协和影视 | 夜夜夜操 | 国产视频亚洲视频 | 久久国产婷婷国产香蕉 | 亚洲精品中文字幕 | 亚洲黄色成人网 | 91久久久久久 | 亚洲天堂中文字幕 | 成人字幕网zmw | 国产在线播 | 日韩久久精品 | www.久| 精品国产乱码久久久久久图片 | 在线观看第一页 | 国产日韩视频在线 | 91久久久久久久久 | 国产xxxx在线 | 亚洲欧美日韩成人在线 | 日本高清不卡视频 | 九九免费在线视频 | 欧美一区免费在线观看 | 在线视频一区二区三区 | 91精品国产91久久久久久 | 天堂一区 |