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
	  serout tcpip,baud,("Indoor Sensor not found",cr,lf)
	  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
  	
  	bintoascii adjtemp,b25,b26,b27
  	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:

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 -

adjtemp=temp12 *9 /8 +320
bintoascii adjtemp, etc...............

Works now.

Neil.
 
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
	  serout tcpip,baud,("Indoor Sensor not found",cr,lf)
	  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
  	
  	bintoascii adjtemp,b25,b26,b27
  	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.
w0 = w0*9/5+32
 
Top