内部RAM寄存器分配
30H MS 50mS单元
31H SECS 秒单元
32H MINUTE 分单元
33H HOUR 时单元
34H DM 显示缓冲区首地址
3AH S1 设置定时数据缓冲区首地址 秒数据“00” 缓冲
3BH M1 分设置数据缓冲
3CH H1 时设置数据缓冲
3DH TABB 存储定时数据区首地址
程序清单
SW1 EQU P1.0
SW2 EQU P1.1
SW3 EQU P1.2
SW4 EQU P1.3
BU EQU P3.0
MS EQU 30H
SECS EQU 31H
MINUTE EQU 32H
HOUR EQU 33H
DM EQU 34H
S1 EQU 3AH
M1 EQU 3BH
H1 EQU 3CH
TABB EQU 3DH
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0INT
ORG 0030H
;主程序
MAIN:MOV S1,#0
MOV M1,#0
MOV H1,#0
MOV SP,#70H
CLR F0
SETB EA
SETB ET0
MOV TMOD,#01H
MOV TL0,#0B0H
MOV TH0,#3CH
MOV MS,#0
MOV SECS,#0
MOV MINUTE,#0
MOV HOUR,#12H
SETB TR0
LOOP: MOV R0,#SECS
LCALL CF
LCALL DISP
LCALL COMP
JB SW3,LOOP
LCALL SET
SJMP LOOP
;定时设置
SET: LCALL CLEAR
LCALL BB
SET0:MOV R0,#S1
LCALL CF
LCALL DISP
JNB SW3,SET0
SETB F0
MOV TABB,#40H
SET1:MOV R0,#S1
LCALL CF
LCALL DISP
JNB SW1,SETH
JNB SW2,SETM
JNB SW3,SAVE
JB SW4,SET1
SJMP SEXIT
;设置分定时值
SETM:MOV R0,#S1
LCALL CF
LCALL DISP
JNB SW2,SETM
MOV A,M1
ADD A,#1
DA A
MOV M1,A
CJNE A,#60H,SET1
MOV M1,#0
SJMP SET1
;设置时定时值
SETH:MOV R0,#S1
LCALL CF
LCALL DISP
JNB SW1,SETH
MOV A,H1
ADD A,#1
DA A
MOV H1,A
CJNE A,#24H,SET1
MOV H1,#0
SJMP SET1
;存储定时值
SAVE:MOV R0,#S1
LCALL CF
LCALL DISP
JNB SW3,SAVE
LCALL BB
MOV R0,TABB
MOV @R0,H1
INC R0
MOV @R0,M1
INC R0
MOV TABB,R0
CJNE R0,#70H,SET1
SEXIT:LCALL BB
CLR F0
RET
;清零程序
CLEAR: MOV R0,#40H
MOV A,#0FFH
CLEAR1:MOV @R0,A
INC R0
CJNE R0,#70H,CLEAR1
RET
;“嘀—”提示音
BB:MOV R5,#80H
BB1:MOV R6,#80H
DJNZ R6,$
CPL BU
DJNZ R5,BB1
SETB BU
RET
;定时比较
COMP:MOV R1,#40H
COMP1:MOV A,@R1
CJNE A,HOUR,COMP5
INC R1
MOV A,@R1
CJNE A,MINUTE,COMP6
CLR BU
comp4:MOV R0,#SECS
LCALL CF
LCALL DISP
MOV A,SECS
JZ COMP4
SETB BU
RET
COMP5:INC R1
COMP6:INC R1
CJNE R1,#70H,COMP1
RET
;T0中断计时
T0INT:PUSH ACC
MOV TL0,#0B0H
MOV TH0,#3CH
INC MS
MOV A,MS
CJNE A,#20,T0EXIT
MOV MS,#0
JB F0,T0INT1
JNB SW1,VH
JNB SW2,VM
T0INT1:MOV A,SECS
ADD A,#1
DA A
MOV SECS,A
CJNE A,#60H,T0EXIT
MOV SECS,#0
MOV A,MINUTE
ADD A,#1
DA A
MOV MINUTE,A
CJNE A,#60H,T0EXIT
MOV MINUTE,#0
MOV A,HOUR
ADD A,#1
DA A
MOV HOUR,A
CJNE A,#24H,T0EXIT
MOV HOUR,#0
T0EXIT:POP ACC
RETI
;校分
VM:MOV A,MINUTE
ADD A,#1
DA A
MOV MINUTE,A
CJNE A,#60H,VM1
MOV MINUTE,#0
VM1:MOV SECS,#0
POP ACC
RETI
;校时
VH:MOV A,HOUR
ADD A,#1
DA A
MOV HOUR,A
CJNE A,#24H,VH1
MOV HOUR,#0
VH1:MOV SECS,#0
POP ACC
RETI
;拆分
CF: MOV R1,#DM
MOV R2,#3
CF1: MOV A,@R0
ANL A,#0FH
MOV @R1,A
INC R1
MOV A,@R0
ANL A,#0F0H
SWAP A
MOV @R1,A
INC R1
INC R0
DJNZ R2,CF1
RET
;显示
DISP:PUSH R0
PUSH R1
PUSH R2
PUSH ACC
MOV R0,#DM
MOV R1,#0FEH
DISP1:MOV DPTR,#TAB
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
MOV P2,R1
MOV R6,#2
MOV R7,#120
DJNZ R7,$
DJNZ R6,$-4
INC R0
MOV A,R1
RL A
MOV R1,A
MOV P2,#0FFH
JB ACC.6,DISP1
POP ACC
POP R2
POP R1
POP R0
RET
TAB:DB 0C0H 0F9H 0A4H 0B0H
DB 99H 92H 82H 0F8H
DB 80H 90H 88H 83H
DB 0C6H 0A1H 86H 8EH
END
文章评论(0条评论)
登录后参与讨论