In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Beau Schwabe wrote: Here is a snippet of code written in Spin that I have been working on... [code] [b]PUB[/b] hirestempc : tc |cr,cpc '' Returns temperature in 0.01° C units '' -- resolution is 0.0625° C [b]if[/b] started high(rst) ' activate sensor shiftout(RdTmp, 8) ' send read temp command tc := shiftin(9) ' read temp in 0.5° C units low(rst) ' deactivate sensor high(rst) ' activate sensor shiftout(RdCntr, 8) ' send Read Counter command cr := shiftin(9) ' read Remaining Counts low(rst) ' deactivate sensor high(rst) ' activate sensor shiftout(RdSlope, 8) ' send Read Slope command cpc := shiftin(9) ' read Counts Per deg C low(rst) ' deactivate sensor tc := tc << 23 ~> 23 ' extend sign bit tc &= !%1 ' Strip LSB tc *= 100 ' Scale values up by 100 tc += ((cpc-cr)*100)/cpc ' Add hires LSB data tc -= 25 ' Bit offset adjust tc *= 5 ' convert to 10ths ' tc /= 10 ' Scale values down by 10 [b]PUB[/b] hirestempf : tf '' Returns temperature in 0.01° F units '' -- resolution is 0.1125° F [b]if[/b] started tf := hirestempc * 9 / 5 + 3200 ' convert to Fahrenheit [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=145582#m145876 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)