Hallo pebisoft,
ich häng dir mal dein Programm, das du eigentlich nur aus dem Samples-Ordner kopiert hast, unten an. Ich habe allerdings ein paar Änderungen vorgenommen, um es auf meine Hardware anzupassen (Chip/Quarz/LCD/Ports). Im Prinzip bleibt es aber. Ich habe das Programm mit einem 24c16 getestet, weil ich grade keinen anderen da habe, und es funktioniert.
Prüfe bitte deine Hardware nach. Pullups werden z.B. gerne vergessen.
Und lies dir den letzten Absatz im Programm durch. Du willst ja mehr als 256 Byte schreiben.
Gruß, Michael
Code:$regfile = "m8def.dat" $crystal = 16000000 Config Portd = Output Config Sda = Portc.4 Config Scl = Portc.5 'Lcd -pins Sind unter Options-Compiler-LCD eingetragen Initlcd Cls Lcd "EE - Test" Waitms 500 Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Byte) Declare Sub Read_eeprom(byval Adres As Byte , Value As Byte) Const Addressw = 162 'slave write address Const Addressr = 163 'slave read address Dim I As Byte Dim B1 As Byte , Adres As Byte , Value As Byte 'dim byte 'Hier werden 3 Adressen beschrieben. Zum Test, obs geklappt hat, 'die 3 Zeilen einfach ausklammern und das Programm nochmal brennen Call Write_eeprom(1 , 15) Call Write_eeprom(2 , 75) Call Write_eeprom(3 , 222) Cls Locate 1 , 1 For I = 1 To 3 Call Read_eeprom(i , Value) Lcd I ; "=" ; Value ; " "; Next End '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 ' 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







Zitieren
Lesezeichen