kwjy

持续进阶之三数码管简易时钟显示

0
阅读(1473)

先上代码,持续更新,望大侠见谅,不要嫌弃小弟哦,望大侠高手多多指点小弟,多给小弟提提意见与建议


/*
MCU:STC89C52RC
Fosc:11059200Hz
日期:2014-04-28
网名:坎悟积验
功能:简单的数码管时钟
显示:00-00-00 :hour-fend-miao
*/
#include <reg52.h>

typedef unsigned char Uint8;
typedef unsigned int Uint16;
Uint8 code shuLED[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80,0x40};
#define Pro0 P0

sbit DULA = P1^7;
sbit WELA = P1^6;
Uint16 m = 0;
Uint8 tab[8] = {0};
Uint8 miao = 0,fend = 0,hour = 0;

void main()
{
TMOD  = 0x01;
TH0 = 0xfc; //1MS
TL0 = 0x66;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1)
{
if(m == 1000)
{
m = 0;
miao++;
if(miao == 60)
{
miao = 0;
fend++;
if(fend == 60)
{
fend = 0;
hour++;
if(hour == 24)
{
hour = 0;
}
tab[0] = hour/10;
tab[1] = hour%10;
}
tab[2] = fend/10;
tab[3] = fend%10;
}
tab[4] = miao/10;
tab[5] = miao%10;
}
}
}

void time0() interrupt 1
{
static Uint8 i = 0;
TH0 = 0xfc;
TL0 = 0x66;
m++;
i++;
switch(i)
{
case 1: {
WELA = 1;
Pro0 = 0xfe;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[tab[0]];
DULA = 0;
Pro0 = 0xff;
   };break;
case 2: {
WELA = 1;
Pro0 = 0xfd;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[tab[1]];
DULA = 0;
Pro0 = 0xff;
};break;
case 3: {
WELA = 1;
Pro0 = 0xfb;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[11];
DULA = 0;
Pro0 = 0xff;
};break;
case 4: {
WELA = 1;
Pro0 = 0xf7;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[tab[2]];
DULA = 0;
Pro0 = 0xff;
};break;
case 5: {
WELA = 1;
Pro0 = 0xef;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[tab[3]];
DULA = 0;
Pro0 = 0xff;
};break;
case 6: { 
WELA = 1;
Pro0 = 0xdf;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[11];
DULA = 0;
Pro0 = 0xff;
};break;
case 7: {
WELA = 1;
Pro0 = 0xbf;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[tab[4]];
DULA = 0;
Pro0 = 0xff;
};break;
case 8: {
WELA = 1;
Pro0 = 0x7f;
WELA = 0;
Pro0 = 0xff;
DULA = 1;
Pro0 = shuLED[tab[5]];
DULA = 0;
Pro0 = 0xff;
};break;
}
if(i == 9)i = 0;
}




上实验现象。。。。。。。。。。-^-^-