Code:
$regfile = "m32def.dat"
$crystal = 16000000
' LCD konfigurieren Port auf Ausgabe setzten und Pin's entsprechend zuordnen
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcd = 16 * 4
Config Lcdbus = 4
Config Portd.0 = Output
Portd.0 = 1
Deflcdchar 1 , 8 , 20 , 8 , 32 , 32 , 32 , 32 , 32
Cursor Off
' Pin für 1wire Schnittstelle festlegen, Schnittstelle wird von Bascom durch Software realisiert
Config 1wire = Portd.7
Dim Dsid(24) As Byte
' Die Adresse meines DS1820 die ich vorher ermittelt habe
Dsid(1) = &H10 : Dsid(2) = &H99 : Dsid(3) = &H4E : Dsid(4) = &H71 : Dsid(5) = &H01 : Dsid(6) = &H08 : Dsid(7) = &H00 : Dsid(8) = &H6D
'^= 1
Dsid(9) = &H10 : Dsid(10) = &H3D : Dsid(11) = &H48 : Dsid(12) = &H71 : Dsid(13) = &H01 : Dsid(14) = &H08 : Dsid(15) = &H00 : Dsid(16) = &H71
'^= 2
Dsid(17) = &H10 : Dsid(18) = &H4D : Dsid(19) = &H47 : Dsid(20) = &H71 : Dsid(21) = &H01 : Dsid(22) = &H08 : Dsid(23) = &H00 : Dsid(24) = &H86
'^= 3
Dim Sc(9) As Byte
Dim Sc2(9) As Byte
Dim Sc3(9) As Byte
Dim T As Byte
Dim T2 As Byte
Dim T3 As Byte
Dim H As Long
Dim Flag As Bit
Dim Eram_h As Eram Long
Dim X As Long
H = Eram_h
Dim M As Long
Dim Flag2 As Bit
Dim Eram_m As Eram Long
Dim Y As Long
M = Eram_m
Dim Flag3 As Bit
Dim Flag4 As Bit
Do
Wait 1
' Alle angeschlossenen DS1820 zum Messen veranlassen
1wreset
1wwrite &HCC
1wwrite &H44
Waitms 750
' Den gewünschten Sensor auswählen
1wverify Dsid(1)
' Kommando READ SCRATCHPAD
1wwrite &HBE
Sc(1) = 1wread(9)
If Sc(9) = Crc8(sc(1) , 8) Then
T = Sc(1)
If Sc(2) > 0 Then
T = 256 - T
End If
T = T / 2
Locate 1 , 1
Lcd "T:"
If Sc(2) > 0 Then Lcd "-";
Lcd T;
If Sc(1).0 = 1 Then
Lcd ".5" ; Chr(1) ; " / "
Else
Lcd ".0" ; Chr(1) ; " / "
End If
End If
Waitms 1
1wreset
1wwrite &HCC
1wwrite &H44
Waitms 750
' Den gewünschten Sensor auswählen
1wverify Dsid(9)
' Kommando READ SCRATCHPAD
1wwrite &HBE
Sc2(1) = 1wread(9)
If Sc2(9) = Crc8(sc2(1) , 8) Then
T2 = Sc2(1)
If Sc2(2) > 0 Then
T2 = 256 - T2
End If
T2 = T2 / 2
Locate 1 , 11
If Sc2(2) > 0 Then Lcd "-";
Lcd T2 ;
If Sc2(1).0 = 1 Then
Lcd ".5" ; Chr(1)
Else
Lcd ".0" ; Chr(1)
End If
End If
' Ausgabe alle 0,75 Sekunden
Waitms 1
If T > H Then Set Flag
If Flag = 1 Then
If Sc(1).0 = 1 Then
X = T + 1
Else
X = T
End If
Eram_h = X
H = Eram_h
Reset Flag
End If
If T2 > H Then Set Flag
If Flag = 1 Then
If Sc2(1).0 = 1 Then
X = T2 + 1
Else
X = T2
End If
Eram_h = X
H = Eram_h
Reset Flag
End If
If Sc(2) > 0 Then
If T > M Then
Set Flag2
If Flag2 = 1 Then
Y = T
Eram_m = Y
M = Eram_m
Reset Flag2
End If
End If
End If
If Sc2(2) > 0 Then
If T2 > M Then
Set Flag4
If Flag4 = 1 Then
Y = T2
Eram_m = Y
M = Eram_m
Reset Flag4
End If
End If
End If
Locate 4 , 1
Lcd "max." ; H ; Chr(1)
Locate 4 , 9
Lcd "min.-" ; M ; Chr(1)
Loop
End
Lesezeichen