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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > proteus與keil Cx51的單片機(jī)仿真(定時(shí)器應(yīng)用2)

          proteus與keil Cx51的單片機(jī)仿真(定時(shí)器應(yīng)用2)

          作者: 時(shí)間:2016-11-24 來源:網(wǎng)絡(luò) 收藏
          使用定時(shí)器產(chǎn)生PWM波調(diào)節(jié)P0和P2口VD的亮度,當(dāng)按下K01時(shí),VD亮度減小,當(dāng)按下K02時(shí),VD亮度增加,設(shè)P0和P2口低高電平燈亮,反之燈滅。

          電路圖:

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



          C程序:

          #include
          #include
          sbit K01=P1^4; //增加鍵
          sbit K02=P1^5; //減少鍵
          sbit BEEP=P3^7;//蜂鳴器
          unsigned char PWM=0x7f;//賦初值
          void Beep();
          void delayms(unsigned char ms);
          void delay(unsigned t);
          void main()
          {
          P0=0xff;
          P1=0xff;
          P2=0xff;
          P3=0xff;
          TMOD=0x21;
          TH0=0xfc;//1ms延時(shí)常數(shù)12M
          TL0=0x18;//頻率調(diào)節(jié)
          TH1=PWM;//脈寬調(diào)節(jié)
          TL1=0;
          EA=1;
          ET0=1;
          ET1=1;
          TR0=1;
          while(1)
          {
          do{if(PWM!=0xff){PWM++;delayms(10);}
          else Beep();}while(K01==0);//K01按下,亮度變暗
          do{if(PWM!=0x01){PWM--;delayms(10);}
          else Beep();}while(K02==0);//K02按下,亮度變亮
          } }
          void timer0() interrupt 1 //定時(shí)器0中斷服務(wù)程序
          {
          TR1=0;
          TH0=0xfc;
          TL0=0x66;
          TH1=PWM;
          TR1=1;
          P0=0x00;
          P2=0x00; //啟動(dòng)輸出
          }
          void timer1() interrupt 3//定時(shí)器1中斷服務(wù)程序
          {TR1=0;P0=0xff;P2=0xff;}//結(jié)束輸出
          void Beep()//蜂鳴器子程序
          {unsigned char i;
          for(i=0;i<100;i++){delay(100);BEEP=!BEEP;}//Beep取反
          BEEP=1;delayms(100);//關(guān)閉蜂鳴器,并延時(shí)
          }
          void delay(unsigned char t){while(t--);}//延時(shí)子程序1
          void delayms(unsigned char ms)//延時(shí)子程序2
          {unsigned char i; while(ms--){for(i=0;i<120;i++);}}




          評論


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