DSC12887与单片机接口的汇编例程
来源:互联网 | 作者:中华IC网整理 | 发表于:2013-09-06
DSC12887与单片机接口的汇编例程
;--------------------------------------------------------------
; 写时间子程序 向DS12887回写时间信息,包括年月日,时分秒;
;--------------------------------------------------------------
WRITE_TIME:
MOV DS_ADDR,#0BH
MOV A,#0A2H
LCALL WRITE_DS
;写秒信息,在60H,61H中
MOV DS_ADDR,#0
MOV A,61H
ANL A,#0FH
SWAP A
ANL 60H,#0FH
ORL A,60H
LCALL WRITE_DS
;分信息,在62,63H中
MOV DS_ADDR,#2
ANL 62H,#0FH
ANL 63H,#0FH
MOV A,63H
SWAP A
ORL A,62H
LCALL WRITE_DS
;时信息,在64,65H中
MOV DS_ADDR,#4
ANL 64H,#0FH
ANL 65H,#0FH
MOV A,65H
SWAP A
ORL A,64H
LCALL WRITE_DS
;周信息,在66H中
MOV DS_ADDR,#6
MOV A,66H
LCALL WRITE_DS
;日信息,在67,68H中
MOV DS_ADDR,#7
ANL 67H,#0FH
ANL 68H,#0FH
MOV A,68H
SWAP A
ORL A,67H
LCALL WRITE_DS
;月信息,在69,6AH中
MOV DS_ADDR,#8
ANL 69H,#0FH
ANL 6AH,#0FH
MOV A,6AH
SWAP A
ORL A,69H
LCALL WRITE_DS
;年信息,在6B,6CH中
MOV DS_ADDR,#9
ANL 6BH,#0FH
ANL 6CH,#0FH
MOV A,6CH
SWAP A
ORL A,6BH
LCALL WRITE_DS
;世纪信息,在6D,6EH中
MOV DS_ADDR,#0EH
ANL 6DH,#0FH
ANL 6EH,#0FH
MOV A,6EH
SWAP A
ORL A,6DH
LCALL WRITE_DS
;-----------以下重新初始化时钟
MOV DS_ADDR,#0AH
MOV A,#2FH
LCALL WRITE_DS
MOV DS_ADDR,#0BH
MOV A,#42H
LCALL WRITE_DS
MOV DS_ADDR,#0CH
LCALL READ_DS
MOV DS_ADDR,#0DH
LCALL READ_DS
RET
;--------------------------------------------------------------
; 读时间信息例程,包括年月日,时分秒
; 分别放入60H-6DH的内存字节中,一个
; 字节中只存放一位数,低位在前
;--------------------------------------------------------------
READ_TIME:
MOV DS_ADDR,#0AH
LCALL READ_DS
JBC ACC.7,READ_TIME 更新标志
;秒信息送60H,61HNDEFINED SYMBOL (PASS-2)
MOV DPTR,#0 读秒信息
MOVX A,@DPTR
MOV 60H,A
SWAP A
MOV 61H,A
ANL 60H,#0FH
ANL 61H,#0FH
;分信息送62,63H
MOV DPTR,#2
MOVX A,@DPTR
MOV 62H,A
SWAP A
MOV 63H,A
ANL 62H,#0FH
ANL 63H,#0FH
SWAP A
CLR BZ_M00 清整点标志
CJNE A,#00,RT_H10
SETB BZ_M00 整点标志
;时信息送64,65H
RT_H10:
MOV DPTR,#4
MOVX A,@DPTR
MOV 64H,A
SWAP A
MOV 65H,A
;周信息送66H
H_14:
MOV DS_ADDR,#6
LCALL READ_DS
MOV 66H,A
ANL 66H,#0FH
;月日期送67,68H
MOV DS_ADDR,#7
LCALL READ_DS
MOV 67H,A
SWAP A
MOV 68H,A
;月计数送69,6AH
D_01:
MOV DS_ADDR,#8
LCALL READ_DS
MOV 69H,A
SWAP A
MOV 6AH,A
SWAP A
;年信息送6B,6C时
MOV DS_ADDR,#9
LCALL READ_DS
MOV 6BH,A
SWAP A
MOV 6CH,A
;世纪信息送6D,6E
CJNE A,#98H,RT_1
RT_1: JC RT_2
MOV A,#19H 判断世纪,大于98是19,小于
是20
AJMP RT_3
RT_2: MOV A,#20H
RT_3: MOV 6DH,A
SWAP A
MOV 6EH,A
;-------------------以下程序累加安全天数,64H=时
JNB BZ_M00,RT_10 不是整点
MOV A,64H
CJNE A,#00H,RT_END 0点累加安全天数
JB BZ_ADD,RT_END 已经加过了
SETB BZ_ADD
LCALL ADD_DAY 累加安全天数
RT_6:
AJMP RT_END
;-----------------以上程序累计产量
RT_10:
CLR BZ_ADD
; CLR BZ_ADM
; CLR BZ_ADN
RT_END:
; MOV DS_ADDR,#0CH
; LCALL READ_DS
RET
;--------------------------------------------------------------
;从DS12887中读写数据,地址在DS_ADDR中
;--------------------------------------------------------------
READ_DS:
; CLR P3.3
MOV DPH,#0H
MOV DPL,DS_ADDR
MOVX A,@DPTR
RET
WRITE_DS:
MOV DPH,#0H
MOV DPL,DS_ADDR
MOVX @DPTR,A
RET
您可以找一个DS12887的资料看一看其它的内存单元读写也可以使用以上两个例程.
DS12887资料参考:http://www.alldatasheet.com/view.jsp?Searchword=DS12887