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

          新聞中心

          C51 模仿PWM,可調(diào)

          作者: 時間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
          #include

          sbit LED_0 = P1^0;

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

          sbit LED_1 = P1^1;

          unsigned Pwm = 0; // 控制 LED_0 的有暗到亮 其中LED_1 作為對比

          unsigned Count=0;

          void Time_Init(void)
          {
          TMOD = 0x02; //定時器0 定時,方式2
          TH0 = 0x9c; //100us
          TL0 = 0x9c;
          EA = 1;
          ET0 = 1;
          TR0 = 1;
          }

          void Int0_Init(void)
          {
          IT0=1; //設(shè)置下降沿觸發(fā)
          EA=1; //開總中斷
          EX0=1; //開外部中斷
          }

          void Int1_Init(void)
          {
          IT1=1; //設(shè)置下降沿觸發(fā)
          EA=1; //開總中斷
          EX1=1; //開外部中斷
          }

          void main(void)
          {
          Time_Init();
          Int0_Init();
          Int1_Init();
          LED_0 = 0;
          LED_1 = 0;
          while(1);

          }

          void INT_Time0() interrupt 1 using 1
          {
          Count++;
          if(Count==100)
          {
          Count=0;
          }
          if(Count<=Pwm)
          {
          LED_0 = 0;
          }
          else
          {
          LED_0 = 1;
          }
          }

          void Int0() interrupt 0
          {
          if(Pwm<=94)
          {
          Pwm=Pwm+5; //此時占空比為Pwm/100
          }
          else
          {
          Pwm=99;
          }
          }

          void Int1() interrupt 2
          {
          if(Pwm>=5)
          {
          Pwm=Pwm-5;
          }
          else
          {
          Pwm=0;
          }
          }



          關(guān)鍵詞: C51模仿PWM可

          評論


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