📄 timer.c
字号:
#include "stm32f10x.h"
#include "common.h"
#include "Timer.h"
/* ************************************************************* **
* 函数名称:void Timer2_Init(void)
* 函数功能:Timer2初始化
* 入口参数:无
* 出口参数:无
** ************************************************************* */
void Timer2_Init(void)
{
// RCC->APB1ENR |= 0x0001;
RegSet(RCC->APB1ENR, RegBit0); //使能外设Timer2时钟
RegSet(TIM2->CR1,RegBit7|RegBit4); //自动重装载预装载允许位、向下计数
RegClr(TIM2->CR1,RegBit3|RegBit2|RegBit1); //更新允许
RegSet(TIM2->DIER,RegBit0|RegBit6); //允许更新中断,事件触发中断
TIM2->PSC = 7200; //预分频10KHz;公式Fck_psc/(PSC[15:0]+1)
TIM2->ARR = 5000; //重装载寄存器设为500,中断为50ms一次
RegSet(TIM2->CR1, RegBit0); //使能TIM2
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -