DIN EQU P1.0
LOAD EQU P1.1
CLK EQU P1.2
SECOND EQU 4000H
MINUTE EQU 4002H
HOUR EQU 4004H
WEEK EQU 4006H
DATE EQU 4007H
MONTH EQU 4008H
YEAR EQU 4009H
REG_A EQU 400AH
REG_B EQU 400BH
REG_C EQU 400CH
REG_D EQU 400DH
W0000: LJMP W0050
W0003: NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
W000B: NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
W0013: NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
W001B:
;; ;;; 定时中断 1
RETI
ORG 0023H
W0023: NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
W002B: NOP
RETI
ORG 0050H
W0050: MOV SP,#50H
MOV P3,#00H
START1:
MOV 26H,#0BH ;; 扫描寄存器 (显示位数)
MOV 27H,#07H ;; 取值由 00-- 07 , 分别表示显示 1 --- 8 个数码管
LCALL DISPLAY
MOV 26H,#0AH ;;; 亮度寄存器
MOV 27H,#04H ;; 00 --- 0F 是由 最暗 --> 最亮
LCALL DISPLAY
MOV 26H,#09H ;; 译码模式寄存器
MOV 27H,#0FFH ;; 按表 B 方式解码
LCALL DISPLAY
MOV 26H,#0CH ;; 关灭寄存器
MOV 27H,#01H ;; 取值为 0, 或 1. 为1,正常操作; 为0,关灭
LCALL DISPLAY
MOV 26H,#01H
MOV 27H,#01H
LCALL DISPLAY
MOV 26H,#02H
MOV 27H,#02H
LCALL DISPLAY
MOV 26H,#03H
MOV 27H,#02H
LCALL DISPLAY
MOV 26H,#04H
MOV 27H,#05H
LCALL DISPLAY
MOV 26H,#05H
MOV 27H,#06H
LCALL DISPLAY
MOV 26H,#06H
MOV 27H,#07H
LCALL DISPLAY
MOV 26H,#07H
MOV 27H,#08H
LCALL DISPLAY
nop
lcall off_all
SJMP INIT_DS12887
off_all:
mov r0,#08h
mov 26H,#01h
LEE:
mov 27H,#0fh
lcall DISPLAY
INC 26H
DJNZ R0,LEE
RET
DISPLAY:
push 00h
MOV R0,#08H
MOV A,26H
L000:
CLR CLK
RLC A
MOV DIN,C
NOP
SETB CLK
DJNZ R0,L000
NOP
;;=====
MOV R0,#08H
MOV A,27H
L001:
CLR CLK
RLC A
MOV DIN,C
SETB CLK
DJNZ R0,L001
NOP
CLR LOAD
NOP
NOP
SETB LOAD
pop 00h
RET
;; 设定时间
INIT_DS12887:
;------------------------------------------------------------------
MOV DPTR,#400AH ;;REG_A
MOV A,#00100000B
MOVX @DPTR,A ;; 20H
MOV DPTR,#400BH ;;REG_B
MOV A,#10000000B ;; 80H
MOVX @DPTR,A
MOV DPTR,#SECOND
MOV A,#55H
MOVX @DPTR,A
MOV DPTR,#MINUTE
MOV A,#9H
MOVX @DPTR,A
MOV DPTR,#HOUR
MOV A,#10H
MOVX @DPTR,A
MOV DPTR,#WEEK
MOV A,#07H
MOVX @DPTR,A
MOV DPTR,#DATE
MOV A,#02H
MOVX @DPTR,A
MOV DPTR,#MONTH
MOV A,#09H
MOVX @DPTR,A
MOV DPTR,#YEAR
MOV A,#95H
MOVX @DPTR,A
MOV DPTR,#400BH ;; REG_B
MOV A,#00010010B ;;; 24 小时制
MOVX @DPTR,A
;------------------------------------------------------------------
READTIME:
MOV DPTR,#400AH ;;; REG_A
RTCBUSY:
MOVX A,@DPTR
JB ACC.7,RTCBUSY ;; 等待数据更新
MOV DPTR,#4000H ;;SECOND ;; 读时间
MOVX A,@DPTR
MOV 26H,A
MOV 27H,#07H
LCALL DISPLAY
MOV 31H,A
MOV DPTR,#MINUTE
MOVX A,@DPTR
MOV 30H,A
MOV DPTR,#HOUR
MOVX A,@DPTR
MOV 32H,A
MOV A,32H
SWAP A
ANL A,#0FH
MOV 26H,A
MOV 27H,#01H
LCALL DISPLAY
MOV A,32H
ANL A,#0FH
MOV 26H,A
MOV 27H,#02H
LCALL DISPLAY
MOV 26H,#0AH
MOV 27H,#03H
LCALL DISPLAY
MOV A,31H
SWAP A
ANL A,#0FH
MOV 26H,A
MOV 27H,#04H
LCALL DISPLAY
MOV A,31H
ANL A,#0FH
MOV 26H,A
MOV 27H,#05H
LCALL DISPLAY
LJMP READTIME
;==================================================================
END
(备注:部份文章为网上收录供大家共同学习参考之用,如存在版权问题请马上通知我们,我们将马上删除。)