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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 如何實(shí)現(xiàn)鍵盤自由控制二極管流水燈

          如何實(shí)現(xiàn)鍵盤自由控制二極管流水燈

          作者: 時(shí)間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
          #include
          //流水燈 從上到下點(diǎn)亮 然后熄滅; 再從下到上點(diǎn)亮 然后熄滅
          sbit Key1=P2^7; //啟動(dòng) 停止 定時(shí)器T0
          sbit Key2=P2^6; //停止 定時(shí)器T0, 通過鍵盤實(shí)現(xiàn) 流水燈 從上到下點(diǎn)亮 然后熄滅
          sbit Key3=P2^5; //停止 定時(shí)器T0, 通過鍵盤實(shí)現(xiàn) 流水燈 從下到上點(diǎn)亮 然后熄滅
          unsigned char t=0;
          unsigned char i=0;
          void Delay(unsigned int i) //延時(shí)
          {
          unsigned char j;
          for( ; i>0; i--)
          for(j=110; j>0; j--);
          }
          void LED_UP() // 二極管向上 逐漸點(diǎn)亮
          {
          unsigned char n;
          P0=0xff;
          for(n=1; n<=8; n++)
          {
          P0=P0>>1;
          Delay(1000);
          }
          P0=0xff;
          }
          void LED_Down()// 二極管向下 逐漸點(diǎn)亮
          {
          unsigned char n;
          P0=0xff;
          for(n=1; n<=8; n++)
          {
          P0=P0<<1;
          Delay(1000);
          }
          P0=0xff;
          }
          void Keycan() // 檢測鍵盤是否被按下
          {
          if(Key1==0) //啟動(dòng) 停止 定時(shí)器T0
          {
          Delay(10);
          if(Key1==0)
          {
          TR0=~TR0;
          }
          while(!Key1);
          }
          if(TR0==0) //定時(shí)器T0 停止, Key2, Key3 鍵 被按下才有作用
          {
          if(Key2==0) //
          {
          Delay(10);
          if(Key2==0)
          {
          LED_UP(); // 二極管向上 逐漸點(diǎn)亮
          }
          while(!Key2);
          }
          if(Key3==0) //
          {
          Delay(10);
          if(Key3==0)
          {
          LED_Down(); // 二極管向下 逐漸點(diǎn)亮
          }
          while(!Key3);
          }
          } //end if(TR0==0)
          }
          void main()
          {
          TMOD=0x01; //
          EA=1; //
          ET0=1;
          TR0=1;
          TH0=(65536-50000)/256;
          TL0=(65536-50000)%256;
          while(1)
          {
          Keycan();
          if(t==20)
          {
          t=0;
          LED_UP();
          LED_Down();
          }
          }
          }
          void TimerLED() interrupt 1 using 1
          {
          TH0=(65536-50000)/256;
          TL0=(65536-50000)%256;
          t++;
          }


          關(guān)鍵詞: 自由控制二極管流水

          評論


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