单片机delay函数延迟时间计算,delay(80);为什么是600us左右?函数定义void delay(unsigned int t){while(t--);}主函数中delay(80);为什么是600us左右?

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 12:08:29

单片机delay函数延迟时间计算,delay(80);为什么是600us左右?函数定义void delay(unsigned int t){while(t--);}主函数中delay(80);为什么是600us左右?
单片机delay函数延迟时间计算,delay(80);为什么是600us左右?
函数定义
void delay(unsigned int t)
{
while(t--);
}
主函数中delay(80);为什么是600us左右?

单片机delay函数延迟时间计算,delay(80);为什么是600us左右?函数定义void delay(unsigned int t){while(t--);}主函数中delay(80);为什么是600us左右?
只有汇编语言才能得到精确的时间.C编译成汇编时,不同的编译器,不同的编译策略都会使最终的程序不一样.
如果短时间的延时,可以利用_nop_()来控制,如果是长时间的可以用定时器中断来控制.
你自己写函数的话,可以在KEIL调试模式下,单步运行,看左侧窗口中的second,那个是程序从复位到当前的运行秒数(可以看到微妙级的),用不同的参数调用delay,比较下,记住差值就可以了.别忘了把项目使用的晶振数填正确.