Also, mein Code besteht aus zwei Teilen.
Zum Einen eine header Datei, die am Anfang includet wird:
Ziemlich am Ende des Codes wird eine zweite Datei includet, dieCode:'--------- LM 75 Temperatursensor --------- $nocompile Const Lm75_base = &B10010000 Declare Function Lm75read(byval Lm75_id As Byte) As Single Config I2cdelay = 100 Config Scl = Portc.1 ' we need to provide the SCL pin name Config Sda = Portc.0 ' we need to provide the SDA pin name I2cinit
die Funktionen enthält, zentrale Sub ist diese:
abgefragt wird das dann über:Code:' ############ LM75 Temperatursensor ############ $nocompile Function Lm75read(lm75_id) ' --> Variablen global deklariert in variables.bas <-- ' Lm75r = Read-Instruktion ' Lm75h = Highbyte Temperatur ' Lm75l = Lowbyte Temperatur ' Lm75_dez = Temperatur als Dezimalwert Local Sub_tempbyte As Byte Local Loc_lm75h As Byte Local Loc_lm75l As Byte Local Loc_tempword As Word Local Loc_lm75_dez As Single Sub_tempbyte = Lm75_id Sub_tempbyte = Sub_tempbyte And &B00000111 Sub_tempbyte = Sub_tempbyte * 2 Sub_tempbyte = Sub_tempbyte Or Lm75_base Lm75w = Sub_tempbyte '= &B10010010 Lm75r = Sub_tempbyte + 1 '= &B10010011 I2cstart I2cwbyte Lm75r I2crbyte Loc_lm75h , Ack I2crbyte Loc_lm75l , Nack I2cstop If Loc_lm75h.7 = 1 Then ' Temperatur ist negativ Loc_lm75l = Not Loc_lm75l Loc_lm75h = Not Loc_lm75h Loc_tempword = Makeint(loc_lm75l , Loc_lm75h) Shift Loc_tempword , Right , 5 Loc_Lm75_dez = Loc_tempword Loc_lm75_dez = Loc_lm75_dez / 8 Loc_lm75_dez = 0 - Loc_lm75_dez Lm75read = Loc_lm75_dez Else Loc_tempword = Makeint(loc_lm75l , Loc_lm75h) Shift Loc_tempword , Right , 5 Loc_Lm75_dez = Loc_tempword Loc_Lm75_dez = Loc_Lm75_dez / 8 Loc_lm75read = Loc_lm75_dez End If End Function End
Temperatur_single = Lm75read(lm75_id) ' 0 bis 8
Wirklich einfache Codes von meinen Jugendsünden hab ich nicht wirklich
noch da ... ob Hardware-oder Soft-TWI kommt aufs Projekt an ... bei diesem
hab ich die Software TWI verwendet. Wenn die LM75 nix sagen hängt
das meist an den Pullups oder an der Adressierung.
Beim LM75 gibts 2 verschiedene Adressen je nach Typ wenn ich mich
noch richtig erinnere ... irgendwo tief im Datenblatt mein ich da mal was
gelesen zu haben.








Zitieren

Lesezeichen