首先使用数学思想
1111 1111=255
1111 1110=255-2^0(代表2的0次方)
1111 1101=255-2^1
:
:
0111 1111=255-2^7
所以根据以上的思想来编写流水灯
#include<reg52.h>
#include<math.h>
sbit led1=P1^1;
delay(int xms)
{
int i,j;
for(i=xms;i>=0;i--)
for(j=112;j>=0;j--);
}
main()
{
int i;
while(1);
{
for(i=1;i<=7;i++)
{
P1=255-pow(2,i);
delay(1000);
}
}
}