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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 1602 AVR單片機(jī)版 報(bào)警指示功能

          1602 AVR單片機(jī)版 報(bào)警指示功能

          作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 收藏

          void delay_1ms(); //延時(shí)1毫秒
          void delay_nms(uint n); //延時(shí)n毫秒
          void wait(); //繁忙等待函數(shù)
          void writedata(uchar w); //寫(xiě)數(shù)據(jù)
          void writecmd(uchar cmd); //寫(xiě)指令
          void init(); //1602初始化
          void display(uchar x,uchar y,uchar *P); //顯示字符串函數(shù)


          void delay(uint k) //常用延遲函數(shù)
          {
          uint i,j;
          for(i=0;i
          for(j=0;j<1140;j++);
          }

          void main()
          {
          DDRB=0xff; //設(shè)置PB口為輸出
          PORTB=0xff;
          DDRD=0x00; //中斷源設(shè)置為輸入
          PORTD=0xff;
          MCUCR=0x02; //中斷為下降沿
          GICR=0xc0; //中斷為int0,int1
          SREG=0x80; //中斷總開(kāi)關(guān)
          init();
          while(1)
          {
          PORTB=0xff;
          delay(300);
          PORTB=0x00;
          delay(300);
          display(5,0,normal);
          display(3,1,indication);
          }
          }

          #pragma vector = 0x04
          __interrupt void qq() //中斷產(chǎn)生報(bào)警
          {
          writecmd(0x01); //清屏
          while(1)
          {
          display(6,0,alarm);
          PORTB=0x00;
          }
          }
          //-----------------------庫(kù)函數(shù)------------------------
          void wait()
          {
          uchar val;
          DATAPORT=0xff;
          RS0;
          RW1;
          __no_operation();
          EN1;
          __no_operation(); //注:一個(gè)__no_operation();延時(shí)130ns;
          __no_operation();
          DDRA=0x00;
          val=PINA;
          while(val&busy)val=PINA;
          EN0;
          DDRA=0xff;
          }

          void writecmd(uchar w)
          {
          wait();
          RS0;
          RW0;
          __no_operation();
          DATAPORT=w;
          __no_operation();
          EN1;
          __no_operation();
          __no_operation();
          EN0;
          }

          void writedata(uchar data)
          {
          wait();
          RS1;
          RW0;
          __no_operation();
          DATAPORT=data;
          __no_operation();
          EN1;
          __no_operation();
          __no_operation();
          EN0;
          }


          void delay_nms(uint k)
          {
          uint i,j;
          for(i=0;i
          for(j=0;j<1140;j++);
          }


          void init()
          {
          delay_nms(15);
          writecmd(0x38);
          delay_nms(5);
          writecmd(0x38);
          delay_nms(5);
          writecmd(0x38);
          writecmd(0x80);
          writecmd(0x01);
          writecmd(0x06);
          writecmd(0x0c);
          }

          void display(uchar x,uchar y,uchar *p)
          {

          uchar add=0x80; //1602數(shù)據(jù)指針初值
          y=y&0x01;
          x=x&0x0f;
          if(y)add=add+0x40; //顯示第二行加數(shù)據(jù)指針加0x40
          writecmd(add+x);
          while(*p!=看屁屁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); })();