51单片机数字钟实验Word文件下载.docx
《51单片机数字钟实验Word文件下载.docx》由会员分享,可在线阅读,更多相关《51单片机数字钟实验Word文件下载.docx(10页珍藏版)》请在冰豆网上搜索。
区域中的P3.0-P3.7端口用8芯排线连接到“动态数码显示”区域中的S1-S8端口上;
把“单片机系统”区域中的P0.0/AD0、P0.1/AD1、P0.2/AD2端口分别用导线连接到“独立式键盘”区域中的SP3、SP2、SP1端口上;
4.相关基本知识
动态数码显示的方法
独立式按键识别过程
“时”,“分”,“秒”数据送出显示处理方法
5.程序框图
6.汇编源程序
SECONDEQU30H
MINITEEQU31H
HOUREQU32H
HOURKBITP0.0
MINITEK
BITP0.1
SECONDK
BITP0.2
DISPBUF
EQU40H
DISPBIT
EQU48H
T2SCNTA
EQU49H
T2SCNTB
EQU4AH
TEMPEQU4BH
ORG00H
LJMPSTART
ORG0BH
LJMPINT_T0
START:
MOVSECOND,#00H
MOVMINITE,#00H
MOVHOUR,#12
MOVDISPBIT,#00H
MOVT2SCNTA,#00H
MOVT2SCNTB,#00H
MOVTEMP,#0FEH
LCALLDISP
MOVTMOD,#01H
MOVTH0,#(65536-2000)/256
MOVTL0,#(65536-2000)MOD256
SETBTR0
SETBET0
SETBEA
WT:
JBSECONDK,NK1
LCALLDELY10MS
INCSECOND
MOVA,SECOND
CJNEA,#60,NS60
NS60:
JNBSECONDK,$
NK1:
JBMINITEK,NK2
INCMINITE
MOVA,MINITE
CJNEA,#60,NM60
NM60:
JNBMINITEK,$
NK2:
JBHOURK,NK3
INCHOUR
MOVA,HOUR
CJNEA,#24,NH24
MOVHOUR,#00H
NH24:
JNBHOURK,$
NK3:
LJMPWT
DELY10MS:
MOVR6,#10
D1:
MOVR7,#248
DJNZR7,$
DJNZR6,D1
RET
DISP:
MOVA,#DISPBUF
ADDA,#8
DECA
MOVR1,A
MOVB,#10
DIVAB
MOV@R1,A
DECR1
MOVA,B
MOVA,#10
MOV@R1,A
INT_T0:
ADDA,DISPBIT
MOVR0,A
MOVA,@R0
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP1,A
MOVA,DISPBIT
MOVDPTR,#TAB
MOVP3,A
INCDISPBIT
CJNEA,#08H,KNA
KNA:
INCT2SCNTA
MOVA,T2SCNTA
CJNEA,#100,DONE
INCT2SCNTB
MOVA,T2SCNTB
CJNEA,#05H,DONE
CJNEA,#60,NEXT
CJNEA,#24,NEXT
NEXT:
DONE:
RETI
TABLE:
DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H
TAB:
DB0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH
END
7.C语言源程序
#include<
AT89X51.H>
unsignedcharcodedispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsignedchardispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsignedchardispbuf[8]={0,0,16,0,0,16,0,0};
unsignedchardispbitcnt;
unsignedcharsecond;
unsignedcharminite;
unsignedcharhour;
unsignedinttcnt;
unsignedcharmstcnt;
unsignedchari,j;
voidmain(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
while
(1)
{
if(P0_0==0)
for(i=5;
i>
0;
i--)
for(j=248;
j>
j--);
second++;
if(second==60)
second=0;
}
dispbuf[0]=second%10;
dispbuf[1]=second/10;
while(P0_0==0);
if(P0_1==0)
minite++;
if(minite==60)
minite=0;
dispbuf[3]=minite%10;
dispbuf[4]=minite/10;
while(P0_1==0);
if(P0_2==0)
hour++;
if(hour==24)
hour=0;
dispbuf[6]=hour%10;
dispbuf[7]=hour/10;
while(P0_2==0);
}
voidt0(void)interrupt1using0
mstcnt++;
if(mstcnt==8)
mstcnt=0;
P1=dispcode[dispbuf[dispbitcnt]];
P3=dispbitcode[dispbitcnt];
dispbitcnt++;
if(dispbitcnt==8)
dispbitcnt=0;
tcnt++;
if(tcnt==4000)
tcnt=0;
}