#include
//sbit Led1 = P0^0;
sbit Latch_seg = P2^0;
sbit Latch_bit = P2^1;
void delay(unsigned char cnt);
/*unsigned char code LedChar[16]={
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E
};*/
unsigned char code LedChar[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code LedBuff[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};
unsigned char Led[8]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
void main()
{
unsigned int cnt = 0;
unsigned int i = 0;
unsigned long num = 0;
TMOD = 0x01;
TH0 = 0xB8;
TL0 = 0x00;
TR0 = 1;
while(1)
{
/1秒计时数码管
Led[7] = LedChar[num%10];
Led[6] = LedChar[num/10%10];
Led[5] = LedChar[num/100%10];
Led[4] = LedChar[num/1000%10];
Led[3] = LedChar[num/10000%10];
Led[2] = LedChar[num/100000%10];
Led[1] = LedChar[num/1000000%10];
Led[0] = LedChar[num/10000000%10];
for(i=0;i<8;i++)
{
P0 = Led[i];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[i];
Latch_bit = 1;
Latch_bit = 0;
delay(1);
}
if(TF0 == 1)
{
TF0 = 0;
TH0 = 0xB8;
TL0 = 0x00;
cnt++;
if(cnt >= 50)
{
cnt = 0;
num++;
}
}
数码管0~F隔一秒显示
/*if(TF0 == 1)
{
TF0 = 0;
TH0 = 0xB8;
TL0 = 0x00;
cnt++;
if(cnt >= 50)
{
cnt = 0;
P0 = LedChar[i++];
if(i>=16)
{
i = 0;
}
}
} */
///Led1秒闪烁
/*if(TF0 == 1)
{
TF0 = 0;
TH0 = 0xB8;
TL0 = 0x00;
cnt++;
if(cnt >= 50)
{
cnt = 0;
Led1 = ~Led1;
}
}*/
}
}
void delay(unsigned char cnt)
{
unsigned char i,j;
for(i=0;i<125;i++)
{
for(j=0;j }
}