void time_Init()
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//TIM_OCInitTypeDef TIM_OCInitStrcture;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_DeInit(TIM2);
TIM_InternalClockConfig(TIM2);
TIM_TimeBaseStructure.TIM_Prescaler=35999; //
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //
TIM_TimeBaseStructure.TIM_Period=2000; //
//如果APB1的时钟分频数不为1,那么TIM2~7的时钟频率将为APB1时钟的两倍。
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_Cmd(TIM2,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;//使能按键外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //抢占优先级2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //子优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
TIM_PrescalerConfig(TIM2,35999,TIM_PSCReloadMode_Immediate);
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
}
有没有人有空,帮我看看这个定时中断,怎么进不去中断,那里设置错误?一直都在跑死循环的 |