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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)+數(shù)碼管簡單秒表程序,帶停止啟動(dòng)復(fù)位

          單片機(jī)+數(shù)碼管簡單秒表程序,帶停止啟動(dòng)復(fù)位

          作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
          p0口是數(shù)碼管的位選入口,P2口是數(shù)碼管的段選用4位一體的數(shù)碼管,P3.0 P3.1 P3.2分別是啟動(dòng)停止和復(fù)位按鈕

          本文引用地址:http://www.ex-cimer.com/article/201611/323949.htm
          #include
          #define uchar unsigned char
          #define uint unsigned int

          #define DATA P2
          sbit start=P3^0;
          sbit stop=P3^1;
          sbit reset=P3^2;

          //---------啟停標(biāo)志-----
          bit SAT=0;

          bit RST=0;

          //------------數(shù)碼管碼表----------
          uchar tab[10]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};

          //------------
          uint time=0; //時(shí)間
          uint cnt=0; //計(jì)數(shù)


          //-------------


          void delay(int k)
          {
          while(k--);
          }



          void startkey()
          {
          static uchar i,j;
          if(start==0)
          {
          if(i==0)
          {
          j++;
          if(j>3)
          {
          if(start==0)
          {
          i=1;j=0; SAT=1;
          }
          }
          }
          }
          else
          {
          i=j=0;
          }
          }


          void stopkey()
          {
          static uchar i,j;
          if(stop==0)
          {
          if(i==0)
          {
          j++;
          if(j>3)
          {
          if(stop==0)
          {
          i=1;j=0; SAT=0;
          }
          }
          }
          }
          else
          {
          i=j=0;
          }
          }


          void resetkey()
          {
          static uchar i,j;
          if(reset==0)
          {
          if(i==0)
          {
          j++;
          if(j>3)
          {
          if(reset==0)
          {
          i=1;j=0; RST=1;
          }
          }
          }
          }
          else
          {
          i=j=0;RST=0;
          }
          }

          //---------數(shù)碼管顯示 00.0-------
          void shownumber(int num)
          {
          DATA=tab[num%10];
          P0=7;
          delay(100);
          DATA=0x80;
          P0=6;
          delay(100);
          DATA=tab[num%100/10];
          P0=5;
          delay(100);
          DATA=tab[num/100];
          P0=4;
          delay(100);
          }

          //---------定時(shí)器初始化ˉ---------
          void time0_init()
          {
          TMOD=0x01;
          TH0=(65536-18348)/256;
          TL0=(65536-18348)%256;
          EA=1;
          ET0=1;
          }

          void T0_time()interrupt 1
          {
          TH0=(65536-18348)/256;
          TL0=(65536-18348)%256;
          cnt++;
          if(cnt==5)
          {
          time++;cnt=0;
          }
          }


          void main(void)
          {
          delay(50000);
          time0_init();
          while(1)
          {
          shownumber(time);
          if(SAT==1)TR0=1;
          if(SAT==0)TR0=0;
          if(RST==1){TR0=0;SAT=0;time=0;}
          startkey();
          stopkey();
          resetkey();
          }
          }


          評論


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