这位同学你好,你的程序我给你写在这里,列清楚了给你解释下
#incoude<reg52.h>
sbit p=P1^0;
void delay(int i)
{
for(; i>0;i--)
for(j=100;j>0;j--);
}
void main()
{
{
int x;
for(x=20;x>0;x--)
{
p=~p;
delay(100);
}
}
while(1);
}
这是你的程序,在这里,有问题的地方我已经给你标注出来 。头文件你没有写完整。重要的是你的while(1)语句位置放错了。你的这个顺序,在主函数执行一遍了以后到达while(1)这里,就形成了死循环,就会停留在while(1)这里。所以想要让小灯闪烁的话,这里只需要把while(1)去掉即可。令外附上我自己写的程序,你参考一下
#include<reg52.h>
#define uchar unsigned char
sbit light=P1^0;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
while(1)
{
delay(500);
light=~light;
}
} |