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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于51單片機(jī)的C語言流水燈程序

          基于51單片機(jī)的C語言流水燈程序

          作者: 時(shí)間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
          #include //51系列單片機(jī)定義文件

          #define uchar unsigned char //定義無符號(hào)字符
          #define uint unsigned int //定義無符號(hào)整數(shù)

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


          void delay(uint); //聲明延時(shí)函數(shù)
          void main()
          {
          uint i;
          uchar temp;

          while(1)
          {
          temp=0x01;
          for(i=0;i<8;i++) //8個(gè)流水燈逐個(gè)閃動(dòng)
          {
          P2=~temp;
          delay(500); //調(diào)用延時(shí)函數(shù)
          temp<<=1;
          }
          temp=0x80;
          for(i=0;i<8;i++) //8個(gè)流水燈反向逐個(gè)閃動(dòng)
          {
          P2=~temp;
          delay(500); //調(diào)用延時(shí)函數(shù)
          temp>>=1;
          }
          temp=0xFE;
          for(i=0;i<8;i++) //8個(gè)流水燈依次全部點(diǎn)亮
          {
          P2=temp;
          delay(500); //調(diào)用延時(shí)函數(shù)
          temp<<=1;
          }
          temp=0x7F;
          for(i=0;i<8;i++) //8個(gè)流水燈依次反向全部點(diǎn)亮
          {
          P2=temp;
          delay(500); //調(diào)用延時(shí)函數(shù)
          temp>>=1;
          }
          }

          }


          void delay(uint a) //延時(shí)函數(shù),毫秒級(jí)別
          {
          uint i;
          while(--a!=0) //執(zhí)行空操作循環(huán),其中a為形參,由調(diào)用該函數(shù)的函數(shù)語句提供值
          {
          for(i=0;i<125;i++);//執(zhí)行當(dāng)0加到125時(shí),大約會(huì)用掉1ms的時(shí)間
          }
          }



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