Zitat von
Björn
Meinst du sowas?
in der Richtung. gebräuchlicher sind die 24c64/256/512 Typen.
Mit Bascom ist das auch recht einfach zu handhaben. Ein Beispielprogramm alá "Klein Erna" hänge ich mal dran, in der Praxis geht das eleganter, so wird aber das Prinzip IMHO am deutlichsten:
Code:
'----------------- EEPROM Test für Mega168-Experimenter -----------------------
'Juli 2005 - HR
'------------------------------------------------------------------------------
$regfile = "m168def.dat" 'bzw "m8def.dat"
$crystal = 7372800
Enable Interrupts
Declare Sub Read_eeprom()
Declare Sub Write_eeprom()
Dim Address As Word At &H112
Dim Address_low As Byte At &H112 Overlay
Dim Address_high As Byte At &H113 Overlay
Dim I As Word
Dim Temp As Byte
Dim Dev As Byte
Dim Wert As Byte
Const Ext_eeprom = 162 'I2C Geräteadresse ggf. anpassen
'------------------------------------------------------------------------------
Cursor Off
Cls
Lcd "EEPROM TEST"
Locate 2 , 1
Lcd "SCHREIBE"
'------------------------------------------
Dev = Ext_eeprom
For Address = 0 To 49
Wert = Address 'schreibt die Adresse als Wert
Call Write_eeprom() 'ins EEprom
Next
Wait 2
Cls
Lcd " LESE"
For Address = 0 To 49
Call Read_eeprom()
Locate 2 , 1
Lcd "ADR: " ; Address ; " " ; "Wert: " ; Wert
Wait 1 ' Pause , damit man was sieht
Next
Wait 2
Cls
Lcd "FERTIG"
End
'------------------------------------------------------
'- Byte (wert) auf EEprom Adresse (address) speichern -
'------------------------------------------------------
Sub Write_eeprom()
I2cstart
I2cwbyte Dev
I2cwbyte Address_high
I2cwbyte Address_low
I2cwbyte Wert
I2cstop
Waitms 2
End Sub
'-----------------------------------------------------------------
'--- Byte (wert) von EEprom Adresse (address) lesen ---
'-----------------------------------------------------------------
Sub Read_eeprom()
Dim Devread As Byte
Devread = Dev + 1
I2cstart
I2cwbyte Dev
I2cwbyte Address_high
I2cwbyte Address_low
I2cstop
I2cstart
I2cwbyte Devread
I2crbyte Wert , Nack
I2cstop
End Sub
'------------------------------------------------------------------------------
Grüße
Henrik
Lesezeichen