本帖最后由 brucewoo 于 2020-9-10 09:01 编辑
给你个参考思路,这是我自己使用的代码
#define SYSTICK_PerUs (SystemCoreClock / 1000000) //每us多少Tick (72M)
void Duino_DelayUs(uint32_t us)
{
u32 count = 0;
u32 ticks = SYSTICK_PerUs * us; //要经历多少tick
u32 oldVal = SysTick->VAL; //记录开始计数器VAL
u32 now = oldVal;
while(1)
{
now = SysTick->VAL;
if(oldVal>= now)
{
count += (oldVal - now); //可能没倒数完过
}
else
{
count += (oldVal + SYSTICK_DEFAULT_RELOAD- now); //肯定倒数完过
}
if(count >= ticks)
{
return;
}
oldVal = now; //更新oldVal值
}
}
|