--------------------------------------

I have a temperature sensor (MCP9800) that spits out a 12 bit - 2's compliment number that represents degrees C from - 55 C to + 125 C.

Name:  temp_reg.gif
Views: 935
Size:  9.4 KB

12 bits of resolution gives increments of 1/16 degree C and displays to 4 decimal places, like so: 26.1875
I've got it up and running and successfully displaying temperature in degrees C. With this:

Code:
'-----------Read and display temperature from MCP9800-----------

checktemp9800:
    i2cread sda9800,clk9800,adr_R,[T_MSB,T_LSB]           'read the 2 bytes of temperature data
    TempC = abs T_MSB                                      'all the stuff to the left of the decimal point is in the MSB.
    TempCdec = (T_LSB >>4) * 625                          'stuff to the right of the decimal point. Side shift out the unused bits and multiply by 625 for 1/16 degree C resolution.

    If T_MSB.7  then                                         'if the sign bit is "1", display a minus sign
        signind = "-"
        else
        signind = "+ "
    endif


    Lcdout $fe,2, "  ", signind, DEC TempC, "." ,DEC4 TempCdec, 223, " C   "   ' Display the info

return


By I can't for the life of me figure out how to do the conversion from degrees C to degrees F. !!

I have NO problem for temperatures ABOVE 32 F (0 C) You just multiply by 1.8 (or 18/10) and add 32. Simple...

But when the temperature goes BELOW 0 C then my life (and math) falls apart and I can't make it work right. And I'm not even sure what to do when the temp falls even further to less than 0 F.
I'm not sure why my brain won't do this. It seems like it should be simple enough.

I want to end up with degrees F available to at least 1 (preferably 2) decimal places, and it should work right over the whole range of -55 C to + 125C (-67 F to +257F)

Can someone please spin me around and pull the blindfold off?

Oh, and my "device" is a 16F887, so I'm stuck with 16 bit math.

Thanks...