void main(void)
{
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_CCOConfig(CLK_OUTPUT_CPU);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2,ENABLE);
TIM2_TimeBaseInit(TIM2_PRESCALER_1,254);
TIM2_OC1Init(TIM2_OCMODE_PWM1,TIM2_OUTPUTSTATE_ENABLE,Baifenbi,TIM2_OCPOLARITY_HIGH);
TIM2_OC1PreloadConfig(ENABLE);
TIM2_CCxCmd(TIM2_CHANNEL_1, ENABLE);
TIM2_UpdateDisableConfig(ENABLE);
TIM2_ITConfig(TIM2_IT_UPDATE,ENABLE);
TIM2_ClearFlag(TIM2_FLAG_UPDATE);
TIM2_Cmd(ENABLE);
enableInterrupts(); // 开总中断
while (1)
{
TIM2_SetCompare1(Baifenbi);
}
}
stm8s_it.c:
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
static uint16_t Time = 0;
FlagStatus fs;
fs = TIM2_GetFlagStatus(TIM2_FLAG_UPDATE);
//fs=RESET or SET
if(fs == SET)
{
TIM2_ClearFlag(TIM2_FLAG_UPDATE);
Time++;
if(Time == 10)
{
Time = 0;
Baifenbi++;
if(Baifenbi>255)Baifenbi = 0;
}
}
}
求救,为什么没进入中断,但可以输出PWM,证明时钟有动,但没进入中断响应