访问电脑版页面

导航:老古开发网手机版STM32单片机STM32F103单片机

利用stm32f103的TIM2实现精确延时

导读:void TIM_ResetCounter(TIM_TypeDef * TIMx){TIMx->CNT = 0;}void TIM2_Delay_ms(unsigned int cms){unsigned short temp = 0;TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;TIM_TimeBaseStructInit(&TIM_TimeBase
关键字:
stm32f103,精确延时,tim2实,

void TIM_ResetCounter(TIM_TypeDef * TIMx)

{

TIMx->CNT = 0;

}

void TIM2_Delay_ms(unsigned int cms)

{

unsigned short temp = 0;

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;

TIM_TimeBaseStructure.TIM_Period = cms * 2;

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

TIM_Cmd(TIM2, ENABLE);

do

{

temp = TIM_GetCounter(TIM2);

}while(temp != 0x01);

TIM_Cmd(TIM2, DISABLE);

TIM_ResetCounter(TIM2);

}


来源:互联网   作者:karen  2018/11/2 10:40:01
栏目: [ STM32F103单片机]

相关阅读

STM32F103学习笔记 (十) TFTLCD 显示

STM32F103试用体验:LCD显示与DHT11测量实验

STM32F103学习笔记 (八) PWM输出

STM32F103外部晶振由8M变为12M

STM32F103系列单片机中的定时器工作原理解析

STM32F103利用模拟I2C驱动ADS1115

STM32F103 开发板试用体验:超声波测距功能的实现

基于STM32F103ZE的USART2 端口时钟

利用stm32f103的TIM2实现精确延时

STM32F103ZET6 之 通用定时器单脉冲模式实验

STM32F103C8T6 ULN2003步进电机驱动代码

stm32F103单片机无源晶振不起振排除问题

嵌入式微处理器STM32F103有什么特点和应用?怎样去开发?

STM32F103试用体验(四):硬件原理与机壳组装

STM32F103试用体验:水共震准备材料中的过程

基于STM32F103的USB数据采集模块的设计

基于单片机Stm32f103 DAC电流输出解决方案

100脚的STM32F103VE单片机通过FSMC接口读写DS12C887时钟芯片中的寄存器

stm32f103zet6与stm32f103rct6的区别

STm32F103ZET6红牛开发板原理图