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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 自制四位數(shù)碼管顯示的數(shù)字鐘c程序

          自制四位數(shù)碼管顯示的數(shù)字鐘c程序

          作者: 時間:2012-09-04 來源:網(wǎng)絡 收藏

          10.jpg

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

          #includestc90.h>
          #define uchar unsigned char
          uchar code shuzi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc0};//0 1 2 3 4 5 6 7 8 9 0
          uchar code shuza[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0xc0};//0 1 2 3 4 5 0
          uchar ss,dd,ff,gg,zz;
          uchar qq,ww,ee,rr,tt;
          uchar z,x,qw,qe,qr,as,fe;
          sbit a=P2^0;//鎖存器1
          sbit b=P2^1;//鎖存器2
          sbit c=P2^2;//鎖存器3
          sbit d=P2^3;//鎖存器4
          sbit e=P2^4;//秒燈
          sbit f=P2^5;//時間指示燈
          sbit g=P2^6;//設置指示燈
          sbit h=P2^7;//....
          sbit i=P1^0;//時間設置按鍵
          sbit j=P1^1;//返回
          sbit k=P1^2;//加
          sbit l=P1^3;//減
          sbit m=P1^4;//定時設置
          sbit y=P1^5;//啟動定時
          void ys();

          void main()
          {
          EA=1; //打開總中斷
          TH0=(65535-50000)/256; //定時器復初值
          TL0=(65535-50000)%256;
          ET0=1; //
          TR0=1; //啟動定時器
          P0=0xc0;
          P2=0xff;
          P2=0xd0;
          while(1)
          {f=0;g=1;
          if(i==0)//設置時間 判斷
          {g=0;f=1;
          while(1)
          {if(j==0){break;}
          if(i==0){ys();if(i==0){while(i==0){if(i==1){x++;break;}}}}
          if(x==5){x=1;}if(x==0){x=1;}

          if(x==1)
          {if(k==0){ys();if(k==0){ss++;if(k==0)if(ss==10){ss=0;}}} if(l==0){ys();if(l==0){if(ss==0){ss=10;}ss--;}}
          a=1;P0=0x7f;P0=shuzi[ss];a=0; }

          if(x==2)
          {if(k==0){ys();if(k==0){dd++;if(k==0)if(dd==6){dd=0;}}} if(l==0){ys();if(l==0){if(dd==0){dd=6;}dd--;}}
          b=1;P0=0x7f;P0=shuza[dd];b=0; }

          if(x==3)
          {if(k==0){ys();if(k==0){ff++;if(k==0)if(ff==10){ff=0;}}} if(l==0){ys();if(l==0){if(ff==0){ff=10;}ff--;}}
          c=1;P0=0x7f;P0=shuzi[ff];c=0; }

          if(x==4)
          {if(k==0){ys();if(k==0){gg++;if(k==0)if(gg==3){gg=0;}}} if(l==0){ys();if(l==0){if(gg==0){gg=3;}gg--;}}
          d=1;P0=0x7f;P0=shuzi[gg];d=0; }

          }
          } //設置時間完

          if(m==0)//定時 判斷
          {g=0;f=0;as=1;
          while(1)
          {if(j==0){as=0;break;}
          if(m==0){ys();if(m==0){while(m==0){if(m==1){x++;break;}}}}
          if(x==5){x=1;}if(x==0){x=1;}

          if(x==1)
          {if(k==0){ys();if(k==0){qq++;if(k==0)if(qq==10){qq=0;}}} if(l==0){ys();if(l==0){if(qq==0){qq=10;}qq--;}}a=1;P0=0x7f;P0=shuzi[qq];a=0; }

          if(x==2)
          {if(k==0){ys();if(k==0){ww++;if(k==0)if(ww==6){ww=0;}}} if(l==0){ys();if(l==0){if(ww==0){ww=6;}ww--;}} b=1;P0=0x7f;P0=shuza[ww];b=0; }

          if(x==3)
          {if(k==0){ys();if(k==0){ee++;if(k==0)if(ee==10){ee=0;}}} if(l==0){ys();if(l==0){if(ee==0){ee=10;}ee--;}}c=1;P0=0x7f;P0=shuzi[ee];c=0; }

          if(x==4)
          {if(k==0){ys();if(k==0){rr++;if(k==0)if(rr==3){rr=0;}}} if(l==0){ys();if(l==0){if(rr==0){rr=3;}rr--;}}d=1;P0=0x7f;P0=shuzi[rr];d=0;}

          }
          } //定時時間完
          if(y==0)//啟動定時功能
          {while(1){if(y==1){h=!h;if(h==0){fe=1;}if(h==1){fe=0;}break;}}}
          if(fe==1)
          {if(gg==rr){if(ff==ee){if(dd==ww){if(ss==qq){ g=0;f=0;;ys();g=1;f=1;ys(); }}}}}

          }
          }
          void zhongduan() interrupt 1 //中斷函
          { TH0=(65535-50000)/256; //定時器復初值
          TL0=(65535-50000)%256;
          z++;
          if(z==80)
          {z=0;
          e=!e;
          zz++;
          if(zz==120){zz=0;ss++;}
          if(ss==10){ss=0;dd++;}
          if(dd==6){dd=0;ff++;}
          if(ff==10){ff=0;gg++;}

          if(gg==2) {if(ff>=4){ff=0;gg=0;}}
          if(gg>=3) {gg=0;}
          if(rr==2) {if(ee>=4){ee=0;rr=0;}}
          if(rr>=3) {rr=0;}

          if(as==0)
          {P0=shuzi[ss];a=1;a=0;
          P0=shuza[dd];b=1;b=0;
          P0=shuzi[ff];c=1;c=0;
          P0=shuzi[gg];d=1;d=0;
          }
          if(as==1)
          { a=1;P0=shuzi[qq];a=0;
          b=1;P0=shuza[ww];b=0;
          c=1;P0=shuzi[ee];c=0;
          d=1;P0=shuzi[rr];d=0;
          }
          }

          }
          void ys()
          {for(qw=255;qw>0;qw--)
          for(qe=255;qe>0;qe--);
          for(qw=255;qw>0;qw--)
          for(qe=50;qe>0;qe--);
          }

          51單片機相關文章:51單片機教程




          評論


          相關推薦

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

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