18B20 Thermometer Question


Closed Thread
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    89

    Default 18B20 Thermometer Question

    Hello all again. I just have a newbie question here. I am using the 18b20 dallas one wire and all is well except one thing. I am trying to cause a port pin to high at 40 degrees f. In celcius this is 4.444444444444 you get the idea. The binary string is something like this:
    0000 0000 0100 0111 which is about 4.4375 degrees celcius which is close enough. This is the code I am using which is complements of Reynolds Electronics:

    OWIN D, 4, [Stat]' Check for still busy converting
    IF Stat = 0 THEN W1' Still busy?, then loop
    OWOUT D, 1,[$55,$28,$7A,$4A,$66,$00,$00,$00,$84,$BE]
    OWIN D, 2, [Temp.LOWBYTE,Temp.HIGHBYTE]' Read two bytes, then end communications
    IF Temp.bit15 = 1 THEN Below_32 ' Check for temp below 0°C
    Sign = "+"
    Temp = ((((Temp >> 4) + 50) * 9) /5) -58
    LCDout $fe,$94,"Temp #1 =","+", DEC Temp,".", DEC2 Temp,"F"

    I am just unsure how to mess with the code necessary for the temp conversion with a 16 bit binary number. I read a couple of strings that are close to what I needed but I couldn't get them to work. I appreciate any help.

    Travin

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The factory default resolution the DS18B20 is 12-bit. If you're just testing for
    over 4.4 deg C, then after reading the temp, try this;

    TEMP = TEMP >> 4 ' Middle 8-bits into low byte. (see data sheet)
    IF TEMP.LowByte >= 4 THEN HIGH Whatever_PIN

    The lower 4-bits of TEMP is the remainder in 0.0625 deg C increments. By
    shifting TEMP >> 4 you're just shifting out the lower 4-bits, and using the
    whole temp result which is the middle 8-bits of 16-bit word TEMP.

    If you need better resolution, then test the lower 4-bits of TEMP first, then
    shift >> 4 to get the whole number.

    Remainder VAR BYTE
    Whole VAR BYTE

    Remainder = (TEMP.LowByte & $0F) ' Mask & keep lower 4-bits in TEMP
    TEMP = TEMP >> 4 ' Shift middle 8-bits into low byte
    Whole = TEMP.LowByte ' Middle 8-bits of TEMP in Whole

    IF (Whole > 4) AND (Remainder = 7) THEN HIGH PIN ' IF > 4.4 deg C THEN

    7 * 0.0625 = 0.4375 deg C.
    Last edited by Bruce; - 5th April 2006 at 01:21.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. General digital thermometer question Thermistor
    By Neosec in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st June 2008, 02:32
  2. Remote PIC input question
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2007, 15:44
  3. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  4. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49
  5. Timer / CCP Question
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd November 2005, 08:22

Members who have read this thread : 1

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