/*使用定时器1的通道1输出PWM*/
void TIM1_PWM_Initial(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(0x0000, TIM1_CounterMode_Up, 500, 0x01);
TIM1_OC1Init(TIM1_OCMode_PWM1,
TIM1_OutputState_Enable,
TIM1_OutputNState_Disable,
200,//占空比
TIM1_OCPolarity_High,
TIM1_OCNPolarity_High,
TIM1_OCIdleState_Set,
TIM1_OCNIdleState_Set);
TIM1_OC1PreloadConfig(ENABLE);
TIM1_Cmd(ENABLE);
TIM1->BKR |=0x80;//主使能
}
void main(void)
{
CLK_HSICmd(ENABLE);
TIM1_PWM_Initial();
/* Executive loop, runs continually after initialization */
while (1)
{
}
} |