hallo, 2x in bascom, I2C beschreiben und lesen.
je nachdem wie du die adresse am eeprom 24c512 geschaltet hast, kontaktiert hast.
bei mir war es die adresse 160 und 161.
geh das programm in ruhe durch, habe ich auch im forum gefunden.
mfg pebisoft.

i2c-eeprom lesen, ausgabe auf dem lcd :

Code:
$regfile = "m16def.dat"
$crystal = 8000000

Enable Interrupts
Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , Rs = Portc.5 , E = Portc.4
Config Lcd = 16 * 2

Config Portd = Output
Config Sda = Portd.6
Config Scl = Portd.7

Cls
Lcd "EE - Test"
Waitms 500

Declare Sub Write_eeprom(byval Adres As Word , Byval Value As Byte)
Declare Sub Read_eeprom(byval Adres As Word , Value As Byte)

Const Addressw = 160                                        'slave write address
Const Addressr = 161                                        'slave read address
Dim I As Word
Dim B1 As Byte , Adres As Word , Value As Byte
Dim Temp As Byte

For I = 15600 To 15700
Call Read_eeprom(i , Value)
Cls
Locate 1 , 1
Lcd I ; "= " ; Value ; " ";
Waitms 500
Next I
End

Sub Write_eeprom(byval Adres Word , Byval Value As Byte)
    Temp = High(adres)
    I2cstart                                                'start condition
    I2cwbyte Addressw                                       'slave address
    I2cwbyte Temp                                           'asdress of EEPROM
    I2cwbyte Adres
    I2cwbyte Value                                          'value to write
    I2cstop                                                 'stop condition
    Waitms 10                                               'wait for 10 milliseconds
End Sub

Sub Read_eeprom(byval Adres Word , Value As Byte)
   Temp = High(adres)
   I2cstart                                                 'generate start
   I2cwbyte Addressw                                        'slave adsress
   I2cwbyte Temp
   I2cwbyte Adres                                           'address of EEPROM

   I2cstart                                                 'repeated start
   I2cwbyte Addressr                                        'slave address (read)
   I2crbyte Value , Nack                                    'read byte
   I2cstop                                                  'generate stop
End Sub


' when you want to control a chip with a larger memory like the 24c64 it requires an additional byte
' to be sent (consult the datasheet):
' Wires from the I2C address that are not connected will default to 0 in most cases!

'   I2cstart                                                'start condition
'   I2cwbyte &B1010_0000                                    'slave address
'   I2cwbyte H                                              'high address
'   I2cwbyte L                                              'low address
'   I2cwbyte Value                                          'value to write
'   I2cstop                                                 'stop condition
'   Waitms 10

'End


i2c-eeprom schreiben :

$regfile = "m16def.dat"
$crystal = 8000000

Enable Interrupts
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , Rs = Portc.5 , E = Portc.4
Config Lcd = 16 * 2

Config Portd = Output
Config Sda = Portd.6
Config Scl = Portd.7

Cls
Lcd "EE - Test"
Waitms 500

Declare Sub Write_eeprom(byval Adres As Word , Byval Value As Byte)
Declare Sub Read_eeprom(byval Adres As Word , Value As Byte)

Const Addressw = 160                                        'slave write address
Const Addressr = 161                                        'slave read address
Dim I As Word
Dim B1 As Byte , Adres As Word , Value As Byte
Dim Temp As Byte

For I = 15600 To 15700
Value = I - 15600
Call Write_eeprom(i , Value)
Next I

End

Sub Write_eeprom(byval Adres Word , Byval Value As Byte)
    Temp = High(adres)
    I2cstart                                                'start condition
    I2cwbyte Addressw                                       'slave address
    I2cwbyte Temp                                           'asdress of EEPROM
    I2cwbyte Adres
    I2cwbyte Value                                          'value to write
    I2cstop                                                 'stop condition
    Waitms 10                                               'wait for 10 milliseconds
End Sub

Sub Read_eeprom(byval Adres Word , Value As Byte)
   Temp = High(adres)
   I2cstart                                                 'generate start
   I2cwbyte Addressw                                        'slave adsress
   I2cwbyte Temp
   I2cwbyte Adres                                           'address of EEPROM

   I2cstart                                                 'repeated start
   I2cwbyte Addressr                                        'slave address (read)
   I2crbyte Value , Nack                                    'read byte
   I2cstop                                                  'generate stop
End Sub


'   I2cstart                                                'start condition
'   I2cwbyte &B1010_0000                                    'slave address
'   I2cwbyte H                                              'high address
'   I2cwbyte L                                              'low address
'   I2cwbyte Value                                          'value to write
'   I2cstop                                                 'stop condition
'   Waitms 10

'End