Code: Select all
sub procedure AT24_write(dim adress as word, dim dta as byte)
I2C1_Start()
I2C1_Wr(0xA0)
I2C1_Wr(hi(adress))
I2C1_Wr(lo(adress))
I2C1_Wr(dta)
I2C1_Stop()
end sub
sub function AT24_read (dim adress as word)as byte
I2C1_Start()
I2C1_Wr(0xA0)
I2C1_Wr(hi(adress))
I2C1_Wr(lo(adress))
'I2C1_Stop()
I2C1_Start()
I2C1_Wr(0xA1)
result=I2C1_Rd(0)
while (I2C1_Is_Idle() = 0)
nop ' Wait for the read cycle to finish
wend
'result=I2C1_Rd(0)
I2C1_Stop()
end sub
I have not already modified code to insert A17 and A16 MSB bits in adress byte, but this should work for adresses lower than 65k