单片机C语言流水灯延时

来源:百度知道 编辑:UC知道 时间:2024/06/07 09:34:49
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
void yanshi();
sbit p0_1=P0^0;
uint i=500,j;
main()
{
while(1)
{
p0_1=0;
while(i--);
p0_1=1;
while(i--);
}
}

这个程序在KEIL上面仿真的时候无论i最开始为多少,一个循环的时间都是0.9秒?为什么会出现这种情况?
有没有可能是软件的问题?我拿一些正确的程序在上面仿真的时候,时间也经常是出错的...(晶振调的没有问题)
为什么延时会不受i控制?

#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit p0_1=P0^0;
uint i;
main()
{
while(1)
{
i = 500;
p0_1=0;
while(i--);
i = 500;
p0_1=1;
while(i--);
}
}
这下试试,应该是可以了

延时的话你用中断啊,用循环定时不准确

函数没有调用

有可能是变量i定义的问题,我以前也碰到过,你将i放在主函数内定义试试~ @ # % @ & *……%……~ ~