void timer_config(void)
{
timer_parameter_struct TIM_TimeBaseStructure; //定义时基单元初始化结构体
rcu_periph_clock_enable(RCU_TIMER1);
nvic_irq_enable(TIMER1_IRQn,3,0);
timer_deinit(TIMER1);
TIM_TimeBaseStructure.prescaler = 9999;
TIM_TimeBaseStructure.period = 47999;
TIM_TimeBaseStructure.repetitioncounter = 0;
TIM_TimeBaseStructure.alignedmode = TIMER_COUNTER_EDGE;
TIM_TimeBaseStructure.counterdirection = TIMER_COUNTER_UP;
TIM_TimeBaseStructure.clockdivision = TIMER_CKDIV_DIV1;
timer_init(TIMER1,&TIM_TimeBaseStructure);
timer_interrupt_flag_clear(TIMER1,TIMER_INT_FLAG_UP);
timer_interrupt_enable(TIMER1,TIMER_INT_UP);
timer_enable(TIMER1);
}
void TIMER1_IRQHandler(void)
{
if(timer_interrupt_flag_get(TIMER1,TIMER_INT_FLAG_UP)) //如果发生了更新事件中断
{
timer_interrupt_flag_clear(TIMER1,TIMER_INT_FLAG_UP);
}
}
设定定时器10s进入一次中断,但是将断点达到中断函数中运行,很快就进入了中断。 继续运行进入中断的时间为10s正常
|