ORG 0000H
LJMP MAIN_1
ORG 000BH
LJMP INTT0
;;;;;;;;;;;;;;;;;;;;;
;; 主程序 ;;
;;;;;;;;;;;;;;;;;;;;;
ORG 0100H
MAIN_1: MOV SP,#67H ;设置堆栈
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
MOV IE,#82H
SETB TR0
MOV R7,#30H ;清48个单元
MOV R0,#20H
M_0: CLR A
MOV @R0,A
INC R0
DJNZ R7,M_0
ACALL CHUSHI
MOV 22H,#40H
MOV 50H,#09H
MOV 51H,#06H
MOV 52H,#12H
MAIN_2: ACALL DIR_0
ACALL DIR
ACALL KEY
CJNE A,#0FFH,M_1
SJMP MAIN_2
M_1: CJNE A,#0AH,M_2
M_2: JNC M_3
ACALL SKEY
SJMP MAIN_2
M_3: CJNE A,#0AH,M_4
ACALL MKEY_1
SJMP MAIN_2
M_4: CJNE A,#0BH,M_5
ACALL MKEY_2
SJMP MAIN_2
M_5: CJNE A,#0CH,M_6
ACALL MKEY_3
SJMP MAIN_2
M_6: CJNE A,#0DH,M_7
ACALL MKEY_4
M_7: SJMP MAIN_2
;;;;;;;;;;;;;;;;;;;;;;;
;; 7279初始化程序 ;;
;;;;;;;;;;;;;;;;;;;;;;;
CHUSHI: CLR P1.0
MOV R6,#0CH
AL0: DJNZ R6,AL0
MOV A,#0A4H
ACALL STFS
MOV R6,#02H
AL1: DJNZ R6,AL1
SETB P1.0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;
;; 7279发送一字节子程序 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
STFS: MOV R7,#08H
BL1: RLC A
MOV P1.2,C
SETB P1.1
MOV R6,#02H
BL2: DJNZ R6,BL2
CLR P1.1
MOV R6,#02H
BL3: DJNZ R6,BL3
DJNZ R7,BL1
RET
;;;;;;;;;;;;;;;;;;;;;;;;;
;; 7279显示程序 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
DIR: ;MOV 42H,#12H
MOV 45H,#12H
MOV 42H,#12H
MOV R5,#08H
MOV R0,#40H
MOV R1,#97H
CL1: CLR P1.0
MOV R6,#0CH
CL2: DJNZ R6,CL2
MOV A,R1
ACALL STFS
MOV R6,#04H
CL3: DJNZ R6,CL3
CL5: MOV A,@R0
ADD A,#0DH
MOVC A,@A+PC
ACALL STFS
MOV R6,#02H
CL4: DJNZ R6,CL4
SETB P1.0
INC R0
DEC R1
DJNZ R5,CL1
RET
TAB: DB 7EH,30H,6DH,79H,33H,5BH,5FH,70H,7FH,7BH
DB 77H,1FH,4EH,3DH,4FH,47H,00H,67H,01H
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 7279显示处理程序 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DIR_0: JB 01H,DIR_OUT ;时分秒设置的标志
JB 03H,DIR_OUT ;年月日设置的标志
JNB 02H,DIR_OUT
CLR 02H
JNB 04H,D_1 ;年月日切换标志
MOV A,35H
CJNE A,#05H,D_2
D_2: JC D_3
CLR 04H
MOV 35H,#00H
SJMP DIR_OUT
D_1: MOV R0,#40H
MOV A,30H
ACALL A_R0
MOV R0,#43H
MOV A,31H
ACALL A_R0
MOV R0,#46H
MOV A,32H
ACALL A_R0
SJMP DIR_OUT
D_3: MOV R0,#40H
MOV A,50H
ACALL A_R0
MOV R0,#43H
MOV A,51H
ACALL A_R0
MOV R0,#46H
MOV A,52H
ACALL A_R0
DIR_OUT:RET
A_R0: MOV R2,A
SWAP A
ANL A,#0FH
MOV @R0,A
INC R0
MOV A,R2
ANL A,#0FH
MOV @R0,A
INC R0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;
;; 中断服务程序 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
INTT0: PUSH ACC
PUSH PSW
CLR TR0
MOV TH0,#3CH ;重覆定时器初值
MOV TL0,#0B0H
SETB TR0
INC 34H
MOV A,34H
CJNE A,#05H,L0 ;半秒加一程序
L0: JC L1
MOV 34H,#00H
SETB 02H
L1: INC 33H
MOV A,33H
CJNE A,#0AH,L2 ;一秒加一程序
L2: JC L10
MOV 33H,#00H
JNB 04H,T_1 ;35H为5S的年月日切换显示时间寄存器,04H是切换标志
MOV A,35H
ADD A,#01H
MOV 35H,A
T_1: MOV A,32H
ADD A,#01H
DA A
MOV 32H,A
CJNE A,#60H,L3
L3: JC L10
MOV 32H,#00H
MOV A,31H
ADD A,#01H
DA A
MOV 31H,A
CJNE A,#60H,L4
L4: JC L10
MOV 31H,#00H
MOV A,30H
ADD A,#01H
DA A
MOV 30H,A
CJNE A,#24H,L5
L5: JC L10
MOV 30H,#00H
MOV A,52H
ADD A,#01H
DA A
MOV 52H,A
CJNE A,#30H,L6
L6: JC L10
MOV 52H,#00H
MOV A,51H
ADD A,#01H
DA A
MOV 51H,A
CJNE A,#12H,L7
L7: JC L10
MOV 51H,#00H
MOV A,50H
ADD A,#01H
DA A
MOV 50H,A
CJNE A,#99H,L8
L8: JC L10
MOV 50H,#00H
L10: POP PSW
POP ACC
RETI
KEY: ACALL KEY1
CJNE A,#0FFH,DL1
CLR 00H
RET
DL1: JB 00H,DL2
SETB 00H
ACALL KEY2
RET
DL2: MOV A,#0FFH
RET
KEY1: CLR P1.0 ;读键值
MOV R6,#0CH
EL1: DJNZ R6,EL1
MOV A,#15H
ACALL STFS
MOV R6,#06H
EL2: DJNZ R6,EL2
ACALL STJS
SETB P1.0
RET
KEY2: MOV B,A ;查键号
MOV R2,#0FH
MOV R7,#0FH
FL1: MOV A,R2
ADD A,#(TAB1-MM)
MOVC A,@A+PC
MM: CJNE A,B,FL2
SJMP FL3
FL2: DEC R2
DJNZ R7,FL1
FL3: MOV A,R2
RET
TAB1: DB 07H,0FH,0EH,0DH,17H,16H,15H,1FH
DB 1EH,1DH,06H,05H,04H,0CH,14H,1CH
STJS: MOV R7,#08H ;接受一个字
HL1: SETB P1.1
SETB P1.2
MOV R6,#02H
HL2: DJNZ R6,HL2
MOV C,P1.2
RLC A
CLR P1.1
MOV R6,#02H
HL3: DJNZ R6,HL3
DJNZ R7,HL1
RET
SKEY: JNB 01H,S_2 ;数字键处理,将输入的设置数字直接显示
MOV R0,22H
MOV @R0,A
INC 22H
MOV A,22H
CJNE A,#48H,S_1
S_1: JC S_OUT
MOV 22H,#40H
RET
S_2: JNB 03H,S_OUT
MOV R0,22H
MOV @R0,A
INC 22H
MOV A,22H
CJNE A,#48H,S_3
S_3: JC S_OUT
MOV 22H,#40H
S_OUT: RET
MKEY_1: ;设置校时的标志
SETB 01H
MOV 22H,#40H
CLR P1.0
MOV R6,#0CH
MK1_2: DJNZ R6,MK1_2
MOV A,#88H
ACALL STFS
MOV R6,#04H
MK1_3: DJNZ R6,MK1_3
MOV A,#00H
ACALL STFS
MOV R6,#02H
MK1_4: DJNZ R6,MK1_4
SETB P1.0
RET
MKEY_3: ;设置03H,年月日校时的标志
SETB 03H
MOV 22H,#40H
CLR P1.0
MOV R6,#0CH
MK3_2: DJNZ R6,MK3_2
MOV A,#88H
ACALL STFS
MOV R6,#04H
MK3_3: DJNZ R6,MK3_3
MOV A,#00H
ACALL STFS
MOV R6,#02H
MK3_4: DJNZ R6,MK3_4
SETB P1.0
RET
MKEY_4: ;设置年月日切换的标志
SETB 04H
RET
MKEY_2: JNB 01H,MM_1 ;保存设置后的值
MOV R0,#40H
ACALL R0_A
MOV 30H,A
MOV R0,#43H
ACALL R0_A
MOV 31H,A
MOV R0,#46H
ACALL R0_A
MOV 32H,A
CLR 01H
CLR P1.0
MOV R6,#0CH
MK41_2: DJNZ R6,MK41_2
MOV A,#88H
ACALL STFS
MOV R6,#04H
MK41_3: DJNZ R6,MK41_3
MOV A,#0FFH
ACALL STFS
MOV R6,#02H
MK41_4: DJNZ R6,MK41_4
SETB P1.0
RET
MM_1: JNB 03H,MM_OUT
MOV R0,#40H
ACALL R0_A
MOV 50H,A
MOV R0,#43H
ACALL R0_A
MOV 51H,A
MOV R0,#46H
ACALL R0_A
MOV 52H,A
CLR 03H
CLR P1.0
MOV R6,#0CH
MK42_2: DJNZ R6,MK42_2
MOV A,#88H
ACALL STFS
MOV R6,#04H
MK42_3: DJNZ R6,MK42_3
MOV A,#0FFH
ACALL STFS
MOV R6,#02H
MK42_4: DJNZ R6,MK42_4
SETB P1.0
MM_OUT: RET
R0_A: MOV A,@R0
SWAP A
MOV R2,A
INC R0
MOV A,@R0
ANL A,#0FH
ORL A,R2
RET
END