bsp;a, FADDR
SETB acc.0
LCALL shout
JC x44
LCALL shin
LCALL NAK
CLR c
x44:LCALL stop
x45:ret
rd_rand:NOP
; AT24Cxx Random Read function.
;Called with programmable address in A, byte address in
; register pair ADDR_HI:ADDR_LO. Returns data in A.
; Returns CY set to indicate that the bus is not available
; or that the addressed device failed to acknowledge.
PUSH b
MOV b, a
LCALL start
JC x47
RL a
ORL a, FADDR
CLR acc.0
LCALL shout
JC x46
MOV a, address
LCALL shout
JC x46
MOV a, b
LCALL rd_curr
LJMP x47
x46: LCALL stop
x47: pop b
ret
start:NOP
; Send START, defined as high-to-low SDA with SCL high.
; Return with SCL, SDA low.
; Returns CY set if bus is not available.
setb SDA
setb SCL; Verify bus available.
jnb SDA, x40
jnb SCL, x40
nop
clr SDA
nop
nop
nop
nop
nop
clr SCL
clr c
Ljmp x41
x40: setb c
x41: ret;;
stop: NOP
; Send STOP, defined as low-to-high SDA with SCL high.
; SCL expected low on entry. Return with SCL, SDA high.
clr SDA
nop
nop
setb SCL
nop
nop
nop
nop
nop
setb SDA
ret
shout:NOP
; Shift out a byte to the AT24Cxx, most significant bit first.
; SCL, SDA expected low on entry. Return with SCL low.
; Called with data to send in A.
; Returns CY set to indicate failure by slave to acknowledge.
; Destroys A.
push b
mov b, #8
x42: NOP
rlc a
mov SDA, c
nop
setb SCL
nop
nop
nop
nop
clr SCL