其他分享
首页 > 其他分享> > STM32F1库函数初始化系列:定时器中断

STM32F1库函数初始化系列:定时器中断

作者:互联网

 1 static void TIM3_Configuration(void)   //10ms
 2 {
 3   TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 4   NVIC_InitTypeDef NVIC_InitStructure;
 5   
 6   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);   // RCC_APB1为72M频率
 7   
 8   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);                    //选择中断分组1  
 9   
10   NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;             //选择串口3中断
11   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;      //抢占式中断优先级设置为1
12   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;             //响应式中断优先级设置为1
13   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                //使能中断
14   NVIC_Init(&NVIC_InitStructure);
15   
16   TIM_TimeBaseStructure.TIM_Period = 100;
17   TIM_TimeBaseStructure.TIM_Prescaler =7199;
18   TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
19   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
20   TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
21   TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE );
22   TIM_Cmd(TIM3, ENABLE);  
23     
24 }
25 
26 void TIM3_IRQHandler(void) //TIM3 中断  10ms
27 {
28     if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查 TIM3 更新中断发生与否
29   {
30       TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //清除 TIM3 更新中断标志
31   }
32 }

 

标签:TIM3,定时器,中断,NVIC,TIM,TimeBaseStructure,InitStructure,STM32F1,库函数
来源: https://www.cnblogs.com/penuel/p/11264229.html