1234567891011121314151617181920 |
- #include "timer.h"
- void timer_config()
- {
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE); // 使能Timer7时钟
- TIM_TimeBaseInitTypeDef timer_init_structure;
- TIM_TimeBaseStructInit(&timer_init_structure);
-
- timer_init_structure.TIM_Prescaler = ((SystemCoreClock / 2) / 1000) - 1; // 预分频器,1ms为一个计数周期
- timer_init_structure.TIM_Period = 0xFFFF; // 最大计数值
- timer_init_structure.TIM_CounterMode = TIM_CounterMode_Up; // 向上计数模式
- TIM_TimeBaseInit(TIM7, &timer_init_structure);
- TIM_Cmd(TIM7, ENABLE); // 启动Timer7
- }
|