金牌会员
 
- 积分
- 1780
- 金钱
- 1780
- 注册时间
- 2014-6-27
- 在线时间
- 964 小时
|
发表于 2024-6-25 10:10:45
|
显示全部楼层
那个延时计算看起来是有点头疼,有更简单的:
//理论最大误差有1ms
//进while时候,如果一个节拍刚好完成,立马x1!=x2,则误差有1ms
//就算不成立,误差范围0MS-1ms
void comm_ms_dly(u32 ms)
{
u32 x1,x2;
x2=x1=comm_get_ms();
while(ms)
{
x1=comm_get_ms();
if(x1!=x2)
{
ms--;
x2=x1;
}
}
}
void comm_s_dly(u32 s)//最大延时几十年
{
while(s)
{
comm_ms_dly(1000);
s--;
}
}
delay延时应该考虑以us为基准,得到的延时理论误差就是us级别了,滴答节拍则没有1MS限制,5MS,10MS等随意设置。
void comm_ms_dly(u32 ms)
{
while(ms)
{
comm_us_dly(1000);
}
} |
|