📄 clock.asm
字号:
ORG 0000H ;this is a program of data&clock
AJMP START0 ;2002/02/21
ORG 0003H
LJMP rddatewait
START0: MOV SP,#81H
MOV A,#43H
MOV DPTR,#0FF20H
MOVX @DPTR,A
CLR EA
SETB IT0
ACALL BUF
MOV R0,#59H
MOV A,#7EH
MOV @R0,A
START: LCALL X2
JNC FUN
LCALL X3
DB 79H,7EH
SJMP START
FUN: CJNE A,#16H,FUN1
AJMP RDCLOCKWAIT ;RD-TIME
FUN1: CJNE A,#17H,FUN2
LCALL DATE ;SET-DATE
CALL BUF
AJMP START
FUN2: CJNE A,#1EH,START
LCALL TIME ;SET TIME
CALL BUF
AJMP START
;----- ----------------------------------------------------------------------
rdclockwait: acall rddate1
setb ea
setb ex0
rdclockcon: mov dptr,#800ah
movx a,@dptr
jb 0e7h,rdclockcon
acall rdtime ;读时间
mov r0,#52h
acall savebuff ;save数据to dis-ram
acall dis ;显示
ajmp rdclockcon
;----------------------------------------------------------------------
DATE: mov r0,#7eh ;7eh,7dh=year 20 x.x,7ch,7bh=yu x.x,7ah,79h=day x.x
mov r1,#55h ;55h=year,54h=yu,53h=day
acall picktime ;7eh...79h,save to 55h,54h,53h
acall setdate ;55h,54h,53h write to ds12887 day unit
RET
time: mov r0,#7eh ;7eh,7dh=hour x.x,7ch,7bh=minutes ;x.x,7ah,79h=second x.x
mov r1,#52h ;52h=hour 51h=minutes 50h=second
acall picktime ;;7eh...79h,save to 52h,51h,50h
acall settime ;设置ds12887时间
RET
;----------------------------------------------------------------------
rddatewait: push dpl
push dph
push acc
push 00h
push 01h
push 02h
push 79h
push 7ah
push 7bh
push 7ch
push 7dh
push 7eh
mov dptr,#800ch
movx a,@dptr ;clr int
rddatecon: mov dptr,#800ah
movx a,@dptr
jb 0e7h,rddatecon
acall rddate ;读date
mov r0,#55h
acall savebuff ;数据转换
lcall disq ;显示
pop 7eh
pop 7dh
pop 7ch
pop 7bh
pop 7ah
pop 79h
pop 02h
pop 01h
pop 00h
pop acc
pop dph
pop dpl
reti
rddate1: mov dptr,#800ah
movx a,@dptr
jb 0e7h,rddate1
acall rddate ;读date
mov r0,#55h
acall savebuff ;save数据to dis-ram
lcall disq ;显示
ret
; -----------------------------------------------------------------------------------
wrint: clr a
mov dptr,#8001h
movx @dptr,a
mov dptr,#8003h
movx @dptr,a
mov dptr,#8005h
movx @dptr,a
ret
setdate: mov r0,#53h
mov dptr,#800ah
movx a,@dptr
mov a,#27h
movx @dptr,a
inc dptr
mov a,#80h
movx @dptr,a
acall wrint
mov dptr,#8007h ;day
mov a,@r0
movx @dptr,a
inc dptr
inc r0
mov a,@r0
movx @dptr,a ;yu
inc dptr
inc r0
mov a,@r0
movx @dptr,a
mov dptr,#800bh
mov a,#2ah ;22h
movx @dptr,a
ret
settime: mov r0,#50h
mov dptr,#800ah
movx a,@dptr
mov a,#27h
movx @dptr,a
inc dptr
mov a,#80h
movx @dptr,a
acall wrint
mov dptr,#8000h
mov a,@r0
movx @dptr,a
inc r0
inc dptr
inc dptr
mov a,@r0
movx @dptr,a
inc r0
inc dptr
inc dptr
mov a,@r0
movx @dptr,a
mov dptr,#800bh
mov a,#2ah ;22h
movx @dptr,a
ret
rddate: mov dptr,#8007h
movx a,@dptr
mov 53h,a ;rd day
inc dptr
movx a,@dptr ;rd yu
mov 54h,a
inc dptr
movx a,@dptr ;rd year
mov 55h,a
ret
rdtime: mov dptr,#8000h
movx a,@dptr
mov 50h,a ;rd second
inc dptr
inc dptr
movx a,@dptr ;rd minutes
mov 51h,a
inc dptr
inc dptr
movx a,@dptr ;rd hour
mov 52h,a
ret
savebuff: ;mov r0,#52h
mov r1,#7eh
mov r2,#03h
savebuff1 : mov a,@r0
swap a
anl a,#0fh
mov @r1,a
dec r1
mov a,@r0
anl a,#0fh
mov @r1,a
dec r1
dec r0
djnz r2,savebuff1
ret
picktime: mov r2,#03h
picktime1: mov a,@r0 ;r0:7EH,r1:55h/52h
swap a
dec r0
orl a,@r0
mov @r1,a
dec r0
dec r1
djnz r2,picktime1
ret
BUF: MOV 7EH,#05H
MOV 7DH,#0EH
MOV 7CH,#14H
MOV 7BH,#14H
MOV 7AH,#10H
MOV 79H,#10H
RET
X3: MOV R4,A
MOV R0,#59H
MOV A,@R0
MOV R1,A
MOV A,R4
MOV @R1,A
CLR A
POP DPH
POP DPL
MOVC A,@A+DPTR
INC DPTR
CJNE A,01H,X30
CLR A
MOVC A,@A+DPTR
X31: MOV @R0,A
INC DPTR
PUSH DPL
PUSH DPH
RET
X30: DEC R1
MOV A,R1
SJMP X31
X2: MOV R6,#50H
X0: ACALL XLE
JNB ACC.5,XX0
DJNZ R6,X0
MOV R6,#20H
MOV R0,#59H
MOV A,@R0
MOV R0,A
MOV A,@R0
MOV R7,A
MOV A,#10H
MOV @R0,A
X1: ACALL XLE
JNB ACC.5,XX1
DJNZ R6,X1
MOV A,R7
MOV @R0,A
SJMP X2
XX1: MOV R6,A
MOV A,R7
MOV @R0,A
MOV A,R6
XX0: RET
XLE: ACALL DIS
ACALL KEY
MOV R4,A
MOV R1,#48H
MOV A,@R1
MOV R2,A
INC R1
MOV A,@R1
MOV R3,A
MOV A,R4
XRL A,R3
MOV R3,04H
MOV R4,02H
JZ X10
MOV R2,#88H
MOV R4,#88H
X10: DEC R4
MOV A,R4
XRL A,#82H
JZ X11
MOV A,R4
XRL A,#0EH
JZ X11
MOV A,R4
ORL A,R4
JZ X12
MOV R4,#20H
DEC R2
SJMP X13
X12: MOV R4,#0FH
x11: MOV R2,04H
MOV R4,03H
X13: MOV R1,#48H
MOV A,R2
MOV @R1,A
INC R1
MOV A,R3
MOV @R1,A
MOV A,R4
RET
LS3: DB 07H,04H,08H,05H,09H,06H,0AH
DB 0BH,01H,00H,02H,0FH,03H,0EH
DB 0CH,0DH
DIS: PUSH DPH
PUSH DPL
SETB RS1
MOV R1,#21H
MOV A,#00H
MOVX @R1,A
MOV R0,#7EH
MOV R2,#20H
MOV R3,#00H
MOV DPTR,#LS0
LS2: MOV A,@R0
MOVC A,@A+DPTR
MOV R1,#22H
MOVX @R1,A
MOV A,R2
DEC R1
CPL A
MOVX @R1,A
CPL A
DEC R0
LS1: DJNZ R3,LS1
CLR C
RRC A
MOV R2,A
JNZ LS2
INC R1
MOV A,#0FFH
MOVX @R1,A
CLR RS1
POP DPL
POP DPH
RET
LS0: DB 0C0H,0F9H,0A4H,0B0H,99H,92H
DB 82H,0F8H,80H,90H,88H,83H,0C6H
DB 0A1H,86H,8EH,0FFH,0CH,89H,7FH,0BFH
KEY: SETB RS1
MOV R2,#0FEH
MOV R3,#08H
MOV R0,#00H
LP1: MOV A,R2
MOV R1,#21H
MOVX @R1,A
RL A
MOV R2,A
MOV R1,#23H
MOVX A,@R1
CPL A
ANL A,#0FH
JNZ LP0
INC R0
DJNZ R3,LP1
MOVX A,@R1
JB ACC.4,XP33
MOV A,#19H
SJMP XP3
XP33: MOV A,#20H
XP3: CLR RS1
RET
LP0: CPL A
JB ACC.0,XP0
MOV A,#00H
SJMP LPP
XP0: JB ACC.1,XP1
MOV A,#08H
SJMP LPP
XP1 : JB ACC.2,XP2
MOV A,#10H
SJMP LPP
XP2: JB ACC.3,XP33
MOV A,#18H
LPP: ADD A,R0
CLR RS1
CJNE A,#10H,LX0
LX0: JNC XP35
MOV DPTR,#LS3
MOVC A,@A+DPTR
XP35: RET
DISQ: mov a,#02h
mov r0,#80h
mov @r0,a
mov 7fh,#00h
MOV R1,#08H
MOV R0,#79H
MOV DPTR,#TAB
LOOP: MOV A,@R0
MOVC A,@A+DPTR
MOV SBUF,A
JNB TI,$
CLR TI
INC R0
DJNZ R1,LOOP
RET
TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH
DB 6FH,7CH,39H,5EH,79H,71H,40H,73H
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -