tempr not working


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3348
Posted: 02:41am 30 May 2026      

The two programs with the updated equation.

Function DS18S20(PinNbr As INTEGER) As FLOAT
' derived from DS18x20 test code by TassyJim
 Local INTEGER  T1,T2,T3

 OneWire RESET PinNbr                       ' reset before command
 OneWire WRITE PinNbr, 8, 2, &hCC, &h44     ' start conversion
 Pause 750                                  ' maximum conversion time
 OneWire RESET PinNbr                       ' reset before command
 OneWire WRITE PinNbr, 1, 2, &hCC, &hBE     ' command read data
 OneWire READ PinNbr, 0, 7, T1,T2,T3,T3,T3,T3,T3  'get the data

 DS18S20t = Str2bin(int16,Chr$(T1)+Chr$(T2))\2 + (16-T3)/16 -0.9375 'process the data
End Function


PinNbr = MM.Info(pinno GP7)
Dim n = 0
Dim DStemp = DS18S20(PinNbr) 'purge old data and start new conversion

Do    'Main Loop
 t = timer
 Print n;
 DStemp = DS18S20(PinNbr) 'get Temp, if ready
 If DStemp <> 1000 Then
   Print
   Print "Temp =";DStemp;"`C"
   n = 0
 EndIf
 Do : Loop until Timer - t > 49.9
 Inc n,50
Loop

Function DS18S20(PinNbr As INTEGER) As FLOAT
' Adapted from DS18x20 test code by TassyJim
 Local INTEGER  done, T1, T2, T3
 DS18S20 = 1000                           'standard error code
 OneWire READ PinNbr, 4, 1, done          ' is conversion finished?
 If done = 0 Then Exit Function           ' if not return to program
 'Get the data
 OneWire RESET PinNbr                     ' reset before command
 OneWire WRITE PinNbr, 1, 2, &hCC, &hBE   ' command read data
 OneWire READ PinNbr, 0, 7, T1,T2,T3,T3,T3,T3,T3  'get the data

 Value = Str2bin(int16,Chr$(T1)+Chr$(T2))\2 + (16-T3)/16 -0.9375 'process the data
 DS18S20 = Cint(Value * 10) / 10 'round to 1/10ths

 'Start conversion, ready for next read
 OneWire RESET PinNbr                      ' reset before command
 OneWire WRITE PinNbr, 8, 2, &hCC, &h44    ' start conversion
End Function

End