#include <reg52.h>
#include <function.h>
u8 code LedChar[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
u8 LedBuff[6]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
void
delay_ms(u16 x)
{
u16 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
LED_Init()
{
P1|=0x0E;
P1&=0xEE;
}
void
SEG_Scan()
{
static
u8 i = 0;
P0 = 0xFF;
P1 = (P1 & 0xF8) | i;
P0 = LedBuff[i];
i++;
if
(i>=6)i=0;
}
void
ShowNumber(u32 num)
{
char
i;
u8 buf[6];
for
(i=0; i<6; i++)
{
buf[i] = num % 10;
num = num / 10;
}
for
(i=5; i>=1; i--)
{
if
(buf[i] == 0)
LedBuff[i] = 0xFF;
else
break
;
}
for
( ; i>=0; i--)
{
LedBuff[i] = LedChar[buf[i]];
}
}