'Speichern in EEprom / c15022010 / n+p 'Atmega8 / LCD 2 x 16 'speichern einer Zahl ins EEprom (24C01) 'Achtung, max. Zahl = 2559999 !!! $regfile = "m8def.dat" $crystal = 1000000 Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.4 , Rs = Portb.5 Config Lcd = 16 * 2 Cls 'SDA und SCL def. Config Sda = Portc.4 Config Scl = Portc.5 Dim A As Byte 'Speicheraddr schreiben Dim B As Byte 'Speicheraddr lesen Dim C As Single Dim D As Single Dim E As Single Dim F As Single Dim G As Single Dim H As Single Dim I As Single Dim J As Byte Dim K As Byte Dim L As Byte Dim J1 As Single Dim K1 As Single Dim L1 As Single Dim Suwe As Single 'hier kann zum testen ein Startwert eingegeben werden (max. 2559999 !) 'C = 0 '- Anfangswert aus EEprom holen : Goto Holen : Do '- Zahl zerlegen : C = Suwe + 1 D = C / 10000 E = C / 100 F = Int(d) 'Wert 1 G = Frac(d) G = G * 100 H = Int(g) 'Wert 2 I = Frac(g) I = I * 100 I = Round(i) J = F K = H L = I 'Wert 3 '- schreibe ins EEprom : A = 30 I2cstart 'Start I2C I2cwbyte &HA0 'Sende Slave Adresse I2cwbyte A 'adr 1 I2cwbyte J I2cstop Waitms 10 A = A + 1 'adr + 1 I2cstart I2cwbyte &HA0 I2cwbyte A 'adr 2 I2cwbyte K I2cstop Waitms 10 A = A + 1 I2cstart I2cwbyte &HA0 I2cwbyte A 'adr 3 I2cwbyte L I2cstop Waitms 10 Locate 1 , 1 Lcd J ; " " ; K ; " " ; L ; " " 'zeige die Schreibwerte Waitms 50 '- lesen vom EEprom : Holen: B = 30 I2cstart 'Start I2C I2cwbyte &HA0 'sende Slave Adresse I2cwbyte B 'sende Speicheradresse I2cstart 'Start I2C I2cwbyte &HA1 'sende Slave Adresse +1 für Lesen I2crbyte J , Nack 'lese Adresse vom EEprom I2cstop 'Stop I2C B = B + 1 'adr + 1 I2cstart I2cwbyte &HA0 I2cwbyte B I2cstart I2cwbyte &HA1 I2crbyte K , Nack I2cstop B = B + 1 I2cstart I2cwbyte &HA0 I2cwbyte B I2cstart I2cwbyte &HA1 I2crbyte L , Nack I2cstop '- Zahl zusammensetzen : J1 = J * 10000 K1 = K * 100 L1 = K1 + L Suwe = J1 + L1 Locate 2 , 1 Lcd Fusing(suwe , "######.") 'zeige ausgelesene Werte Waitms 200 Loop End