English
Language : 

AN1759 Datasheet, PDF (23/24 Pages) Freescale Semiconductor, Inc – Add a Non-Volatile Clock to the MC68HC705J1A
Freescale Semiconductor, Inc.
Application Note
Code Listing
CLOCK_IT
bset
bclr
decx
bne
* Check for ACK
bclr
bset
brclr
ACK_ERROR
bra
J2
bclr
bset
rts
SCL,SER_PORT
SCL,SER_PORT
WRITE
SDA,DDRA
SCL,SER_PORT
SDA,SER_PORT,J2
ACK_ERROR
SCL,SER_PORT
SDA,DDRA
;SCL=1
;SCL=0
;decrement counter
;SDA is input
;SCL=1
;if SDA=0, slave ACK
;no slave ACK, error loop
;SCL=0
;SDA is output
;return from sub
*** Routine clocks the DS1307 to read data from SDA, MSB first
*** 8 bit contents are put in AccA
*** Generates ACK back to slave
RXD
bclr SDA,DDRA
;make the SDA pin on J1A input
ldx
#8T
;set counter
READ
J3
bset
brclr
rola
bclr
SCL,SER_PORT
SDA,SER_PORT,J3
SCL,SER_PORT
;SCL=1
;carry bit = SDA
;put carry bit into AccA MSB
;SCL=0
decx
bne
* ACK back to slave
bset
bclr
bset
bclr
rts
READ
SDA,DDRA
SDA,SER_PORT
SCL,SER_PORT
SCL,SER_PORT
;decrement counter
;make the SDA pin on J1A output
;SDA=0
;SCL=1
;SCL=0
;return from sub
*** Routine clocks the DS1307 to read data from SDA, MSB first
*** 8 bit contents are put in AccA
*** Generates NO ACK back to slave, signals last read to DS1307
RXD_LAST
bclr SDA,DDRA
;make the SDA pin on J1A input
ldx
#8T
;set counter
READ_LAST
J4
bset
brclr
rola
bclr
SCL,SER_PORT
SDA,SER_PORT,J4
SCL,SER_PORT
;SCL=1
;carry bit = SDA
;put carry bit into AccA MSB
;SCL=0
decx
bne
READ_LAST
* NO ACK back to slave
bset SDA,DDRA
bset SDA,SER_PORT
bset SCL,SER_PORT
bclr SCL,SER_PORT
rts
;decrement counter
;make the SDA pin on J1A output
;SDA=1
;SCL=1
;SCL=0
;return from sub
*** VECTOR TABLE *******************************************************************
ORG
RESET
DW
START
AN1759
23
For More Information On This Product,
Go to: www.freescale.com