这两张要清晰一点:
流水灯代码:
#include <reg52.h>
unsigned char code seg[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0x00,0,0x55,0x55,0xaa,0xaa};
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
unsigned char i;
while(1)
{
P1=0xFE;
for(i=0;i<8;i++)
{
delay(10000);
P1 <<=1;
}
P1=0x7F;
for(i=0;i<8;i++)
{
delay(10000);
P1 >>=1;
}
P1=0xFE;
for(i=0;i<8;i++)
{
delay(10000);
P1 <<=1;
P1 |=0x01;
}
P1=0x7F;
for(i=0;i<8;i++)
{
delay(10000);
P1 >>=1;
P1 |=0x80;
}
for(i=0;i<16;i++)
{
delay(20000);
P1=seg[i];
}
}
}
#include <reg52.h>
unsigned char code seg[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0x00,0,0x55,0x55,0xaa,0xaa};
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
unsigned char i;
while(1)
{
P1=0xFE;
for(i=0;i<8;i++)
{
delay(10000);
P1 <<=1;
}
P1=0x7F;
for(i=0;i<8;i++)
{
delay(10000);
P1 >>=1;
}
P1=0xFE;
for(i=0;i<8;i++)
{
delay(10000);
P1 <<=1;
P1 |=0x01;
}
P1=0x7F;
for(i=0;i<8;i++)
{
delay(10000);
P1 >>=1;
P1 |=0x80;
}
for(i=0;i<16;i++)
{
delay(20000);
P1=seg[i];
}
}
}
















我要赚赏金
