'
' USB Thermometer
' Version: 0.1 by steliosm
' based on original work done by Hippy
'
Symbol TReading = W0
Symbol Whole = B2
Symbol Fract = B3
Symbol SignBit = B4
Symbol Dig = B5
Symbol TempC_100 = W4
Main:
high 1
ReadTemp12 2,TReading
Gosub Calculate
Serout 4, t2400, (10,13)
pause 100
low 1
pause 5000 ‘wait 5 seconds
Goto Main
Calculate:
SignBit = TReading / 256 / 128
If SignBit = 0 Then Positive
' it's negative
TReading = TReading ^ $ffff + 1
Positive:
TempC_100 = TReading * 6 ' TC = value * 0.0625
TReading = TReading * 25 / 100
TempC_100 = TempC_100 + TReading
GoSub DisplayTemp
Return
DisplayTemp:
Whole = TempC_100 / 100
Fract = TempC_100 % 100
If SignBit = 0 Then DisplayTemp_1 ' Positive temperature
Serout 4, t2400, ("-")
DisplayTemp_1:
Serout 4, t2400, (#Whole, ".")
' be sure the fractional is two digits
Dig = Fract / 10
Serout 4, t2400, (#Dig)
Dig = Fract % 10
Serout 4, t2400, (#Dig)
Return