;;*****************************************************************
WriteEEPROM:
push acc
push b
reWrite_EEPROM:
call start ;; Start Bit
mov a,#07h
anl a,r7
rl a
orl a,#EEP24CXXWrite
call shout
jc Write_EEPROMErr
mov a, r5
call shout
jc Write_EEPROMErr
mov a, r3
call shout
jc Write_EEPROMErr
call stop
clr c
pop b
pop acc
ret
Write_EEPROMErr:
call stop
jmp reWrite_EEPROM
;;*****************************************************************************
; I2C Read Address=r2;Return DATA=A
ReadEEPROM:
push acc
push b
reRead_EEPROM:
call start ;; Start Bit
mov a,#07h
anl a,r7
rl a
orl a,#EEP24CXXRead
mov r3,a
clr acc.0
call shout
jc read_EEPROMErr
mov a, r5 ;; Register Address
call shout
jc read_EEPROMErr
call read_current ;; Read in Data
mov r7,a ;; Return Value
pop b
pop acc
ret
read_EEPROMErr:
call stop
jmp reRead_EEPROM
;;--------------------------------------
read_current:
setb SDAPin
setb SCLPin
nop
nop
nop
call start
mov a, r3
call shout
jc x44
read_current1:
call shin
call ACK
clr c
x44: call stop
ret
;;--------------------------------------
start: setb SDAPin
setb SCLPin ; enforce SCL high
nop ;
nop ;
clr SDAPin
nop ;
nop ;
clr SCLPin
nop ;
nop ;
ret
;;--------------------------------------
stop: clr SDAPin
nop ;
nop ;
setb SCLPin
nop ;
nop ;
nop ;
setb SDAPin
nop ;
nop ;
nop ;
nop ;
ret
;;--------------------------------------
shout: push b
mov b, #8
shoutBit_loop: rlc a
mov SDAPin, c
nop ;
setb SCLPin
nop ;
nop ;
nop ;
clr SCLPin
nop ;
nop ;
djnz b, shoutBit_loop
setb SDAPin
nop ;
setb SCLPin
nop ;
nop ;
jnb SDAPin,shoutACK
setb c
jmp shoutNACK
shoutACK:
clr c
shoutNACK:
clr SCLPin
nop ;
nop ;
nop ;
clr SDAPin
nop ;
nop ;
nop ;
pop b
ret
;;--------------------------------------
shin: setb SDAPin
push b
mov b, #8
shinloop:
setb SCLPin
nop ;
nop ;
mov c, SDAPin
rlc a
clr SCLPin
nop ;
nop ;
djnz b, shinloop
pop b
ret
;;--------------------------------------
ACK: setb SDAPin
nop ;
nop ;
setb SCLPin
nop ;
nop ;
clr SCLPin
ret