8279做的时钟程序C语言源代码
扫描二维码
随时随地手机看文章
#include
#include
#define Z8279 XBYTE[0x8FFF] //定义外部命令口
#define D8279 XBYTE[0x8FFE] //定义外部数据口
#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) //在正常显示情况下显示各位数字
{
Z8279=LEDWR0;
D8279=led[sec2];
D8279=led[sec1];
D8279=0x40;
D8279=led[min2];
D8279=led[min1];
D8279=0x40;
D8279=led[hour2];
D8279=led[hour1];
}
}