Reading temperature using multi DS18B20


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Sep 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Reading temperature using multi DS18B20

    I am having some troubles understanding the read temperature portion of this code. Take the following exerpt from the code:
    W1:
    OWIN DQ,4,[busy] ' Check for still busy converting
    IF busy = 0 THEN W1' Still busy?, then loop
    owout dq,1,[$55,S[(L*8)+0],S[(L*8)+1],S[(L*8)+2],S[(L*8)+3],S[(L*8)+4],S[(L*8)+5],S[(L*8)+6],S[(L*8)+7],$BE]
    OWIN dq, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
    HotOrCold:
    IF Cold_Bit = Real_Cold THEN ' If Cold_Bit = 1, it's below "0" LcdDeg C
    Sign = "-" ' Display - symbol for negative temp
    Dummy = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise LcdDeg C
    endif

    if cold_bit = 0 then
    Sign = "+"
    Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
    TempC = DIV32 10 ' Use Div32 value to calculate precise LcdDeg C
    TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
    Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
    endif

    1. Okay so, under HotOrCold:, about 10 lines down you are assigning TempC to DIV32 10. No problems there. Then you assign TempC to (R_Temp & $0FF0) >> 4. Does this not just overwrite the value of TempC that you just assigned?

    2. Under HotOrCold: again. 3 lines down. What is the "~" for? Couldn't find any documentation on this from the picbasic help file. And what does the +1 do?

  2. #2
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Reading temperature using multi DS18B20

    I think I can answer your last question...

    ~ is Bitwise NOT... meaning to invert each bit

    For the other question I can not help... I have yet to understand exactly what the DIV32 function does.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Sep 2011
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Reading temperature using multi DS18B20

    Thanks! That clears that up. Do you know why the +1 on the end?

    The DIV32 command allows you to divide the 32 bit number held in internal registers. But that's not really important here. More importantly, why do we assign TEMPC, then reassign it again on the next line of code without using it.

  4. #4
    Join Date
    Apr 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: Reading temperature using multi DS18B20

    Thanks for posting your code. I was having difficulty with negative readings and converting to an integer. I saw what I was doing wrong, corrected my code and now I can read negative temperatures.
    thanks,

Similar Threads

  1. Please help with code for DS18B20
    By fratello in forum mel PIC BASIC Pro
    Replies: 109
    Last Post: - 28th April 2013, 22:12
  2. Multi DS18b20 Code help.
    By sccsltd in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2009, 07:13
  3. DS18S20 reading negative temperature
    By srob in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th December 2007, 22:21
  4. DS18B20 error reading
    By Gaetano in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th August 2007, 17:21
  5. Reading 5 DS18B20 Problem
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2005, 21:51

Members who have read this thread : 4

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts