//本例程使用了3.4.0版库
volatile uint32_t g_SysTimer;
//初始化,既配置系统定时器
void SysTickInit(void)
{
g_SysTimer=0;
SysTick_Config(72000); //系统时钟/1000=产生一ms中断
}
//系统定时器中断函数
void SysTick_Handler( void )
{
g_SysTimer++;
}
//获取当前定时值
uint32_t GetCurrentTick(void)
{
uint32_t ret;
CLI();
ret=g_SysTimer;
SEI();
return ret;
}
//计算过去时间
uint32_t GetPassedTick(uint32_t t)
{
uint32_t cur=GetCurrentTick();
if(cur>=t)
return (cur-t);
return (cur+(0xffffffff-t));
}
//延时
void SysDelayMs(uint32_t t)
{
uint32_t tick=GetCurrentTick();
while(GetPassedTick(tick)<t);
}
|
|