比较寄存器已经初始化,代码如下:
#define CCR1_Val ((uint16_t)1*16)
#define CCR2_Val ((uint16_t)2*16)
#define CCR3_Val ((uint16_t)3*16)
#define CCR4_Val ((uint16_t)4*16)
static void TIM1_Config(void);
void main(void)
{
CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
TIM1_Config();
while (1)
{
}
}
static void TIM1_Config(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 5*16, 0);
TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_RESET);
TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, CCR2_Val,
TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_RESET);
TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
CCR3_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_RESET);
TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, CCR4_Val, TIM1_OCPOLARITY_LOW,
TIM1_OCIDLESTATE_SET);
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
} |