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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > avr單片機(jī)串行四線驅(qū)動(dòng)1602液晶

          avr單片機(jī)串行四線驅(qū)動(dòng)1602液晶

          作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
          用串口的方式來驅(qū)動(dòng)1602液晶的的優(yōu)點(diǎn)很明顯,就是串行能節(jié)約單片機(jī)有限的io口,本程序僅用四線就完成了液晶的驅(qū)動(dòng)

          示范程序很簡單,不用多注釋應(yīng)該都能看懂。作為演示用途,其中有些長時(shí)間延時(shí)沒有沒有使用定時(shí)器,在多任務(wù)系統(tǒng)中當(dāng)然要用定時(shí)中斷來代替了。
          這就是電路,細(xì)心的朋友會(huì)發(fā)現(xiàn)實(shí)物圖中有幾個(gè)貼片的阻容件,秘密就在這里,利用電容的記憶效應(yīng),把并行的數(shù)據(jù)轉(zhuǎn)為串行。

          關(guān)于本制作的更多圖解請(qǐng)打開:http://www.51hei.com/bbs/dpj-20365-1.html
          // Drive a LCD1602 with 2 wire
          //===================================================
          //ICC-AVR application builder : 2010-10-3 19:30:02
          // Target : M16
          // Crystal: 4.0000Mhz

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

          #include
          #include

          #define Set_E PORTB|=2
          #define Clr_E PORTB&=~2
          #define Set_D PORTB|=1
          #define Clr_D PORTB&=~1
          #define Set_xy(y,x) Send(0,(y<<6)|(x&15)|0x80)

          //===================================================
          void init_devices(void)
          {
          CLI(); //disable all interrupts
          DDRB = 0x03;
          MCUCR = 0x00;
          GICR = 0x00;
          SEI(); //re-enable interrupts
          }

          //===================================================
          void Delay(unsigned int i)
          {
          while(i--);
          }

          //===================================================
          void Send(unsigned char RS, unsigned char dat)
          {
          unsigned char i;
          for (i = 2; i > 0; i--)
          {
          if (dat & 0x80) Set_D; else Clr_D;
          Delay(10608);//14520us
          if (RS) Set_E;
          if (dat & 0x40) Set_D; else Clr_D;
          Delay(462); //660us
          if (dat & 0x20) Set_D; else Clr_D;
          Delay(18); //30us
          Set_E;
          if (dat & 0x10) Set_D; else Clr_D;
          _NOP(); //0.5us < t < 1.36us
          Clr_E;
          dat <<= 4;
          }
          }

          //===================================================
          void init_1602(void)
          {
          unsigned char i = 3;
          Clr_D;
          Clr_E;
          Delay(10608);
          do{
          Clr_D;
          Delay(462);
          Set_D;
          Set_E;
          Delay(18);
          if (i == 0) Clr_D;
          _NOP();_NOP();_NOP();
          Clr_E;
          }while(i--);
          Send(0,0x28);
          Send(0,0x01);
          Send(0,0x0f);
          }

          //===================================================
          void Send_S(unsigned char *p)
          {
          while(*p) Send(1,*p++);
          }

          //===================================================
          void main(void)
          {
          unsigned char i;
          init_devices();
          init_1602();

          Set_xy(0,2);
          Send_S("Hello world!");
          Set_xy(1,3);
          Send_S("Im COWBOY.");
          for (i=0;i<255;i++) Delay(10000);

          Send(0,0x01);
          Set_xy(0,3);
          Send_S("Welcome to");
          Set_xy(1,1);
          Send_S(www.51hei.com);
          while(1);
          }



          評(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); })();