$regfile = "m8def.dat" $crystal = 3686400 Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2 Config Lcd = 16 * 2 Config Portd = Output Cls Cursor Off Noblink Config Sda = Portc.4 Config Scl = Portc.5 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Byte , Byval Name1 As String * 3) Declare Sub Read_eeprom(byval Adres As Byte , Value As Byte , Name1 As String * 3) Const Addressw = 160 'slave write address Const Addressr = 161 'slave read address Dim B1 As Byte , Adres As Byte , Value As Byte , Name1 As String * 3 'dim byte Call Write_eeprom(1 , "Kai") 'write value of three to address 1 of EEPROM Call Write_eeprom(5 , 15) Call Write_eeprom(7 , 25) Call Write_eeprom(9 , 35) Locate 1 , 1 Call Read_eeprom(1 , Name1) : Lcd Name1 'read it back Locate 2 , 1 Call Read_eeprom(5 , Value) : Lcd Value 'again for address 5 Locate 2 , 5 Call Read_eeprom(7 , Value) : Lcd Value Locate 2 , 7 Call Read_eeprom(9 , Value) : Lcd Value 'sample of writing a byte to EEPROM AT2404 Sub Write_eeprom(byval Adres As Byte , Byval Value As Byte) I2cstart 'start condition I2cwbyte Addressw 'slave address I2cwbyte Adres 'asdress of EEPROM I2cwbyte Value 'value to write I2cstop 'stop condition Waitms 10 'wait for 10 milliseconds End Sub 'sample of reading a byte from EEPROM AT2404 Sub Read_eeprom(byval Adres As Byte , Value As Byte) I2cstart 'generate start I2cwbyte Addressw 'slave adsress I2cwbyte Adres 'address of EEPROM I2cstart 'repeated start I2cwbyte Addressr 'slave address (read) I2crbyte Value , Nack 'read byte I2cstop 'generate stop End Sub