1234567891011121314151617181920212223242526272829303132 |
- #include "time.h"
- /*
- 使用案例
- TIME_Config(TIM1, 400-1, 84-1, 1, 0, RCC_APB2PeriphClockCmd, RCC_APB2Periph_TIM1, TIM1_UP_TIM10_IRQn);
- */
- void TIM_Mod_Config(void(*ClockCmd)(uint32_t, FunctionalState), u32 RCC_APBnPeriphn,TIM_TypeDef *TIMx, u16 psc, u16 per, u8 pre, u8 sub)
- {
- (*ClockCmd)(RCC_APBnPeriphn, ENABLE);
-
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_TimeBaseStructure.TIM_Prescaler = psc; //定时器分频
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式
- TIM_TimeBaseStructure.TIM_Period = per; //自动重装载值
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseInit(TIMx,&TIM_TimeBaseStructure);//初始化定时器
-
- TIM_ARRPreloadConfig(TIMx, ENABLE); //允许定时重载
- TIM_SelectOutputTrigger(TIMx, TIM_TRGOSource_Update); //选择事件更新为触发源
-
- TIM_ITConfig(TIMx, TIM_IT_Update, ENABLE);
- TIM_Cmd(TIMx, ENABLE); //使能
- }
- void TIM_NVIC_Config(u8 NVIC_IRQChannel, u8 pre, u8 sub)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = NVIC_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = pre;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = sub;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
|