標(biāo)題: STC32G單片機(jī)+LCD1602程序 不亂碼 [打印本頁(yè)]

作者: 崇慶陽(yáng)光    時(shí)間: 2022-8-18 16:37
標(biāo)題: STC32G單片機(jī)+LCD1602程序 不亂碼

今天剛調(diào)好的,僅供參考哈。

單片機(jī)源程序如下:

  1. #include    <stc32g.h>
  2. #include    <intrins.h>
  3. #define     MAIN_Fosc       11059200L   //定義主時(shí)鐘
  4. typedef     unsigned char   u8;
  5. typedef     unsigned int    u16;
  6. typedef     unsigned long   u32;
  7. #include    "delay.h"
  8. #include    "LCD1602.h"

  9. u8 code ma2[]={" STC32G+LCD1602"};

  10. void main(void)
  11. {
  12.           u8 i;
  13.     u8 a;        
  14.           u8 b;
  15.     P0M1 = 0x00;   P0M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口
  16.     P1M1 = 0x00;   P1M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口
  17.     P2M1 = 0x00;   P2M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口
  18.     P3M1 = 0x00;   P3M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口
  19.     P4M1 = 0x00;   P4M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口
  20.     P5M1 = 0x00;   P5M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口
  21.     P6M1 = 0x00;   P6M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口
  22.     P7M1 = 0x00;   P7M0 = 0x00;   //設(shè)置為準(zhǔn)雙向口         
  23.           WTST = 0;  //設(shè)置程序指令延時(shí)參數(shù),賦值為0可將CPU執(zhí)行指令的速度設(shè)置為最快
  24.         
  25.     LCD_INIT();          //初始化LCD
  26.         
  27.           a=0x80 + 7;          //第一行,7為第7列(第7個(gè)字符)
  28.           Write_CMD(a);
  29.           Write_Data('O');
  30.           a=0x80 + 8;          //第一行,8為第8列(第8個(gè)字符)
  31.           Write_CMD(a);
  32.           Write_Data('K');
  33.          
  34.           b=0xC0 + 0;          //第二行,0為第一列(第一個(gè)字符)
  35.           Write_CMD(b);
  36.           i=0;
  37.           while(ma2[i] != '\0')
  38.                 {
  39.     Write_Data(ma2[i]);
  40.                 i++;                 //第二行止。
  41.                 }
  42.                
  43.           while(1);
  44. }
復(fù)制代碼

Keil代碼下載:
STC32G LCD1602顯示程序.rar (291.6 KB, 下載次數(shù): 55)





作者: 崇慶陽(yáng)光    時(shí)間: 2022-8-18 20:59
整理了一下細(xì)節(jié)。
STC32G LCD1602顯示程序.rar (291.53 KB, 下載次數(shù): 26)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1