这是本人慢慢调出来的参数,有误差是必须的,除非用汇编才会精确,后续我会更新修改,尽量精确。
调试环境:Keil V4.02本文引用地址:http://www.eepw.com.cn/article/201611/315933.htm
源代码如下:
#include #include
//--延时0.2*n(ms)函数,若需延时1ms,则*5。适合延时50ms以下或左右的--//
void DelayMSx02(unsigned char n)
{
unsigned char x, y;
for(x=n; x>0; x--)
for(y=96; y>0; y--); //for循环中的"--"位置前后都可以
}
//--延时t*2+5(us)函数 --//
void DelayUSx2a5(unsigned char t)
{
while(--t);//while循环中要注意"--"的位置,放前面比放后面时间要短很多
}
//--大概延时1mS--//
void DelayMS(unsigned char t)
{
while(t--)
{
DelayUSx2a5(234);
DelayUSx2a5(256);
}
}
int main()
{
DelayMS(1); //延时1ms
DelayMSx02(5*1); //延时1ms
DelayUSx2a5(1); //延时7us
_nop_(); //延时1us
return 0;
}