楼主有点不明白你的意思的,至少使用5位的数码管才能显示出你要的这种形式啊,前两位是分钟,后两位代表秒,是这意思吗?这个程序显示的000:00,你可以自己把高位的0去掉,变成00:00
#include"reg52.h"
#define uchar unsigned char
#define uint unsigned int
sbit DULA = P2^6; //74H573控制位,控制数码管段码输出
sbit WELA = P2^7; //74H573控制位,控制数码管位码输出
uchar minute = 0;
uchar second = 0;
uchar T0RH = 0;
uchar T0RL = 0;
uint cnt = 0; //秒计数器
uchar LedBuff[6] = {0X00,0X00,0X00,0X00,0X00,0X00}; //数码管显示缓冲区
uchar code LedChar[] = { //数码管显示编码表
0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07, //0~7
0X7F,0X6F,0X77,0X7C,0X39,0X5E,0X79,0X71,0X09 //8~15 :
};
void ConfigTimer0(uint ms); //定时器0初始化,确定定时时间
void LedShow(uchar minute,uchar second);
void main()
{
EA = 1;
ConfigTimer0(1); //初始化定时器0,定时时间1ms
while(1)
{
if(cnt>=1000)
{
cnt = 0;
second++;
if(second>=60)
{
second = 0;
minute++;
if(minute>=2)
{
minute = 0;
}
}
}
LedShow(minute,second);
}
}
void ConfigTimer0(uint ms)
{
unsigned long temp;
temp = 11059200/12;
temp = temp*ms/1000;
temp = 65536 - temp;
T0RH = (uchar)(temp>>8);
T0RL = (uchar)temp;
TMOD &= 0XF0;
TMOD |= 0X01;
TH0 = T0RH;
TL0 = T0RL;
TR0 = 1;
ET0 = 1;
}
void LedShow(uchar minute,uchar second)
{
uchar buff[6];
uchar i;
buff[0] = second%10;
buff[1] = second/10;
buff[2] = 16;
buff[3] = minute%10;
buff[4] = minute/10;
buff[5] = 0;
for(i=0;i<6;i++)
LedBuff[ i] = LedChar[buff[ i]];
}
void LedScanf()
{
static uchar i = 0;
P0 = 0X00;
DULA = 1;
P0 = LedBuff[ i];
DULA = 0;
P0 = 0XFF;
WELA = 1;
P0 = ~(0X20>>i);
WELA = 0;
i++;
if(i>5)
i = 0;
}
void interrupttimer0() interrupt 1
{
TH0 = T0RH;
TL0 = T0RL;
LedScanf();
cnt++;
}