Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I just assumed they were "rounding" the number. The least significant bit in the DS18S20 temperature word is 1/2° but the "count_remain" byte, or 4 bits actually, is the full fractional portion of the Celsius temperature reading.Hi Mike,
I may have misunderstood this but the formula in the data sheet has an additional subtraction of ¼°C which when it is in 12 bit format would be minus 4.
Mike.
That should work fine and then you don't really need to format the data as 12-bit DS18B20 data...
movf Count_R,W ;count remain from SP
sublw .16 ;subtract from 16
movwf Index ;
movf Index,W ;get the index
call Table_Frac ;call the decimal digit
Hi Mike thanks for that hint.Same as subtract from 16.
Just a thought you put 16 instead of count per C because of the fraction (count remain) never exceeds 4 bits?Code:movf Count_R,W ;count remain from SP sublw .16 ;subtract from 16 movwf Index ; movf Index,W ;get the index call Table_Frac ;call the decimal digit
Is this how you made your formula?
;
call absolute ; make TempL positive
clrc ; clear carry
rrf TempL,F ; get rid of the half degree bit
movf count_remain,W ; get "count remain"
call FracTbl ; get fraction digit '0'..'9'
;
; TempL = integer number
; WREG = fractional digit '0'..'9'
; NegFlag = '1' if negative (from Absolute sub')
;
When the most significant bit is a '1' then the number is negative and you need to two's compliment it to make it positive (the "absolute" subroutine call in my example). You would need to do this on the fractional bits too.
I saw your other thread over on Forum.Microchip