#### craigcurtin

##### Senior Member
Guys,

I have gone over previous forum posts and must admit that i am pretty lost when it comes to the maths that is involved with READTEMP12 (probably why i had always used plain old READTEMP before.

I have a routine that Hippy previously posted that is working to format and displat the READTEMP12 routine (on a 40x1) to an LCD panel and this is working well.

However i would like to be able to test within my code for more granular than 1 degree increments and am unsure how to do this

Currently my code goes something like

If AverageBackDoorTemperature &gt;= 22 then Goto Overheat

What i would like to do is be more granular than 1 degree increments.

I am working in Celsius and store the ReadTEMP12 value in a word variable.

Can anyone provide some code i can try to follow to compare on 1/2 (or 1/4 degree numbers) presumably if these were left as binary this would be easiest ?

Craig

#### craigcurtin

##### Senior Member
Sorry, I should have also added that i am not worried about Negative values for this application

regards

Craig

#### BeanieBots

##### Moderator
Hippy has some good code that works to 1/2,1/4,1/8 etc but personally I prefer to work in 0.1s.
Readtemp12 returns the celcius value X16.
Hence /16 to get to deg C.
However, if you want the extra decimal place, then X10 first.
eg (I've used many variables to show working)
w1=w0*10 '(temp X 160)
w2=w1/16 '(temp X 10)
b0=w2/10 'integer part
b1=w2//10 'decimal part
sertout pin,baud,(#b0,&quot;.&quot;,#b1,\$D3,&quot;C&quot

The \$D3 is the code needed to display degree sign for MY LCD display. It may be different for other displays and I can't remember the value for the terminal.

Edited by - beaniebots on 14/08/2007 08:29:02

#### craigcurtin

##### Senior Member
Hey BB,

Thanks for the quick response. Once i get the temp Value x10 (as per step 2), i do not want to output to screen but simply test and action - so would it be valid to say something like

if W1 &gt; 215 goto overheat 'this is the equivalent of 21.5 degrees ?

regards

Craig

#### BeanieBots

##### Moderator
If you only want a threshhold, then don't do any maths at all.

Keeping with the variables used in my example:-

if w0 &gt; 344 then...
is equivalent to:-
if w0 &gt; 21.5C then...

Or, for easier reading (but reduced resolution) you could use:-

if w2 &gt; 215 then...
is equivalent to:-
if w2 &gt; 21.5C then...

Note, I had a variable typo in the earlier reply which is now corrected.

Edited by - beaniebots on 14/08/2007 09:39:45

#### craigcurtin

##### Senior Member
Thanks very much BB - much appreciated

Craig

#### flyingnunrt

##### Senior Member
How does readtemp12 handle temperatures below 0 deg C ?

#### craigcurtin

##### Senior Member
Something about a sign bit in Bit 7 i believe. One of the brains trust will know though, or you can do a search on ReadTemp12 - there are heaps of posts (most answered by Hippy, Stan or BB

Craig

#### pha555

##### Senior Member
I have some sample code at

http://www.phanderson.com/picaxe/ds18b20_08m.html

P H Anderson