#include <reg52.h>
sbit ADDR2 = P1^2;
sbit ADDR1 = P1^1;
sbit ADDR0 = P1^0;
sbit ENLED = P1^4;
sbit ADDR3 = P1^3;
sbit KEY4 = P2^7;
unsigned
char
code LedChar[6]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF};
void
delay_ms(unsigned
int
x)
{
unsigned
int
i,j;
if
(x==1000)
{
for
(i=0;i<19601;i++)
{
for
(j=5;j>0;j--);
}
}
else
while
(x--)
for
(j=115;j>0;j--);
}
void
IO0_OUT()
{ADDR2 = 0;ADDR1 = 0;ADDR0 = 0;}
void
IO1_OUT()
{ADDR2 = 0;ADDR1 = 0;ADDR0 = 1;}
void
IO2_OUT()
{ADDR2 = 0;ADDR1 = 1;ADDR0 = 0;}
void
IO3_OUT()
{ADDR2 = 0;ADDR1 = 1;ADDR0 = 1;}
void
IO4_OUT()
{ADDR2 = 1;ADDR1 = 0;ADDR0 = 0;}
void
IO5_OUT()
{ADDR2 = 1;ADDR1 = 0;ADDR0 = 1;}
void
main()
{
unsigned
char
i=0;
ADDR3 = 1;
ENLED = 0;
P2 = 0xF7;
while
(1)
{
P0=0xFF;
switch
(i)
{
case
0: IO0_OUT();P0=LedChar[0];
break
;
case
1: IO0_OUT();P0=LedChar[1];
break
;
case
2: IO0_OUT();P0=LedChar[2];
break
;
case
3: IO0_OUT();P0=LedChar[3];
break
;
case
4: IO1_OUT();P0=LedChar[3];
break
;
case
5: IO2_OUT();P0=LedChar[3];
break
;
case
6: IO3_OUT();P0=LedChar[3];
break
;
case
7: IO4_OUT();P0=LedChar[3];
break
;
case
8: IO5_OUT();P0=LedChar[3];
break
;
case
9: IO5_OUT();P0=LedChar[4];
break
;
case
10:IO5_OUT();P0=LedChar[5];
break
;
case
11:IO5_OUT();P0=LedChar[0];
break
;
case
12:IO4_OUT();P0=LedChar[0];
break
;
case
13:IO3_OUT();P0=LedChar[0];
break
;
case
14:IO2_OUT();P0=LedChar[0];
break
;
case
15:IO1_OUT();P0=LedChar[0];
break
;
}
if
(KEY4==0)i++;
if
(i>=16)i=0;
delay_ms(30);
}
}