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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51單片機(jī)的1602驅(qū)動(dòng)程序

          51單片機(jī)的1602驅(qū)動(dòng)程序

          作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏

          /*************************************
          函數(shù)名:lcdwcmd
          函數(shù)功能:向1602中寫指令
          參數(shù):cmd(命令)
          返回:無
          備注:無
          *************************************/
          void lcdwcmd(uchar cmd)
          {
            while(lcdbusy());
            RSlcd=0;
            RWlcd=0;
            EPlcd=0;
            _nop_();
            _nop_();
            P0=cmd;
            delaynop();
            EPlcd = 1;
            delaynop();
            EPlcd = 0;
          }
          /*************************************
          函數(shù)名:lcdwdat
          函數(shù)功能:向1602中寫數(shù)據(jù)
          參數(shù):dat(數(shù)據(jù))
          返回:無
          備注:無
          *************************************/
          void lcdwdat(uchar dat)
          {
            while(lcdbusy());
            RSlcd=1;
            RWlcd=0;
            EPlcd=0;
            P0=dat;
            delaynop();
            EPlcd=1;
            delaynop();
            EPlcd=0;
          }
          /*************************************
          函數(shù)名:lcdprc
          函數(shù)功能:寫一個(gè)字符
          參數(shù):zifu(字符)
          返回:無
          備注:無
          *************************************/
          void lcdprc(uchar zifu)
          {
            lcdwdat(zifu);
          }
          /*************************************
          函數(shù)名:lcdprs
          函數(shù)功能:寫字符串
          參數(shù):zifu(字符)
          返回:無
          備注:無
          *************************************/
          void lcdprs(uchar *string)
          {
            while(*string)
            {lcdwdat(*string);string++;}
          }
          /*************************************
          函數(shù)名:lcdclear
          函數(shù)功能:清屏
          參數(shù):無
          返回:無
          備注:無
          *************************************/
          void lcdclear(void)
          {
            lcdwcmd(0x01);
          }
          /*************************************
          函數(shù)名:lcdenter
          函數(shù)功能:軟復(fù)位
          參數(shù):無
          返回:無
          備注:無
          *************************************/
          void lcdenter(void)
          {
            lcdwcmd(0x2);
          }
          /*************************************
          函數(shù)名:lcdsetxs
          函數(shù)功能:顯示設(shè)置
          參數(shù):d(顯示)c(光標(biāo))b(閃爍)
          返回:無
          備注:d=1(開顯示),d=0(關(guān)顯示)
          c=1(顯示光標(biāo)),c=0(不顯示光標(biāo))
          b=1(光標(biāo)閃爍),b=0(不閃爍)
          *************************************/
          void lcdsetxs(bit D,bit C,bit B)
          {
            unsigned char order;
            order=0x8;
            if(D)
              order=order+0x4;
            if(C)
              order=order+0x2;
            if(B)
              order=order+0x1;
            lcdwcmd(order);
          }
          /*************************************
          函數(shù)名:lcdsetim
          函數(shù)功能:左右移動(dòng)
          參數(shù):I_D(地址指針), S(整行移動(dòng))
          返回:無
          備注:I_D=1(光標(biāo)右移),I_D=0(光標(biāo)左移)
          S=1(整行左右移),S=0(整行不動(dòng))
          *************************************/
          void lcdsetim(bit I_D,bit S)
          {
            unsigned char order;
            order=0x4;
            if(I_D)
              order=order+0x2;
            if(S)
              order=order+0x1;
            lcdwcmd(order);
          }

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

          /*************************************
          函數(shù)名:lcdinit
          函數(shù)功能:初始化
          參數(shù):無
          返回:無
          備注:無
          *************************************/
          void lcdinit()
          {

            lcdwcmd(0x38);
            _nop_();
            _nop_();
            _nop_();
            _nop_();
            lcdwcmd(0x38);
            _nop_();
            _nop_();
            _nop_();
            _nop_();
            lcdwcmd(0x38);
            _nop_();
            _nop_();
            _nop_();
            _nop_();
            lcdsetxs(1,0,0);//設(shè)置輸入模式,默認(rèn)增量方式,畫面不動(dòng),光標(biāo)向右邊移動(dòng)
            lcdsetim(1,0);
            lcdwcmd(0x01);//清屏
          }

          /*************************************
          函數(shù)名:lcdsetxy
          函數(shù)功能:坐標(biāo)設(shè)置
          參數(shù):x(列數(shù)),y(行數(shù))
          返回:無
          備注:配合lcdxyprc,lcdxyprs函數(shù)使用
          列數(shù)小于39,行數(shù)小于2
          *************************************/
          void lcdsetxy(uchar X,uchar Y)
          {
          uchar Address;
          if(X>39)
             X=39;
          if (Y == 0)
           {
            Address = 0x80 + X;
          }
          else
           {
           Address = 0xc0 + X;
           }
          lcdwcmd(Address);
          }



          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁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); })();