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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > ATMage16的16位定時器的PWM應(yīng)用

          ATMage16的16位定時器的PWM應(yīng)用

          作者: 時間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
          //ICC-AVR application builder : 2007-5-6 21:30:57
          // Target : M16
          // Crystal: 8.0000Mhz
          //TIMER1 initialize - prescale:64
          // WGM: 10) PWM phz correct, TOP= ICRn
          // desired value: 1Hz
          // actual value: 1.000Hz (0.0%)


          #include
          #include

          #define PWM1A PORTD5 //OC1A PD5
          #define PWM1B PORTD4 //OC1B PD4
          unsigned char OCAH;
          unsigned char OCAL;
          unsigned char OCBH;
          unsigned char OCBL;

          void timer1_init(void)
          {
          TCCR1B = 0x00; //stop
          TCNT1H = 0x00; //setup
          TCNT1L = 0x01;
          OCR1AH = OCAH;
          OCR1AL = OCAL;
          OCR1BH = OCBH;
          OCR1BL = OCBL;
          ICR1H = 0xff; // pwm 的計數(shù)頂值
          ICR1L = 0xFF;
          TCCR1A = 0xA3; // 匹配清零 top置位
          TCCR1B = 0x0B; // start Timer
          }

          void init_devices(unsigned char valueah,unsigned char valueal,unsigned char valuebh,unsigned char valuebl)
          {

          OCAH=valueah;
          OCAL=valueal;
          OCBH=valuebh;
          OCBL=valuebl;
          CLI();
          //disable all interrupts
          timer1_init();
          MCUCR = 0x00;
          GICR = 0x00;
          TIMSK = 0x04; //timer interrupt sources
          SEI(); //re-enable interrupts

          }


          void main(void)
          {
          PORTD&=(0<DDRD|=(1<init_devices(0x0f,0x45,0x0f,0xf0); //修改實參即可改變占空比,最大值為0X0FFF;
          while(1);
          }
          [Copy to clipboard]







          我愛avr,我愛虛擬儀器


          評論


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