利用stm32f103的TIM2实现精确延时
时间:11-19
来源:互联网
点击:
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);/*此处不能计数到0*/TIM_Cmd(TIM2, DISABLE);TIM_ResetCounter(TIM2);/*将计数寄存器的值恢复为0是必须的*/}
stm32f103TIM2精确延 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)