8279做的時鐘程序C語言源代碼
#includereg52.h>
#includeabsacc.h>
#define Z8279 XBYTE[0x8FFF] //定義外部命令口
#define D8279 XBYTE[0x8FFE] //定義外部數(shù)據(jù)口
#define LEDWR0 0x90 //寫端口命令
#define uchar unsigned char
void view8279(void);
uchar hour1=0,hour2=0,min1=0,min2=0,sec1=0,sec2=0,num_20; //時分秒的十位和個位,初值為零
uchar led[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};//定義0到F的鍵碼
void main(void)
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
IE=0x82;
TR0=1;
num_20=20;
while(1)
{}
}
void shizhong(void) interrupt 1
{ //7
TH0=0x3c;
TL0=0xb0;
num_20--;
if(num_20!=0) return;
if(sec1==5 sec2==9)
{ //05
sec1=0;
sec2=0;
if(min1==5 min2==9)
{ //03
min1=0;
min2=0;
if(hour1==5 hour2==9)
{ //01
hour1=0;
hour2=0;
} //01
else if(hour2==9)
{ //02
hour1++;
hour2=0;
} //02
else hour2++;
} //03
else if(min2==9)
{ //04
min1++;
min2=0;
} //04
else min2++;
}
//05
else if(sec2==9)
{ //06
sec1++;
sec2=0;
} //06
else sec2++;
view8279();
num_20=20; //7
}
void view8279(void)
{
if (1) //在正常顯示情況下顯示各位數(shù)字
{
Z8279=LEDWR0;
D8279=led[sec2];
D8279=led[sec1];
D8279=0x40;
D8279=led[min2];
D8279=led[min1];
D8279=0x40;
D8279=led[hour2];
D8279=led[hour1];
}
}
評論