单片机数码管显示时钟程序Word文档下载推荐.docx
《单片机数码管显示时钟程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《单片机数码管显示时钟程序Word文档下载推荐.docx(8页珍藏版)》请在冰豆网上搜索。
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
ucharnuml,num2,s,si,m,ml,f,fl,num,numf,nums,dingshi;
ucharns,nsl,nf,nf1,numns,numnf;
voiddelay(uintz);
voidkeyscan();
voidkeyscanl();
voidalram();
voiddisplay(ucharm,ucharml,ucharf,ucharf1,uchars,ucharsl);
voiddisplayO(ucharnf,ucharnf1,ucharns,ucharnsl);
voidmain()
{
TMOD二0x01;
//设定定时器0工作方式1
THO=(65536-46080)/256;
TLO=(65536-46080)%256;
EA二1;
//开总中断
ETO=1;
//开定时器0中断
TRO二1;
//启动定时器0中断
numns=12;
numnf=0;
while
(1)
if(dingshi==0)
keyscan();
display(m,ml,f,fl,s,si);
alram();
else
keyscanl();
displayO(nf,nf1,ns,nsl);
}
voidkeyscan()
if(keyl==0)
delay(10);
if(keyl==0)
nums++;
if(nums=:
=24)
nums二0;
while(!
keyl);
if(key2==0)
if(key2=0)
numf++;
if(numf==60)
numf=O;
key2);
display(m,ml,f,fl,s,si);
if(key3==0)
delay(10);
dingshi二'
dingshi;
while(!
key3)
/*if(key4=0)
if(key4==0)
flag二1;
key4);
}*/
voidkeyscanl()
delay仃0);
numns++;
if(numns=24)
numns=0;
//display(nf,nf1,ns,nsl);
numnf++;
if(numnf—60)
dingshi^O;
wh订e(!
key3);
voidalramO
if((numnf==numf)&
&
(numns二二nums))
beep二0;
if(((numnf+l=:
numf)&
(numns~nums))&
(dingshi—O))//一分钟报
时提示
beep=l;
voiddisplayO(ucharnf,ucharnf1,ucharns,ucharnsl)//闹钟显示函数
nf=numnf%10;
nfl=numnf/10;
ns=:
numns%10;
nsl二numns./10;
/*wela=l;
P0=0xc0;
//送位选数据
wela=0;
P0二Oxff;
*/
dula=l;
PO二table[nsl];
dula=0;
PO二Oxff;
wela=l;
PO二Oxfe;
delay
(1);
PO二table[ns]0x80;
PO=Oxff;
PO二Oxfd;
delay
(1);
P0=tableLnf1];
PO=Oxfb;
wela=O;
PO=table[nf];
dula=O;
P0=0xf7;
voiddisplay(ucharm,ucharml,ucharf,ucharfl,uchars,ucharsl)//
时间显示
PO二table[ml];
//秒位第1位
//秒位第2位
//时位第一位
PO=Oxef;
wela=O;
delay
(1);
PortableIm];
dula=0;
wela=l;
PO二Oxdf;
wela=0;
P0=table[si];
Portable[s]0x80;
delay
(1);
P0=table[fl]:
//分位第一位
wela二0;
PO二table[f]0x80;
voidT0_timer()interrupt1
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
num2++;
if(num2=20)
num++;
num2=0;
m=:
num%10;
ml二num/10;
f=numf%10;
f1二numf/10;
s=nums%10;
signums/10;
if(num—59)
num^O;
if(numf二二59)
if(nums二二24)nums=O;
voiddelay(uintz)
uintx,y;
for(x=110;
x>
0;
x--)
for(y=z;
y>
y一一);