Hi,
ich habe wieder mal meine porbleme mit dem I²C Bus und Eeproms.
Ich habe hier mal ein bischen Code für den 24LC16 aber der funktionirt
nicht.
Code:$regfile = "2313def.dat" ' specify the used micro
$crystal = 1000000 ' used crystal frequency
$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
Declare Sub Read_eeprom
Config Sda = Portd.1
Config Scl = Portd.0
Config Lcdpin = Pin , Db4 = Portd.6 , Db5 = Portb.0 , Db6 = Portb.1 , Db7 = Portb.2 , E = Portb.3 , Rs = Portb.4
Dim I As Bit
Config Lcd = 16 * 2 'configure lcd screen
Dim Addres As Byte
Dim Wert As Byte 'clear the LCD display
Dim Lesen As Byte
Cls
Do
Cls
Locate 1 , 1
Lcd Chr(122) 'display this at the top line
If I = 0 Then
Addres = 1
Wert = 122
Call Write_eeprom
I = 1
Wert = 0
End If
If I = 1 Then
Call Read_eeprom
Locate 2 , 1
Lcd Chr(lesen)
End If
Loop
End
Sub Write_eeprom(byval Addres As Byte , Byval Block As Byte , Byval Wert As Byte)
I2cstart 'start condition
Waitms 1
I2cwbyte &B10100000 ' Bausteinadresse
Waitms 1
I2cwbyte Addres ' Adresse im IC
Waitms 1
I2cwbyte Wert ' Byte schreiben
Waitms 1
I2cstop ' Stopbedingung
Waitms 10 ' int. Schreibzeit abwarten
End Sub
Sub Read_eeprom(byval Addres As Byte , Byval Block As Byte , Byval Lesen As Byte)
I2cstart 'start condition
Waitms 1
I2cwbyte &B10100001 ' Bausteinadresse
Waitms 1
I2crbyte Lesen
Waitms 1
I2cstop ' Stopbedingung
Waitms 10 ' int. Schreibzeit abwarten
End Sub
Verbesserungsvorschläge sind wilkommen