# Farenheight Conversion

#### neiltechspec

##### Senior Member
I'm having a bit of trouble trying to convert to to Fahrenheit & displaying to one decimal place.

Currently using the following code which displays rounded value only.

Code:
``````	readtemp12 insens,temp12	;read raw into temp12

if temp12 = 0 then		;check if DS18B20 responding
pause 750
return
endif

sign = 43				;sign is "+"

if temp12 > 2048 then		;check for below 0 deg
sign = 45				;if temp is below 0 sign is "-"
let temp12 = - temp12		;two's compliment
endif

adjtemp = temp12 * 10 / 16

serout tcpip,baud,("Indoor Temp:  ",sign,b25,b26,".",b27,\$b0,"C")

fht=adjtemp /10 *9 /5 +32      ;fahrenheit conversion
serout tcpip,baud,(" (",#fht,\$b0,"F)",cr,lf)

return``````
This code is an extract from whole program (indoor temp, outdoor temp, windspeed & humidity).

Any help with the maths appreciated.

Neil.

Last edited:

why the "/10"?

#### cravenhaven

##### Senior Member
I think you have made the variable "fht" a byte variable. Try making it a word variable and you should see the solution to your problem.

#### Armp

##### Senior Member
BTW The calculation can be rearranged to handle temps down to 0F/-17.8C without overflow:

Code:
``````readtemp12 insens,temp12	;read raw into temp12
adjtemp = temp12 + 285 *9 / 8   ; Give Temperature in tenths degree F``````
temp12 = -285 (-17.8C) gives 0; temp12 = 0 gives 320; temp12=1600 (100C) gives 2120

Last edited:

#### neiltechspec

##### Senior Member
The problem was another of my silly mistakes.

I was converting the Celsius adjusted value instead of the raw 12 bit value.

I'm using -

Works now.

Neil.

#### Digisapien

##### Member
I'm having a bit of trouble trying to convert to to Fahrenheit & displaying to one decimal place.

Currently using the following code which displays rounded value only.

Code:
``````	readtemp12 insens,temp12	;read raw into temp12

if temp12 = 0 then		;check if DS18B20 responding
pause 750
return
endif

sign = 43				;sign is "+"

if temp12 > 2048 then		;check for below 0 deg
sign = 45				;if temp is below 0 sign is "-"
let temp12 = - temp12		;two's compliment
endif

adjtemp = temp12 * 10 / 16