ºC -> ºF Conversion


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Since the DS1802 gives you temperature in half degrees, it would be easier to use the formula F = (C*9/10)+32. For negative numbers you need to convert the negative temperature to positive and reverse the formula F = 32-((ABS C)*9/10). Spotting negative numbers is easily done by looking at the highest bit. If it's set the number is negative.

    TempC VAR WORD
    TempF VAR WORD

    IF TempC.15 THEN
    TempF = 32-((ABS TempC)*9/10)
    ELSE
    TempF = (TempC*9/10)+32
    ENDIF


    You could use the ** operator to save the division. This operator makes a multiplication and an "invisible" division by 65536. 0.9 * 65536 = 58982.4, since we can only use integers we round that to 58983. Our calculation will look like......

    IF TempC.15 THEN
    TempF = 32-((ABS TempC)**58983)
    ELSE
    TempF = (TempC**58983)+32
    ENDIF

    /Ingvar

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    For the EASIEST way to convert temperatures.

    Try my Temperature Conversion routines for PBP.

    It's an INCLUDE file that converts between Celsius, Fahrenheit and Kelvin.

    HTH,
       Darrel

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 02:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 17:26
  3. Multiple if then optimization
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 35
    Last Post: - 5th March 2008, 13:15
  4. A/D conversion problem on 18F4431
    By ttease in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th April 2007, 00:03
  5. Strange A/D conversion...
    By Christos_K in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2005, 02:35

Members who have read this thread : 0

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