K1 BIT P1.0
K2 BIT P1.1
ORG 0000H
AJMP START
ORG 000BH
AJMP DS0
ORG 0030H
START: CLR A
MOV R0,#7FH //初始化清零
CL: MOV @R0,A
DJNZ R1,CL
MOV TMOD,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
SETB EA //开定时中断0
SETB ET0
SETB TR0
MOV R2,#14H //计时次数
MOV 42H,#0AH // 显示--的DB位置
MOV 45H,#0AH // 显示--的DB位置
MAIN: LCALL KEY
LCALL ZH //转化
LCALL DIS //调显示
AJMP MAIN
KEY: JNB K1,KEY1 //分。时调时
JNB K2,KEY2
RET
KEY1: LCALL DEL
JB K1,KEYEND //分加一
INC 31H
MOV A,31H
CJNE A,#3CH,KEYEND
MOV 31H,#00H
KEYEND: RET
KEY2: LCALL DEL
JB K2,KEYEND //时加一
INC 32H
MOV A,32H
CJNE A,#18H,KEYEND
MOV 32H,#00H
RET
DIS: MOV R0,#40H //显示放置初地址
MOV 36H,#7FH //秒钟位码地址
MOV R4,#08H //显示次数
DIS1: MOV A,@R0
MOV DPTR,#DUAN
MOVC A,@A+DPTR
MOV P0,A
SETB P2.2
CLR P2.2
MOV A,36H
MOV P0,A
SETB P2.3
//LCALL DEL
CLR P2.3
LCALL DELL
INC R0
RR A
MOV 36H,A
DJNZ R4,DIS1
RET
ZH: MOV R0,#30H
MOV R3,#03H //时分秒转化,秒钟由30H转到40 41,分由31转到43 44,
MOV R1,#40H //时由32H转到46H 47H
ZH1: MOV A,@R0
MOV B,#10
DIV AB
XCH A,B
MOV @R1,A
INC R1
MOV @R1,B
INC R0
INC R1
INC R1
DJNZ R3 ,ZH1
RET
DS0: PUSH ACC
PUSH PSW
CLR ET0
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B3H
SETB TR0
DJNZ R2,TC
MOV R2,#14H
INC 30H
MOV A,30H
CJNE A,#3CH,TC
MOV 30H,#00H
INC 31H
MOV A,31H
CJNE A,#3CH,TC
MOV 31H,#00H
INC 32H
MOV A,32H
CJNE A,#18H,TC
MOV 32H,#00H
MOV 31H,#00H
MOV 30H,#00H
TC: POP PSW
POP ACC
SETB ET0
REti
DUAN: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H
DEL: MOV R7,#50
DEL1: MOV R6,#100
DJNZ R6,$
DJNZ R7,DEL1
RET
DELL: MOV R7,#10
DELL1: MOV R6,#100
DJNZ R6,$
DJNZ R7,DELL1
RET
END
|