Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:44 23 May 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : tempr not working

     Page 2 of 2    
Author Message
Peter63
Senior Member

Joined: 28/07/2017
Location: Sweden
Posts: 171
Posted: 09:09am 21 May 2026
Copy link to clipboard 
Print this post

  Quote  The ds18s20 isn't supported by MMBasic. It functions differently and is not compatible

GotIt!     /Peter63
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3222
Posted: 11:32am 21 May 2026
Copy link to clipboard 
Print this post

As Jim's test program seems to work, further down the thread linked to by @dddns there is a more compact Function based on Jim's program.
Function DS18x20(PinNbr As INTEGER) As FLOAT
' Extracted from DS18x20 test code by TassyJim
' Run that program and find the values that get your device to work.
' Copy those values into this Function
 Local INTEGER  t, T1, T2, done
 Local FLOAT Value=0

 OneWire RESET PinNbr                        ' reset before command
 OneWire WRITE PinNbr, 8, 2, &hcc, &h44      ' start conversion

 t = Timer
 Do               'There should be a result in less than 1000mS
  If Timer - t > 1000 Then
    Value = 1000 'standard error code
    Print "*** Timeout ***",
    Exit Do
  EndIf

 OneWire READ PinNbr, 4 , 1 , done       ' conversion done?
 Loop Until done
'  Print Timer - t;" mS conversion time", 'un-comment this to see how long it took
 If Value = 0 Then ' we have not timed out yet, so assume data is valid
  OneWire WRITE PinNbr, 1, 2, &hcc, &hbe      ' command read data
  OneWire READ PinNbr, 2, 2, T1, T2           ' get the data

  OneWire RESET PinNbr
   If T2 And &b1000 Then       'negative temp
     'make 2s complement (1s complement+1)
     T2 = (T2 Xor &hFF)
   T1 = (T1 Xor &hFF)+1

   If T1=1 Then T2=T2+1        'add the carry if required
     Value = -((T2 And &b111) * 256 + T1) / 16 'adjust this if the temp. is wrong
    Else                            'positive temp
     Value = ((T2 And &b111) * 256 + T1) / 16 'adjust this if the temp. is wrong
   EndIf
 EndIf
 DS18x20 = Value
End Function

Edited 2026-05-21 21:36 by phil99
 
Peter63
Senior Member

Joined: 28/07/2017
Location: Sweden
Posts: 171
Posted: 12:54pm 21 May 2026
Copy link to clipboard 
Print this post

  Quote  As Jim's test program seems to work, further down the thread linked to by @dddns there is a more compact Function based on Jim's program


Oh thanks, I will check further...

/Peter63
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026