DS1620 and celsius degrees below 0 ?
With the code below i read the temperature in celsius from a DS1620, and it works fine until the temperature goes under 0 degrees. Then i get a strange result!
Im going to present the tempreature on a LED display, its because of that i have to separate the digits.
Im going to present the tempreature on a LED display, its because of that i have to separate the digits.
Repeat
Temperature.Start(0,1,2)
cData := Temperature.gettempc
tensValue := (cData/100)
onesValue := (cData/10)-((cData/100)*10)
debug.start(31, 30, 0, 9600)
debug.dec(tensValue)
debug.dec(onesValue)
debug.str(string(" C"))
debug.tx(13)

Comments
if cData < 0 cData := -cData debug.tx ('-') .... ....This fix the sign bit so you can do normal math on it. As Tracy pointed out, the raw value is in 0.5 degree units. Multiply that by 5 to get 0.1 degree units with 0.5 degrees of resolution. From there everything is pretty easy.
tc := tc << 23 ~> 23 ' extend sign bit tc *= 5 ' convert to 10ths return tcSo its already does that for me.
My problem is that i need to get the answer in two separate digits (to present it on a LED display).
if (tc < 0) sign := 1 tc := -tc else sign := 0 tens := tc / 100 ones := (tc // 100) / 10 tenths := tc // 10