#include <reg52.h>
sbit LATCH_bit = P2^3;
sbit LATCH_seg = P2^2;
sbit SPK=P0^2;
unsigned int LED[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90/*,0x88,0x83,0xc6,0xa1,0x86,0x8e*/};
void delay(int n);
void DelayMs(unsigned char t);
void DelayUs2x(unsigned char t);//函数声明
unsigned char misec_10;
unsigned char sec;
void main()
{
unsigned int i;
TMOD = 0x01;
TH0 = 0xd8;
TL0 = 0xf0;
EA = 1;
ET0 = 1;
TR0 = 1;
misec_10 = 0;
sec = 10;
while(1)
{
P1 = 0xfb;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[misec_10/10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
P1 = 0xf7;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[misec_10%10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
P1 = 0xfe;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[sec/10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
P1 = 0xfd;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[sec%10];
P1 += 0x80;
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
if(misec_10 == 0)
{
misec_10 = 99;
sec--;
DelayUs2x(200);
DelayUs2x(200);
SPK=!SPK;
if(sec == 255)
{
sec = 10;
for(i=0;i<500;i++)
{
DelayMs(1);
SPK=!SPK;
}
delay(3000);
}
}
}
}
void delay(int n)
{
while(n--);
}
void TSR_T0(void) interrupt 1
{
TH0 = 0xd8;
TL0 = 0xf0; //0xd8f0 == 55536
misec_10--;
}
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延时1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void DelayUs2x(unsigned char t)
{
while(--t);
}
sbit LATCH_bit = P2^3;
sbit LATCH_seg = P2^2;
sbit SPK=P0^2;
unsigned int LED[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90/*,0x88,0x83,0xc6,0xa1,0x86,0x8e*/};
void delay(int n);
void DelayMs(unsigned char t);
void DelayUs2x(unsigned char t);//函数声明
unsigned char misec_10;
unsigned char sec;
void main()
{
unsigned int i;
TMOD = 0x01;
TH0 = 0xd8;
TL0 = 0xf0;
EA = 1;
ET0 = 1;
TR0 = 1;
misec_10 = 0;
sec = 10;
while(1)
{
P1 = 0xfb;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[misec_10/10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
P1 = 0xf7;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[misec_10%10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
P1 = 0xfe;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[sec/10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
P1 = 0xfd;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[sec%10];
P1 += 0x80;
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);
if(misec_10 == 0)
{
misec_10 = 99;
sec--;
DelayUs2x(200);
DelayUs2x(200);
SPK=!SPK;
if(sec == 255)
{
sec = 10;
for(i=0;i<500;i++)
{
DelayMs(1);
SPK=!SPK;
}
delay(3000);
}
}
}
}
void delay(int n)
{
while(n--);
}
void TSR_T0(void) interrupt 1
{
TH0 = 0xd8;
TL0 = 0xf0; //0xd8f0 == 55536
misec_10--;
}
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延时1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void DelayUs2x(unsigned char t)
{
while(--t);
}