標題: at89c51控制的lcd1602顯示 [打印本頁]

作者: 啊哈哈000    時間: 2017-5-2 22:31
標題: at89c51控制的lcd1602顯示
自己學了很長時間,功夫不負有心人,終于懂點了。




  1. #include <reg51.h>
  2. #define uint  unsigned int
  3. #define uchar unsigned char
  4. uchar code table1[]="SMILE -_-!"; //第一行需要的字符
  5. uchar code table2[]="HI,HONEY!_HYC";//第二行需要的字符
  6. sbit RS=P2^0;
  7. sbit RW=P2^1;
  8. sbit E=P2^2;
  9. void delay(uint t)//延時程序
  10. {
  11.         uint i,j;
  12.         for(i=t;i>0;i--);
  13.         for(j=110;j>0;j--);
  14. }
  15. void write_com(uchar com)//寫指令
  16. {
  17.         RS=0;
  18.         RW=0;
  19.         P0=com;
  20.         delay(5);//延時,給硬件反應時間
  21.         E=1;
  22.         delay(5);
  23.         E=0;
  24. }
  25. void write_date(uchar date)//寫數(shù)據(jù)
  26. {
  27.         RS=1;
  28.         RW=0;
  29.         P0=date;
  30.         delay(5);
  31.         E=1;
  32.         delay(5);
  33.         E=0;
  34. }
  35. void init()//LCD初始化
  36. {
  37.         E=0;
  38.         delay(15);
  39.         write_com(0x38); //設置8位格式
  40.         delay(5);       
  41.         write_com(0x38);
  42.         delay(5);
  43.         write_com(0x38); //連續(xù)3次,確保成功
  44.         delay(5);
  45.   write_com(0x0c);//設置開顯示,不顯示光標
  46.         delay(5);               
  47.   write_com(0x06);//每次寫數(shù)據(jù)后地址指針加1
  48.         delay(5);
  49.         write_com(0x01);//清屏
  50.         delay(5);
  51. }
  52. void main()//主程序
  53.         {
  54.                 uchar x,y;
  55.                 init();
  56.                 write_com(0x80);//第一行地址基數(shù)
  57.                 for(x=0;x<10;x++)
  58.                 {
  59.                         write_date(table1[x]);
  60.                         delay(5);
  61.                 }
  62.                 write_com(0xC0);//第二行地址基數(shù)
  63.                 for(y=0;y<13;y++)
  64.                 {
  65.                         write_date(table2[y]);
  66.                         delay(5);
  67.                 }
  68.                 while(1);
  69.         }
復制代碼

下載:
lcd1602.zip (34.92 KB, 下載次數(shù): 44)


作者: ptlantu    時間: 2018-6-20 14:12
學習了,感謝分享
作者: xiaofeiyang    時間: 2020-4-17 19:14
前輩可以留個聯(lián)系方式嗎




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