DS18B20 : +/- 0.5 fok, de a gyakorlatban +/- 0.1 fok
DHT11 : +/- 2 fok
Az autót nem tudom
Tipp: olvadó jég: 0 fok
Kód: Egész kijelölése
Dim Ds18b20_scratchpad(9) As Byte
Dim DS18B20_integer_temp As Integer AT DS18B20_Scratchpad OVERLAY
Dim DS18B20_single_temp As Single
Dim Calculated_CRC_value As Byte
Dim I As Byte
Dim Homerseklet As String * 6
1wreset ' Master issues reset pulse.
1wwrite &HCC ' Master issues Skip ROM command.
1wwrite &H44 ' Master issues Convert T command.
Waitms 800 ' Wait for T conversion.
1wreset ' Master issues reset pulse.
1wwrite &HCC ' Master issues Skip ROM command.
1wwrite &HBE ' Master issues Read Scratchpad command.
' Master reads entire scratchpad including CRC.
Ds18b20_scratchpad(1) = 1wread(9)
Calculated_crc_value = Crc8(ds18b20_scratchpad(1) , 8) 'Claculate the CRC value
If Ds18b20_scratchpad(9) = Calculated_CRC_value Then
Ds18b20_single_temp = Ds18b20_integer_temp * 0.0625
Homerseklet = Fusing(ds18b20_single_temp , "#.##")
Lcdat 1 , 1 , "DS18B20 Temp" , Black , White
Lcdat 10 , 1 , Homerseklet , Black , White
Else
Lcdat 60 , 1 , "CRC Error" , Black , White
End If
Kód: Egész kijelölése
Device 16F628A
Declare XTAL = 4
ALL_DIGITAL = true
Output PORTA.0
Output PORTA.1
Output PORTA.2
Output PORTA.3
Output PORTB
Low PORTA.0
Low PORTA.1
Low PORTA.2
Low PORTA.3
Dim Temperature As DWord ' Temperature storage
Dim Temperature_m As Word
Dim temperature_a As DWord
Dim Count_remain As Byte ' Count remaining
Dim Count_per_c As Byte ' Count per degree C
Dim Dum As Byte ' Dummy variable to pad OWIN
Dim i As Byte
Dim d As Byte
Dim dis As Byte
Dim t As Byte
Dim bt As Bit
Dim dis0 As Byte, dis1 As Byte, dis2 As Byte, dis3 As Byte
Dim d0 As Byte, d1 As Byte, d2 As Byte, d3 As Byte
Dim dig0 As Byte, dig1 As Byte, dig2 As Byte, dig3 As Byte
Dim C As Byte
Dim meanb As DWord
Dim first As Bit
Dim x As Byte
Dim templow As Byte
Dim temphigh As Byte
Dim sig As Bit
first = 0
meanb = 5000
Symbol DQ = PORTA.4 ' One-wire data pin
DelayMS 100 ' Wait for PICmicro to stabilise
Mainloop:
OWrite DQ, 1, [$CC, $44] ' Start temperature conversion
Repeat
x = 10
GoSub display
ORead DQ, 4, [C] ' Keep reading low pulses until
Until C <> 0
OWrite DQ, 1, [$CC, $BE] ' Read the temperature
Low PORTA.0
Low PORTA.1
Low PORTA.2
Low PORTA.3
'ORead DQ, 0, [Temperature_m.LowByte, Temperature_m.HighByte, Dum,Dum,Dum,Dum, Count_remain, Count_per_c]
ORead DQ, 0, [templow, temphigh, Dum,Dum,Dum,Dum, Count_remain, Count_per_c]
'Temphigh = 255
'Templow = 206
Temperature_m.LowByte = templow
Temperature_m.HighByte = temphigh '+-
If temphigh = 0 Then
sig = 0
Temperature_m = (((Temperature_m >> 1) * 100) - 25) + (((Count_per_c - Count_remain) * 100) / Count_per_c)
'Temperature_m = ((Temperature_m >> 1) * 100)
EndIf
If temphigh = 255 Then
sig = 1
Temperature_m = 65535 - Temperature_m + 1
Temperature_m = (((Temperature_m >> 1) * 100) + 25) + (((Count_per_c - Count_remain) * 100) / Count_per_c)
'Temperature_m = ((Temperature_m >> 1) * 100)
EndIf
Temperature = Temperature_m
If first = 0 Then
meanb = Temperature
first = 1
EndIf
temperature_a = Temperature
meanb = meanb * 10
meanb = meanb + temperature_a '"lowpass filter"
meanb = meanb / 11
temperature_a = meanb
If Temperature = temperature_a Then t = 2
If Temperature > temperature_a Then t = 128
If Temperature < temperature_a Then t = 16
If Temperature < 500 Then t = 18
If Temperature > 9500 Then t = 130
If sig = 1 Then t = 146
dig0 = Dig temperature_a ,0
dig1 = Dig temperature_a ,1
dig2 = Dig temperature_a ,2
dig3 = Dig temperature_a ,3
x = 255
GoSub display
GoTo Mainloop
End
display:
For i = 1 To x
DelayMS 2
Inc dis
If dis > 3 Then dis = 0
Select Case dis
Case 0:
High PORTA.0
Low PORTA.1
Low PORTA.2
Low PORTA.3
PORTB = t
Case 1:
Low PORTA.0
High PORTA.1
Low PORTA.2
Low PORTA.3
d1 = LookUp dig1 , [252,96,218,242,102,182,190,228,254,246,252]
PORTB = d1
Case 2:
Low PORTA.0
Low PORTA.1
High PORTA.2
Low PORTA.3
d2 = LookUp dig2 , [252,96,218,242,102,182,190,228,254,246,252]
PORTB = d2+1
Case 3:
Low PORTA.0
Low PORTA.1
Low PORTA.2
High PORTA.3
d3 = LookUp dig3 , [252,96,218,242,102,182,190,228,254,246,252]
PORTB = d3
End Select
Next i
Return