为什么以下的流水灯程序只会循环一次?
时间:10-02
整理:3721RD
点击:
#include <reg52.h>
void delay(unsigned int t)
{
unsigned int i;
unsigned char j;
for(i=t;i>0;i--)
for(j=125;j>0;j--);
}
void main()
{
unsigned int i;
P1=0xfe;
while(1)
{
for(i=0;i<8;i++)
{
P1<<=1;
P1=P1|0x01;
delay(2000);
}
}
}
void delay(unsigned int t)
{
unsigned int i;
unsigned char j;
for(i=t;i>0;i--)
for(j=125;j>0;j--);
}
void main()
{
unsigned int i;
P1=0xfe;
while(1)
{
for(i=0;i<8;i++)
{
P1<<=1;
P1=P1|0x01;
delay(2000);
}
}
}
这是肯定了,当你循环完第一次后P1就一直等于0xff了,你在for循环后或之前加一句P1=0xfe;就行了
当for循环中子程序运行8次以后,P1=0xff,所以再往下运行,p1=0xff不变了,流水灯只循环了一次。
明白了,谢谢!