dann versuch ichs mal so:
Code:
$lib "i2c_TWI.lib"
Config Scl = Portc.0 'PIN für I2C Bus
Config Sda = Portc.1
I2cinit
Config Twi = 400000
Dim Eehead(2) As Byte
Dim Ee_adresse01 As Word At Eehead Overlay
Dim Eebyte(4) As Byte
Dim Eesingle As Single At Eebyte Overlay
Dim Eeword(2) As Word At Eebyte Overlay
Dim Tempeebyte(4) As Byte
Dim Eebanz As Byte
Dim Eead As Word
Dim Exteetemp As Byte
Const 24c64w = &B10100000
Const 24c64r = &B10100001
Const Eetest = 1
'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(byref Ee_daten As Byte , Byval Ee_adresse As Word)
Declare Sub Saveword(byref Ee_daten As Word , Byval Ee_adresse As Word)
Declare Sub Savesingle(byref Ee_daten As Single , Byval Ee_adresse As Word )
Goto 001
Sub Savebyte(byref Ee_daten As Byte , Byval Ee_adresse As Word)
Eebyte(1) = Ee_daten
Ee_adresse01 = Ee_adresse
Eebanz = 1 : Gosub Write_ee
End Sub
Sub Saveword(byref Ee_daten As Word , Byval Ee_adresse As Word)
Eeword(1) = Ee_daten
Ee_adresse01 = Ee_adresse
Eebanz = 2 : Gosub Write_ee
End Sub
Sub Savesingle(byref Ee_daten As Single , Byval Ee_adresse As Word )
Eesingle = Ee_daten
Ee_adresse01 = Ee_adresse
Eebanz = 4 : Gosub Write_ee
End Sub
Function Loadbyte(byval Ee_adresse As Word) As Byte
Ee_adresse01 = Ee_adresse
Eebanz = 1 : Gosub Read_ee
Loadbyte = Eebyte(1)
End Function
Function Loadword(byval Ee_adresse As Word) As Word
Ee_adresse01 = Ee_adresse
Eebanz = 2 : Gosub Read_ee
Loadword = Eeword(1)
End Function
Function Loadsingle(byval Ee_adresse As Word) As Single
Ee_adresse01 = Ee_adresse
Eebanz = 4 : Gosub Read_ee
Loadsingle = Eesingle
End Function
'Routine zum schreiben von Daten in das EEPROM ++++++++++++++++++++++++++++++++
Write_ee:
Eead = Ee_adresse01 + Eebanz
For Exteetemp = 1 To Eebanz Step 1
I2cstart
I2cwbyte 24c64w 'send slave address
I2cwbyte Eehead(1)
I2cwbyte Eehead(2)
I2cwbyte Eebyte(exteetemp) 'send a value
I2cstop
incr Ee_adresse01
Waitms 10
Next
Return
'Routine zum lesen von Daten aus dem EEPROM ++++++++++++++++++++++++++++++++++++
Read_ee:
Eead = Ee_adresse01 + Eebanz
I2csend 24c64w , Eehead(1) , 2
waitms 1
I2creceive 24c64r , Eebyte(1) , 0 , Eebanz
Return
001:
#if Eetest = 1
Dim Ins As Single
Dim Inw As Word
Dim Inb As Byte
Do
Input "Single: " , Ins
Call Savesingle(ins , 5)
Print "gespeicherter Wert: " ; Ins
Ins = Loadsingle(5)
Print "geladener Wert: " ; Ins
Input "Word: " , Inw
Call Saveword(inw , 10)
Print "gespeicherter Wert: " ; Inw
Inw = Loadword(10)
Print "geladener Wert: " ; Inw
Input "Byte: " , Inb
Call Savebyte(inb , 30)
Print "gespeicherter Wert: " ; Inb
Inb = Loadbyte(30)
Print "geladener Wert: " ; Inb
Loop
#endif
Lesezeichen