#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit RED1=P1^0;
sbit RED2=P1^3;
sbit RED3=P1^6;
sbit RED4=P3^1;
sbit YEL1=P1^1;
sbit YEL2=P1^4;
sbit YEL3=P1^7;
sbit YEL4=P3^2;
sbit GRE1=P1^2;
sbit GRE2=P1^5;
sbit GRE3=P3^0;
sbit GRE4=P3^3;
void Delay(uchar i)
{
uchar x;
uchar y;
for(y=0;y<i;y++)
for(x=0;x<=148;x++);
}
void main()
{
void Delay(uchar);
void LED1(uchar,uchar,uchar);
void LED2(uchar,uchar,uchar);
void LED3(uchar,uchar,uchar);
void LED4(uchar,uchar,uchar);
uchar a,b,c;
while(1)
{
a=6,b=5,c=5;
LED1(a,b,c);
a=2,b=5,c=1;
LED2(a,b,c);
a=4,b=3,c=5;
LED3(a,b,c);
a=2,b=1,c=1;
LED4(a,b,c);
}
}
void LED1(uchar c,uchar c1,uchar c2)
{
uchar b;
RED1=0;
RED3=0;
GRE2=0;
GRE4=0;
for(b=0;b<120;b++)
{
P2=0xfe;
P0=table[c1];
Delay(5);
P2=0xef;
P0=table[c2];
Delay(5);
}
if(c!=1)
LED1(--c,--c1,--c2);
else
{
P1=0xff;
P3=0xff;
}
}
void LED2(uchar c,uchar c1,uchar c2)
{
uchar b;
GRE1=0;
GRE3=0;
YEL2=0;
YEL4=0;
for(b=0;b<120;b++)
{
P2=0xfe;
P0=table[c1];
Delay(5);
P2=0xef;
P0=table[c2];
Delay(5);
}
if(c!=1)
LED2(--c,--c1,--c2);
else
{
P1=0xff;
P3=0xff;
}
}
void LED3(uchar c,uchar c1,uchar c2)
{
uchar b;
RED2=0;
RED4=0;
GRE1=0;
GRE3=0;
for(b=0;b<120;b++)
{
P2=0xfe;
P0=table[c1];
Delay(5);
P2=0xef;
P0=table[c2];
Delay(5);
}
if(c!=1)
LED3(--c,--c1,--c2);
else
{
P1=0xff;
P3=0xff;
}
}
void LED4(uchar c,uchar c1,uchar c2)
{
uchar b;
RED2=0;
RED4=0;
YEL1=0;
YEL3=0;
for(b=0;b<120;b++)
{
P2=0xfe;
P0=table[c1];
Delay(5);
P2=0xef;
P0=table[c2];
Delay(5);
}
if(c!=1)
LED4(--c,--c1,--c2);
else
{
P1=0xff;
P3=0xff;
}
}