我32新手,定时器中断基本配置都配置过了,为什么没有进入中断啊。灯都没亮过.
void Tim3_Init(void)
{
TIM_TimeBaseInitTypeDef Tim_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
NVIC_InitStruct.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd =ENABLE;
NVIC_Init(&NVIC_InitStruct);
Tim_InitStruct.TIM_ClockDivision = 0;
Tim_InitStruct.TIM_CounterMode = TIM_CounterMode_Down; //想上计数
Tim_InitStruct.TIM_Prescaler = 7200-1; //预分频
Tim_InitStruct.TIM_Period = 10000; //重装载寄存器的值
TIM_TimeBaseInit(TIM3,&Tim_InitStruct);
printf("Counter = %d Prescaler = %d\n",TIM_GetCounter(TIM3),TIM_GetPrescaler(TIM3));
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //设置定时器更新时间为中断源
TIM_Cmd(TIM3,ENABLE);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update))
{
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
LED1(1); //点亮LED灯
DelayMs(1000);
LED1(0); //熄灯
}
}
|