
Application Note
Code Listing
AN1759
23
CLOCK_IT
bset
bclr
decx
bne
SCL,SER_PORT
SCL,SER_PORT
;SCL=1
;SCL=0
;decrement counter
WRITE
* Check for ACK
bclr
bset
brclr
SDA,DDRA
SCL,SER_PORT
SDA,SER_PORT,J2
;SDA is input
;SCL=1
;if SDA=0, slave ACK
ACK_ERROR
bra
ACK_ERROR
;no slave ACK, error loop
J2
bclr
bset
rts
SCL,SER_PORT
SDA,DDRA
;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
ldx
#8T
;make the SDA pin on J1A input
;set counter
READ
bset
brclr
rola
bclr
SCL,SER_PORT
SDA,SER_PORT,J3
;SCL=1
;carry bit = SDA
;put carry bit into AccA MSB
;SCL=0
J3
SCL,SER_PORT
decx
bne
;decrement counter
READ
* ACK back to slave
bset
bclr
bset
bclr
rts
SDA,DDRA
SDA,SER_PORT
SCL,SER_PORT
SCL,SER_PORT
;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
ldx
#8T
;make the SDA pin on J1A input
;set counter
READ_LAST
bset
brclr
rola
bclr
SCL,SER_PORT
SDA,SER_PORT,J4
;SCL=1
;carry bit = SDA
;put carry bit into AccA MSB
;SCL=0
J4
SCL,SER_PORT
decx
bne
;decrement counter
READ_LAST
* NO ACK back to slave
bset
bset
bset
bclr
rts
SDA,DDRA
SDA,SER_PORT
SCL,SER_PORT
SCL,SER_PORT
;make the SDA pin on J1A output
;SDA=1
;SCL=1
;SCL=0
;return from sub
*** VECTOR TABLE *******************************************************************
ORG
RESET
DW
START
F
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
.