想用STM8AL3l68的tiM2 Channel1输出PWM,写的代码如下,放在main函数中运行,但是始终无法输出,求解。
uint16_t t=112;
uint8_t timebase=224;
void TIMER2_PWMInit()
{
CLK_DeInit;
CLK_clockSwitchConfig(CLK_SWITCHMODE_AUTO,CLK_SOURCE_HSE,DISABLE,CLK_CURRENTCLOCKSTATE_ENABLE);
GPIO_DeInit(GPIOB);
GPIO_Init(GPIOB,GPIO_PIN_0,GPIO_MODE_OUT_PP_HIGH_FAST);
// CLK_PeripheralClockConfig(CLK_Peripheral_TIM1,ENABLE);写上这句一直报错
TIM2_DeInit();
TIM2_TimeBaseInit(TIM2_PRESCALER_128, timebase);
TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, t, TIM2_OCPOLARITY_HIGH);
TIM2_OC1PreloadConfig(ENABLE);
TIM2_Cmd(ENABLE);
//TIM2_CtrlPWMOutputs(ENABLE);
} |