這位同學(xué)你好,你的程序我給你寫在這里,列清楚了給你解釋下
#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);
}
這是你的程序,在這里,有問題的地方我已經(jīng)給你標(biāo)注出來 。頭文件你沒有寫完整。重要的是你的while(1)語句位置放錯了。你的這個順序,在主函數(shù)執(zhí)行一遍了以后到達(dá)while(1)這里,就形成了死循環(huán),就會停留在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;
}
} |