#include<reg52.h>
//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};
unsigned long num = 0;
bit flag = 0;
unsigned char k = 0;
void main()
{
unsigned int i = 0;
EA = 1;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while(1)
{
/////////////////////////////////////1秒计时数码管
if(flag == 1)
{
flag = 0;
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];
}
}
}
void InterruptTimer0() interrupt 1
{
static unsigned int cnt = 0;
TH0 = 0xFC;
TL0 = 0x67;
cnt++;
if(cnt >= 1000)
{
cnt = 0;
num++;
flag = 1;
}
P0 = 0xFF;
switch(k)
{
case 0: P0 = Led[0];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[0];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 1: P0 = Led[1];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[1];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 2: P0 = Led[2];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[2];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 3: P0 = Led[3];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[3];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 4: P0 = Led[4];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[4];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 5: P0 = Led[5];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[5];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 6: P0 = Led[6];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[6];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 7: P0 = Led[7];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[7];
Latch_bit = 1;
Latch_bit = 0;
k=0;
break;
default:break;
}
}
//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};
unsigned long num = 0;
bit flag = 0;
unsigned char k = 0;
void main()
{
unsigned int i = 0;
EA = 1;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while(1)
{
/////////////////////////////////////1秒计时数码管
if(flag == 1)
{
flag = 0;
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];
}
}
}
void InterruptTimer0() interrupt 1
{
static unsigned int cnt = 0;
TH0 = 0xFC;
TL0 = 0x67;
cnt++;
if(cnt >= 1000)
{
cnt = 0;
num++;
flag = 1;
}
P0 = 0xFF;
switch(k)
{
case 0: P0 = Led[0];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[0];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 1: P0 = Led[1];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[1];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 2: P0 = Led[2];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[2];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 3: P0 = Led[3];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[3];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 4: P0 = Led[4];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[4];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 5: P0 = Led[5];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[5];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 6: P0 = Led[6];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[6];
Latch_bit = 1;
Latch_bit = 0;
k++;
break;
case 7: P0 = Led[7];
Latch_seg = 1;
Latch_seg = 0;
P0 = LedBuff[7];
Latch_bit = 1;
Latch_bit = 0;
k=0;
break;
default:break;
}
}
1万+

被折叠的 条评论
为什么被折叠?



