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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 一個(gè)簡(jiǎn)單的流水燈c51程序

          一個(gè)簡(jiǎn)單的流水燈c51程序

          作者: 時(shí)間:2012-11-15 來(lái)源:網(wǎng)絡(luò) 收藏
          //代碼
          #includereg52.h> //頭文件
          #define uchar unsigned char //宏定義
          #define uint unsigned int
          void delay(uint x) //(控制燈亮與滅的間隔)
          {
           uint i,j;
          for(i=500;i>0;i--)
          for(j=x;j>0;j--);
          }
          void main() //主函數(shù)
          {
            uchar i; //定義局部變量
            P2=0x00; //關(guān)閉所有發(fā)光二極管
            while(1) //死循環(huán)
            {
             P2=0xfe; //第一個(gè)二極管亮
             delay(100); //延時(shí)
              for(i=0;i7;i++) //左移7次
              {
                P2=~P2; //把P2的值取反
                P2=P21; //左移一位
                P2=~P2;
                delay(100);
              }
              for(i=0;i3;i++)
              {
                P2=0xff; //所有的二極管都滅
                delay(100);
                P2=0x00; //所有的二極管都亮
                delay(100);
              }
              P2=0x7f; //最后一個(gè)二極管亮
              delay(100);
              for(i=0;i7;i++)
              {
                 P2=~P2;
                P2=P2>>1;
                P2=~P2;
                delay(100);
              }
              for(i=0;i3;i++)
              {
                P2=0x00;
                 delay(100);
                P2=0xff;
                delay(100);
              }
            }
          }
          /*注:發(fā)光二極管接單片機(jī)的P2口,低電平有效,即可實(shí)現(xiàn)效果
          */


          評(píng)論


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