<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 單片機寫LCD1602液晶程序源碼

          單片機寫LCD1602液晶程序源碼

          作者: 時間:2016-12-02 來源:網(wǎng)絡(luò) 收藏
          本程序的pdf格式的原理圖下載:http://www.51hei.com/f/ks51.pdf


          /***********寫1602液晶**************/
          /**
          *功能:寫1602液晶
          *時間:二〇一四年三月十五日 08:59:26
          *作者:寒竹子
          **/

          本文引用地址:http://www.ex-cimer.com/article/201612/324596.htm

          #include
          #include

          typedef unsigned int uint;
          typedef unsigned char uchar;

          //LCD1602
          sbit LCD1602_RS = P1^0;
          sbit LCD1602_RW = P1^1;
          sbit LCD1602_EN = P1^5;

          void LCD1602_Wait();
          void writeCmd_LCD1602(uchar cmd);
          void writeData_LCD1602(uchar dat);
          void LCD1602_Init();
          void writeString_LCD1602(uchar * pstr);
          void LCD1602_ShowStr(uchar x, uchar y, uchar * pstr);

          void main()
          {
          LCD1602_Init();

          /*
          writeCmd_LCD1602(0x00 | 0x80);
          writeData_LCD1602(C);

          writeString_LCD1602("Hanzhuzi");
          */
          LCD1602_ShowStr(0, 0, "han zhu ying xue");
          LCD1602_ShowStr(0, 1, "QQ:1754410821");
          while (1);
          }

          //LCD1602判忙準(zhǔn)備
          void LCD1602_Wait()
          {
          uchar sta = 0;//讀取液晶當(dāng)前狀態(tài)
          P0 = 0xFF;//讀取狀態(tài)時必須把總線拉高才能正確的讀取其狀態(tài)!否則寫入有時不成功?。?!
          LCD1602_RS = 0;
          LCD1602_RW = 1;

          do
          {
          LCD1602_EN = 1;
          sta = P0;//讀取狀態(tài)
          LCD1602_EN = 0;//避免液晶輸出數(shù)據(jù)影響到總線P0上的其他器件
          } while (sta & 0x80);//檢測第七位是否為1,若為1繼續(xù)等待直到0為止
          }

          //LCD1602寫命令
          void writeCmd_LCD1602(uchar cmd)
          {
          //在進行讀寫數(shù)據(jù)之前要進行液晶忙碌等待
          LCD1602_Wait();

          LCD1602_RS = 0;
          LCD1602_RW = 0;
          LCD1602_EN = 0;
          P0 = cmd;
          LCD1602_EN = 1;//高脈沖送入命令
          LCD1602_EN = 0;//避免液晶輸出數(shù)據(jù)影響其他的器件
          }

          //LCD1602寫數(shù)據(jù)
          void writeData_LCD1602(uchar dat)
          {
          LCD1602_Wait();

          LCD1602_RS = 1;
          LCD1602_RW = 0;
          LCD1602_EN = 0;
          P0 = dat;//送入數(shù)據(jù)
          LCD1602_EN = 1;//高脈沖
          LCD1602_EN = 0;//避免液晶輸出數(shù)據(jù)影響到其他器件
          }

          //LCD1602初始化
          void LCD1602_Init()
          {
          writeCmd_LCD1602(0x38);//5*7點陣,16*2顯示
          writeCmd_LCD1602(0x0C);//開顯示,不顯示光標(biāo)
          writeCmd_LCD1602(0x06);//數(shù)據(jù)指針++,光標(biāo)++
          writeCmd_LCD1602(0x01);//清屏
          }

          //LCD1602寫String
          void writeString_LCD1602(uchar * pstr)
          {
          while (*pstr)
          {
          writeData_LCD1602(*pstr++);
          }
          }

          //LCD1602按地址寫
          void LCD1602_ShowStr(uchar x, uchar y, uchar * pstr)
          {
          uchar addr = 0;
          //判斷RAM地址
          if (y == 0) //LCD1602的左上角地址是 (0, 0)
          {
          addr = (0x00 + x);//確定x坐標(biāo),x為偏移量
          }
          else
          {
          addr = (0x40 + x);//第二行
          }

          //寫入地址
          writeCmd_LCD1602(addr | 0x80);//地址是從0x80H開始的

          //寫入數(shù)據(jù)
          while (*pstr != 看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();