#include<reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
unsigned char code ledchar[] ={0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E};
unsigned char ledbuff[] = {0xff,0xff,0xff,0xff,0xff,0xff};
void main()
{
unsigned int cnt = 0;
unsigned long sec = 0;
unsigned char i = 0;
ADDR3 = 1;
ENLED = 0;
TMOD = 0x01;
TH0 = 0xfc;
TL0 = 0x67;
TR0 = 1;
while(1)
{
if(TF0 == 1)
{
TF0 = 0;
TH0 = 0xfc;
TL0 = 0x00;
cnt++;
if(cnt == 1000)
{
cnt = 0;
sec++;
ledbuff[0] = ledchar[sec%10];
ledbuff[1] = ledchar[sec/10%10];
ledbuff[2] = ledchar[sec/100%10];
ledbuff[3] = ledchar[sec/1000%10];
ledbuff[4] = ledchar[sec/10000%10];
ledbuff[5] = ledchar[sec/100000%10];
}
P0 = 0xff;
switch(i)
{
case 0: ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=ledbuff[0];break;
case 1: ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=ledbuff[1];break;
case 2: ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=ledbuff[2];break;
case 3: ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=ledbuff[3];break;
case 4: ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=ledbuff[4];break;
case 5: ADDR2=1; ADDR1=0; ADDR0=1; i=0; P0=ledbuff[5];break;
default:break; //会有跳动这种情况
}
}
}
}
|