STM8 互补 PWM TIM1定时器 输出成功
扫描二维码
随时随地手机看文章
程序测试:#include
void PWM_INIT(){
CLK_PCKENR1 |= 0x80;//开启定时器1外设时钟 TIM1_EGR |= 0x01; //重新初始化TIM1 TIM1_CR1 = 0x00; //B7(0)可以直接写入 B65(00)边缘对齐模式B4(0)向上计数B3(0)计数器不停止发生更新事件 TIM1_RCR = 0x00; TIM1_PSCRH =0; //设定预分频为,16分频 1M TIM1_PSCRL =0x80; //PWM的时钟 影响周期 TIM1_CCER1 = 0x0F; //CC2ER1开启1,2,高电平有效 TIM1_CCMR1 = 0x60; //PWM模式1,CC1配置入输出 TIM1_ARRH = 0; //设定重装载值 TIM1_ARRL = 0xFF; //PWM的周期 TIM1_CCR1H = 0; TIM1_CCR1L = 0x80; // 占空比值 TIM1_CR1 |= 0x01; //使能TIM1计数器 TIM1_BKR |= 0x80;}void main(){PWM_INIT();while(1);}非常重要注意,芯片的Option配置AFR7和AFR0修改如下图: