Maxim Integrated Secure Microcontroller User Manual
Page 170

Secure Microcontroller User’s Guide
170 of 187
;***********************************
;
; This subroutine performs a “context switch: to the CE2 data ; space and
then reads one byte from the timekeeping device. ; Then it switches back to
the CE1 data space and returns ; the byte read in the accumulator, with all
other registers ; unchanged.
;
RBYTE: PUSH
DPL
;Save the data
PUSH
DPH
; pointer on stack.
PUSH
MCON
;Save MCON register.
ORL
MCON,#4
;Switch to CE2.
PUSH
B
;Save the B register.
MOV
DPL,#4
;Set up for data input.
MOV
DPH,#0
;Set high address byte.
MOV
B,#8
;Set the bit count.
LI:
PUSH
ACC
;Save the accumulator.
MOVX
A,@DPTR
;Input the data bit from the RTC into
; ACC.7.
RLC
A
;Move it to carry.
POP
ACC
;Get the accumulator.
RRC
A
;Save the data bit.
DJNZ
B,LI
;Loop for a whole byte.
POP
B
;Restore the B register.
POP
MCON
;Restore the MCON register.
POP
DPH
;Restore the data
POP
DPL
; pointer from stack.
RET
;Return.
;
;************************************
;*** SUBROUTINE TO WRITE A DATA BYTE
;************************************
;
; This subroutine performs a “context switch” to the CE2 data
; space and then writes one byte from the accumulator to the
; timekeeping device. Then it switches back to the CE1 data
; space and returns with all registers unchanged.
;
WBYTE: PUSH
DPL
;Save the data
PUSH
DPH
; pointer on stack.
PUSH
MCON
;Save the MCON register.
ORL
MCON,#4
;Switch to CE2.
PUSH
B
;Save the B register.
MOV
DPH,#0
;Set high address byte.
MOV
B, #8 ;Set the bit Count.
LO:
PUSH
ACC
;Save the accumulator.
ANL
A, #1
;Set up bit for output.
MOV
DPL,A
;Set address to write bit.
MOVX
A, @DPTR
;Output the data bit.
POP
ACC
;Restore the accumulator.
RR
A
;Position next bit.
DJNZ
B, LO
;Loop for a whole byte.
POP
B
;Restore the B register.
POP
MCON
;Restore the MCON register.
POP
DPH
;Restore the data
POP
DPL
; pointer from stack.
RET
;Return.
;
END
;End of program.