STM8 互補(bǔ) PWM TIM1定時(shí)器 輸出成功
程序測試:#include
void PWM_INIT(){
CLK_PCKENR1 |= 0x80;//開啟定時(shí)器1外設(shè)時(shí)鐘 TIM1_EGR |= 0x01; //重新初始化TIM1 TIM1_CR1 = 0x00; //B7(0)可以直接寫入 B65(00)邊緣對齊模式B4(0)向上計(jì)數(shù)B3(0)計(jì)數(shù)器不停止發(fā)生更新事件 TIM1_RCR = 0x00; TIM1_PSCRH =0; //設(shè)定預(yù)分頻為,16分頻 1M TIM1_PSCRL =0x80; //PWM的時(shí)鐘 影響周期 TIM1_CCER1 = 0x0F; //CC2ER1開啟1,2,高電平有效 TIM1_CCMR1 = 0x60; //PWM模式1,CC1配置入輸出 TIM1_ARRH = 0; //設(shè)定重裝載值 TIM1_ARRL = 0xFF; //PWM的周期 TIM1_CCR1H = 0; TIM1_CCR1L = 0x80; // 占空比值 TIM1_CR1 |= 0x01; //使能TIM1計(jì)數(shù)器 TIM1_BKR |= 0x80;}void main(){PWM_INIT();while(1);}非常重要注意,芯片的Option配置AFR7和AFR0修改如下圖: