Hallo PicNick,
gedacht war es so:
eesingle....eeword(2)......eebyte(6)
eesingle....eeword(2)......eebyte(5)
eesingle....eeword(1)......eebyte(4)
eesingle....eeword(1)......eebyte(3)
....................................eebyte(2)----------für Adresse(HighByte)
....................................eebyte(1)----------für Adresse(LowByte)
Mit Words funktionierts ganz gut, nur mit singles nicht:
Code:
$lib "i2c.lib"
Config Scl = Portc.0 'PIN für I2C Bus
Config Sda = Portc.1
I2cinit
Config I2cdelay = 3
Dim Eesingle As Single
Dim Eeword(2) As Word At Eesingle Overlay
Dim Eebyte(6) As Byte At Eesingle Overlay
Dim Eebanz As Byte
Dim Ee_adresse As Word
Dim Ee_adr(2) As Byte At Ee_adresse Overlay
Const 24c64w = &B10100000
Const 24c64r = &B10100001
'Definition der Funktionen ++++++++++++++++++++++++++++++++++++++++++++++++++++
Declare Function Loadbyte(byval Ee_adresse As Word) As Byte
Declare Function Loadword(byval Ee_adresse As Word) As Word
Declare Function Loadsingle(byval Ee_adresse As Word) As Single
Declare Sub Savebyte(byval Ee_daten As Byte , Byval Ee_adresse As Word)
Declare Sub Saveword(byval Ee_daten As Word , Byval Ee_adresse As Word)
Declare Sub Savesingle(byval Ee_daten As Single , Byval Ee_adresse As Word )
Goto 001
Sub Savebyte(byval Ee_daten As Byte , Byval Ee_adresse As Word)
Eebyte(3) = Ee_daten
Ee_adresse = Ee_adresse
Eebanz = 1 + 2 : Gosub Write_ee
End Sub
Sub Saveword(byval Ee_daten As Word , Byval Ee_adresse As Word)
Eeword(2) = Ee_daten
Ee_adresse = Ee_adresse
Eebanz = 2 + 2 : Gosub Write_ee
End Sub
Sub Savesingle(byval Ee_daten As Single , Byval Ee_adresse As Word )
Eesingle = Ee_daten
Ee_adresse = Ee_adresse
Eebanz = 4 + 2 : Gosub Write_ee
End Sub
Function Loadbyte(byval Ee_adresse As Word) As Byte
Ee_adresse = Ee_adresse
Eebanz = 1 : Gosub Read_ee
Loadbyte = Eebyte(3)
End Function
Function Loadword(byval Ee_adresse As Word) As Word
Ee_adresse = Ee_adresse
Eebanz = 2 : Gosub Read_ee
Loadword = Eeword(2)
End Function
Function Loadsingle(byval Ee_adresse As Word) As Single
Ee_adresse = Ee_adresse
Eebanz = 4 : Gosub Read_ee
Loadsingle = Eesingle
End Function
'Routine zum schreiben von Daten in das EEPROM ++++++++++++++++++++++++++++++++
Write_ee:
Eebyte(1) = Ee_adr(1)
Eebyte(2) = Ee_adr(2)
I2csend 24c64w , Eebyte(1) , Eebanz
Waitms 30
Return
'Routine zum lesen von Daten aus dem EEPROM ++++++++++++++++++++++++++++++++++++
Read_ee:
Eebyte(1) = Ee_adr(1)
Eebyte(2) = Ee_adr(2)
I2csend 24c64w , Eebyte(1) , 2
Waitms 5
I2creceive 24c64r , Eebyte(3) , 0 , Eebanz
Waitms 25
Return
001:
Dim Ins As Single
Dim Inw As Word
Dim Inb As Byte
Do
Input "Single: " , Ins
Call Savesingle(ins , 100)
Print "gespeicherter Wert: ";ins
Ins = Loadsingle(100)
Print "geladener Wert: " ; Ins
Input "Word: " , Inw
Call Saveword(inw , 100)
Print "gespeicherter Wert: " ; Inw
Inw = Loadword(100)
Print "geladener Wert: " ; Inw
Input "Byte: " , Inb
Call Savebyte(inb , 100)
Print "gespeicherter Wert: " ; Inb
Inb = Loadbyte(100)
Print "geladener Wert: " ; Inb
Loop
Lesezeichen