自己写的,数码管只显示有效位。
#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,
};
unsigned char i = 0; // 动态扫描的索引
unsigned int cnt = 0;
unsigned char flag1s = 0; // 1秒定时标志
unsigned long sec = 0;
void main()
{
ENLED = 0;
ADDR3 = 1;
EA = 1;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while(1)
{
if (flag1s == 1)
{
flag1s = 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];
L