Aus RN-Wissen.de
Zeile 24: | Zeile 24: | ||
=== Beispiel für EEprom 24C16 === | === Beispiel für EEprom 24C16 === | ||
<pre> | <pre> | ||
+ | '============I2C EEprom versuch V1.03================================== | ||
+ | |||
+ | ' =========== Für 24C16 EEprom ===================== | ||
+ | ' 8MHz Quarz | ||
+ | ' LCD auf Port B , | ||
+ | ' | ||
+ | $regfile = "m8def.dat" | ||
+ | $crystal = 8000000 | ||
+ | |||
+ | '---Config für LCD ----------------- | ||
+ | Config Lcd = 40 * 2 | ||
+ | Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , Rs = Portb.4 , E = Portb.5 | ||
+ | Config Lcdbus = 4 | ||
+ | Config Lcdmode = Port | ||
+ | Cursor On | ||
+ | |||
+ | |||
+ | 'SDA und SCL definieren | ||
+ | Config Sda = Portd.5 | ||
+ | Config Scl = Portd.7 | ||
+ | |||
+ | |||
+ | Dim X As Byte | ||
+ | Dim A As Byte | ||
+ | Dim B As Byte | ||
+ | Dim Schreiben As Byte | ||
+ | Dim Lesen As Byte | ||
+ | |||
+ | |||
+ | |||
+ | Schreiben = 0 | ||
+ | |||
+ | Do | ||
+ | |||
+ | '---- schreibe in EEprom ---- | ||
+ | For A = 1 To 10 | ||
+ | Incr X '1 bis Überlauf zählen | ||
+ | |||
+ | I2cstart 'Start I2C | ||
+ | I2cwbyte &HA0 'Sende Slavadresse | ||
+ | I2cwbyte A 'Sende Speicheradresse | ||
+ | I2cwbyte X 'Sende Wert | ||
+ | I2cstop 'Stop I2C | ||
+ | Waitms 10 'warte 10ms | ||
+ | |||
+ | Locate 1 , 1 | ||
+ | Lcd "ins EEprom = " ; X ; " " ' Ausgabe der geschriebenen Werte am LCD | ||
+ | Waitms 500 | ||
+ | Next A | ||
+ | |||
+ | |||
+ | '--- lesen vom EEprom ---- | ||
+ | For B = 1 To 10 | ||
+ | |||
+ | I2cstart 'Start I2C | ||
+ | I2cwbyte &HA0 'sende Slave Adresse schreiben | ||
+ | I2cwbyte B 'sende Speicheradresse | ||
+ | |||
+ | I2cstart 'Start I2C | ||
+ | I2cwbyte &HA1 'sende Slavadresse +1 für Schreiben | ||
+ | I2crbyte Lesen , Nack 'lese Adresse vom EEprom | ||
+ | I2cstop 'Stop I2C | ||
+ | |||
+ | Locate 2 , 1 | ||
+ | Lcd "Lese EEprom= " ; Lesen ; " " 'Ausgabe der EEprom Werte | ||
+ | Waitms 500 | ||
+ | Next B | ||
+ | |||
+ | Loop | ||
+ | End | ||
+ | |||
+ | |||
+ | |||
</pre> | </pre> |
Version vom 25. Januar 2006, 12:22 Uhr
Inhaltsverzeichnis
Ansteuern vom I2C EEproms mit Bascom
Allgemein
I
Etwas genauer
Struktur:
blablaaa
Beispiel für EEprom 24C16
'============I2C EEprom versuch V1.03================================== ' =========== Für 24C16 EEprom ===================== ' 8MHz Quarz ' LCD auf Port B , ' $regfile = "m8def.dat" $crystal = 8000000 '---Config für LCD ----------------- Config Lcd = 40 * 2 Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , Rs = Portb.4 , E = Portb.5 Config Lcdbus = 4 Config Lcdmode = Port Cursor On 'SDA und SCL definieren Config Sda = Portd.5 Config Scl = Portd.7 Dim X As Byte Dim A As Byte Dim B As Byte Dim Schreiben As Byte Dim Lesen As Byte Schreiben = 0 Do '---- schreibe in EEprom ---- For A = 1 To 10 Incr X '1 bis Überlauf zählen I2cstart 'Start I2C I2cwbyte &HA0 'Sende Slavadresse I2cwbyte A 'Sende Speicheradresse I2cwbyte X 'Sende Wert I2cstop 'Stop I2C Waitms 10 'warte 10ms Locate 1 , 1 Lcd "ins EEprom = " ; X ; " " ' Ausgabe der geschriebenen Werte am LCD Waitms 500 Next A '--- lesen vom EEprom ---- For B = 1 To 10 I2cstart 'Start I2C I2cwbyte &HA0 'sende Slave Adresse schreiben I2cwbyte B 'sende Speicheradresse I2cstart 'Start I2C I2cwbyte &HA1 'sende Slavadresse +1 für Schreiben I2crbyte Lesen , Nack 'lese Adresse vom EEprom I2cstop 'Stop I2C Locate 2 , 1 Lcd "Lese EEprom= " ; Lesen ; " " 'Ausgabe der EEprom Werte Waitms 500 Next B Loop End
Autor