#include <reg52.h>
sbit ADDR2 = P1^2;
sbit ADDR1 = P1^1;
sbit ADDR0 = P1^0;
sbit ENLED = P1^4;
sbit ADDR3 = P1^3;
sbit LED2 = P0^0;
sbit KEY4 = P2^7;
unsigned
char
code LedChar[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
unsigned
char
LedBuff[6]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned
char
cnt=0;
void
SEG_task()
{
static
unsigned
char
i=0;
LedBuff[0]= LedChar[cnt%10];
if
(cnt>=10) LedBuff[1]= LedChar[(cnt/10)%10];
if
(cnt>=100)LedBuff[2]= LedChar[(cnt/100)%10];
if
(cnt==0){ LedBuff[1]=0xFF;LedBuff[2]=0XFF; }
P0=0xFF;
switch
(i)
{
case
0:
ADDR2 = 0;ADDR1 = 0;ADDR0 = 0;P0=LedBuff[0];i++;
break
;
case
1:
ADDR2 = 0;ADDR1 = 0;ADDR0 = 1;P0=LedBuff[1];i++;
break
;
case
2:
ADDR2 = 0;ADDR1 = 1;ADDR0 = 0;P0=LedBuff[2];i=0;
break
;
}
}
void
main()
{
unsigned
char
key_up=1;
unsigned
int
times=0;
ADDR3 = 1;
ENLED = 0;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
P2 = 0xF7;
while
(1)
{
SEG_task();
if
(key_up==0)
{
if
(KEY4==1)
{
cnt++;
}
}
key_up=KEY4;
}
}