1.程序结构采用主程序和中断服务子程序结构.
2.定时中断程序
定时器1于方式1,16位,10ms中断一次
40H10ms计数单元
41H秒计数单元
42H分计数单元
43H时计数单元
定时方式1为10MS:THX=0ECH,TLX=78H
方式0为10MS: THX=63H,TLX=18H
3.参考程序
;
DISPEQU0DE00H;显示子程序入口
;
ORG0000H
START:AJMPMAIN
;
ORG001BH;定时器1中断服
AJMPTINT1;务程序入口
;
ORG0030H
MAIN:MOVR0,#39H;显示缓冲区初始化内容来自单片机之家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;主程序循环
SJMPMAIN_1
;
;定时器1中断服务程序
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;小时单元加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;小时拆字
ANLA,#0FH
MOV3DH,A
MOVA,43H
ANLA,#0F0H
SWAPA
MOV3EH,A
TINT1R:POPPSW
POPACC
RETI