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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 數(shù)碼管可調(diào)倒計(jì)時(shí)器

          數(shù)碼管可調(diào)倒計(jì)時(shí)器

          作者: 時(shí)間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
          調(diào)節(jié)精度:5分鐘 調(diào)節(jié)范圍:0~650分鐘 數(shù)碼管顯示格式:000(分鐘)-00(秒)
          按下P1^0口開始倒計(jì)時(shí) P1^1口停止 P1^2加時(shí)間 P1^3減時(shí)間
          #include
          #define KeyPort P1
          sbit Key_UP=P1^0;
          sbit Key_DOWN=P1^1;
          unsigned char KeyV,TempKeyV,num;
          sbit P25=P2^0;//數(shù)碼管第1位
          sbit P26=P2^1;//數(shù)碼管第2位
          sbit P29=P2^2;
          sbit gang=P2^3;
          sbit P27=P2^4;//數(shù)碼管第4位
          sbit P28=P2^5;
          sbit P12=P1^2;//時(shí)間加
          sbit P13=P1^3; //時(shí)間減
          sbit JDQ=P3^7;//繼電器
          unsigned int js;
          unsigned int ds=6000,x,y;//倒計(jì)時(shí)初始時(shí)間,加時(shí),減時(shí)
          unsigned char jsflag;
          static unsigned int i;
          unsigned char code LEDDis[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF,0xBF};
          unsigned char KeyScan(void);//鍵盤掃描
          void tiaojie(void);
          void Delay(unsigned int ii) //1MS
          {
          unsigned int jj;
          for(;ii>0;ii--)
          for(jj=0;jj<125;jj++);
          }
          void main()
          {
          EA = 1; //允許CPU中斷
          ET0 = 1; //定時(shí)器0中斷打開
          ET1=1; //定時(shí)器1中斷打開
          TMOD = 0x11; //設(shè)定時(shí)器0 1為模式1,16位模式
          TH0=0xB8;
          TL0=0x00; //設(shè)定時(shí)值為(20ms)
          TH1=0xdc; //設(shè)定時(shí)值為(10ms)
          TL1=0x00;
          TR0 = 1;
          TR1=1;

          KeyV = 0;
          TempKeyV = 0;
          jsflag=0;
          while(1);
          }
          //定時(shí)器0中斷外理中鍵掃描和顯示
          void Key_Time0(void) interrupt 1 using 2
          {
          TH0=0xB8;
          TL0=0x00; //設(shè)定時(shí)值為20000us(20ms)
          if (!Key_UP)
          KeyV = 1;
          if (!Key_DOWN)
          KeyV = 2;

          if(P12==0)
          {
          Delay(20);
          if(P12==0)
          ds=ds+500;//定時(shí)加5分鐘 (調(diào)節(jié)精度)
          while(!P12);
          }
          if(P13==0)
          {
          Delay(20);
          if(P13==0)
          ds=ds-500; //定時(shí)減5分鐘
          while(!P13);
          }
          if (KeyV!= 0) //有鍵按下
          {
          Delay(10); //延時(shí)防抖 按下10ms再測
          if (!Key_UP)
          TempKeyV = 1;
          if (!Key_DOWN)
          TempKeyV = 2;
          if (KeyV == TempKeyV) //兩次值相等為確定接下了鍵
          {
          if (KeyV == 1)
          {
          jsflag=0;
          if(ds==0)
          {
          ds=100;
          }
          js=js+1;
          JDQ=1; //繼電器吸合

          if(js==50)
          {
          js=0;
          ds=ds-1;

          }
          }
          if(KeyV==2)
          {
          jsflag=1;
          }
          }
          }
          if(jsflag==1)
          {
          JDQ=0;
          }
          if(ds==0)
          {
          JDQ=0;
          jsflag=1;
          KeyV=0;
          }

          }
          void disp_Time1(void) interrupt 3 using 3
          {
          TH1=0xdc;
          TL1=0x00;
          x=ds/10000;
          P0=LEDDis[x]; //分鐘百位
          P25=0;
          Delay(2);
          P25=1;
          y=(ds%10000)/1000;//分鐘十位
          P0=LEDDis[y];
          P26=0;
          Delay(2);
          P26=1;
          P0=LEDDis[((ds%10000)%1000)/100];//分鐘各位
          P29=0;
          Delay(2);
          P29=1;
          P0=0xbf; //分鐘與秒的間隔符
          gang=0;
          Delay(2);
          gang=1;
          P0=LEDDis[(((ds%10000)%1000)%100)/10]; //秒十位
          if(((ds%1000)%100)/10>=6) //滿60,百位減一
          {
          ds=ds-10;
          P0=LEDDis[6];
          }
          P27=0;
          Delay(2);
          P27=1;
          P0=LEDDis[(((ds%10000)%1000)%100)%10]; //秒個(gè)位
          P28=0;
          Delay(2);
          P28=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); })();