用單片機(jī)定時(shí)器編制電子時(shí)鐘程序?qū)嵗?/h1>
?。保绦蚪Y(jié)構(gòu)采用主程序和中斷服務(wù)子程序結(jié)構(gòu).
?。玻〞r(shí)中斷程序
定時(shí)器1于方式1,16位,10ms中斷一次
40H10ms計(jì)數(shù)單元
41H秒計(jì)數(shù)單元
42H分計(jì)數(shù)單元
43H時(shí)計(jì)數(shù)單元
定時(shí)方式1為10MS:THX=0ECH,TLX=78H
方式0為10MS: THX=63H,TLX=18H
3.參考程序
;
DISPEQU0DE00H;顯示子程序入口
;
ORG0000H
START:AJMPMAIN
;
ORG001BH;定時(shí)器1中斷服
AJMPTINT1;務(wù)程序入口
;
ORG0030H
MAIN:MOVR0,#39H;顯示緩沖區(qū)初始化內(nèi)容來自單片機(jī)之家www.dpj100.com
MAIN_0:MOV@R0,#0
INCR0
CJNER0,#44H,#0
MOVTMOD,#10H
MOVIE,#10001000B
MOVTH1,#0ECH;10ms:EC78H
MOVTL1,#78H
SETBTR1
MAIN_1:LCALLDISP;主程序循環(huán)
SJMPMAIN_1
;
;定時(shí)器1中斷服務(wù)程序
TINT1:MOVTH1,#0ECH
MOVTL1,#78H
PUSHACC
PUSHPSW
INC40H
MOVA,40H
CJNEA,#100,TINT1R
MOV40H,#0
MOVA,41H;秒單元加1
INCA
DAA
MOV41H,A
CJNEA,#60H,TINT10
MOV41H,#0
MOVA,42H;分單元加1
INCA
DAA
MOV42H,A
CJNEA,#60H,TINT10
MOV42H,#0
MOVA,43H;小時(shí)單元加1
INCA
DAA
MOV43H,A
CJNEA,#24H,TINT10
MOV43H,#0
TINT10:MOVA,41H;秒拆字
ANLA,#0FH
MOV39H,A
MOVA,41H
ANLA,#0F0H
SWAPA
MOV3AH,A
MOVA,42H;分拆字
ANLA,#0FH
MOV3BH,A
MOVA,42H
ANLA,#0F0H
SWAPA
MOV3CH,A
MOVA,43H;小時(shí)拆字
ANLA,#0FH
MOV3DH,A
MOVA,43H
ANLA,#0F0H
SWAPA
MOV3EH,A
TINT1R:POPPSW
POPACC
RETI