我用tim2,初始化如下:
RCC_APB1ENR |= (uint32)(1<<0) ; //timer2时钟使能
TIM2_ARR =1000;
TIM2_PSC = 47999;//计数器时钟分频
TIM2_CR1 |= 1<<7;//自动重装允许
// TIM4_CCMR2 |= 0x8; //ch3预装载使能
TIM2_SR &= ~(uint16)(1<<0);
TIM2_DIER |= (1<<0) | (1<<6) ;//允许中断,允许更新中断
NVIC_ISER0 |= 1<<28; //使能timer2全局中断
TIM2_CR1 |= 1; //使能计数
中断服务程序,
这样是好使的,led正常闪烁
void TIM2_IRQHandler(void)
{
TIM2_SR &= ~(uint16)(1<<0);
LED_B_CONV;
my_timer4_count_key += 1;
// Clear_timer2_it;
}
但是下面这样led不闪,但其他程序还正常运行,就像没进这个中断一样
void TIM2_IRQHandler(void)
{
LED_B_CONV;
my_timer4_count_key += 1;
TIM2_SR &= ~(uint16)(1<<0);
// Clear_timer2_it;
}
也就是把清除中断标志放在后面就有问题
搞不明白是怎么回事,大家帮忙,先谢了 |