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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 利用51的定時(shí)器和1602的一個(gè)時(shí)鐘程序

          利用51的定時(shí)器和1602的一個(gè)時(shí)鐘程序

          作者: 時(shí)間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
          #include

          #define uchar unsigned char
          #define uint unsigned int
          sbit rs=P3^0;
          sbit lcden=P3^1;
          sbit s1=P3^6;
          sbit s2=P3^7;
          uchar count,shi,fen,miao,num;
          uchar code table[]="2011-02-25";
          uchar code table1[]="00:00:00";
          void reflesh(uchar add,uchar date);
          void delay(uchar z)
          {
          uint x,y;
          for(x=0;xfor(y=0;y<110;y++);
          }
          void write_ins(uchar add)
          {
          rs=0;
          delay(5);
          P1=add;
          lcden=1;

          delay(5);
          lcden=0;
          delay(5);
          }
          void write_date(uchar add)
          {
          rs=1;
          delay(5);
          P1=add;
          lcden=1;

          delay(5);
          lcden=0;
          delay(5);
          }
          void init()
          {
          uchar i;
          lcden=0;
          shi=0;
          fen=0;
          miao=0;
          write_ins(0x38);
          write_ins(0x0c);
          write_ins(0x06);
          write_ins(0x01);
          write_ins(0x80);
          for(i=0;i<14;i++)
          {
          write_date(table[i]);
          delay(5);
          }
          write_ins(0x80+0x40);
          for(i=0;i<13;i++)
          {
          write_date(table1[i]);
          delay(5);
          }

          TMOD=0x01;
          TH0=(65536-50000)/256;
          TL0=(65536-50000)%6;
          EA=1;
          ET0=1;
          TR0=1;
          }
          void keyscan()
          {

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

          if(num==""||num==0)
          {
          if(s1==0)
          delay(5);
          if(s1==0)
          {
          while(!s1);
          TR0=0;
          write_ins(0x80+0x40+11);
          write_ins(0x0c);
          num=1;
          }
          }
          if(num==1)
          {
          if(s1==0)
          delay(5);
          if(s1==0)
          {
          while(!s1);
          write_ins(0x80+0x40+8);
          write_ins(0x0c);
          num=2;
          }
          }
          if(num==2)
          {
          if(s1==0)
          delay(5);
          if(s1==0)
          {
          while(!s1);
          write_ins(0x80+0x40+5);
          write_ins(0x0c);
          num=3;
          }
          }
          if(num==3)
          {
          if(s1==0)
          delay(5);
          if(s1==0)
          {
          while(!s1);
          write_ins(0x0c);
          TR0=1;
          num=0;
          }
          }






          if(num!=0)
          {
          if(num==1)
          {
          if(s2==0)
          delay(5);
          if(s2==0)
          {
          while(!s2);
          miao++;
          if(miao==60)
          miao=0;
          reflesh(0x80+0x40+10,miao);
          }
          }
          if(num==2)
          {
          if(s2==0)
          delay(5);
          if(s2==0)
          {
          while(!s2);
          fen++;
          if(fen==60)
          miao=0;
          reflesh(0x80+0x40+7,fen);
          }
          }
          if(num==3)
          {
          if(s2==0)
          delay(5);
          if(s2==0)
          {
          while(!s2);
          shi++;
          if(shi==24)
          shi=0;
          reflesh(0x80+0x40+4,shi);
          }
          }
          }
          }
          void main()
          {
          init();

          while(1)
          {
          keyscan();
          if(count==20)
          {
          count=0;
          miao++;
          if(miao==60)
          {
          miao=0;
          fen++;
          if(fen==60)
          {
          fen=0;
          shi++;
          }
          reflesh(0x80+0x40+4,shi);
          }
          reflesh(0x80+0x40+7,fen);
          }
          reflesh(0x80+0x40+10,miao);


          }

          }

          void timer0() interrupt 1
          {
          TH0=(65536-50000)/256;
          TL0=(65536-50000)%6;
          count++;
          }
          void reflesh(uchar add,uchar date)
          {
          uchar ten,ge;
          write_ins(add);
          ten=date/10;
          ge=date;
          write_date(0x30+ten);
          write_date(0x30+ge);


          }



          關(guān)鍵詞: 51定時(shí)器160

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