;******************************************************************
;
; Convert °F*4 (ADRES) to °C*1000 (3 decimal places)
;
; ADRES values are °F * 4 (10mv/degree Fahrenheit or 2.5mv/step)
; using a 2.56v ADC reference voltage
;
; °C*1000 = ABS(35556 * ( °F*4 - 32*4 )) / 256
; = ABS(35556 * ( ADRES - 128 )) / 256
;
; NegFlag = '1' for '-' result or '0' for '+' result
;
; ADRES Output Display
; =====================================
; 0.00 °F 0 017778 -17.77 °C
; 5.00 °F 20 015000 -15.00 °C
; 10.00 °F 40 012222 -12.22 °C
; 15.00 °F 60 009444 - 9.44 °C
; 20.00 °F 80 006666 - 6.66 °C
; 25.00 °F 100 003888 - 3.88 °C
; 25.25 °F 101 003750 - 3.75 °C
; 25.50 °F 102 003611 - 3.61 °C
; 25.75 °F 103 003472 - 3.47 °C
; 26.00 °F 104 003333 - 3.33 °C
; 32.00 °F 128 000000 0.00 °C
; 60.00 °F 240 015555 15.55 °C
; 70.00 °F 280 021111 21.11 °C
; 77.00 °F 308 025000 25.00 °C
; 80.00 °F 320 026667 26.66 °C
; 90.00 °F 360 032222 32.22 °C
; 100.00 °F 400 037778 37.77 °C
; 212.00 °F 848 100001 100.00 °C
;
; Digit6:1 (msb:lsb) contain the bcd/decimal output
;
Celsius
movlw low(d'35556') ; setup multiplier Mult1H:L |B0
movwf Mult1L ; |B0
movlw high(d'35556') ; |B0
movwf Mult1H ; |B0
bsf STATUS,RP0 ; bank 1 |B1
movlw d'128' ; setup multiplicand Mult2H:L |B1
subwf ADRESL,W ; |B1
bcf STATUS,RP0 ; bank 0 |B0
movwf Mult2L ; |B0
movf ADRESH,W ; |B0
skpc ; borrow? no, skip, else |B0
decf ADRESH,W ; |B0
movwf Mult2H ; |B0
call Multiply ; sign extended 16x16 multiply |B0
;
; check for a negative or 'minus' product
;
AbsProd32
bcf NegFlag ; assume a positive result |B0
btfss Prod4,7 ; negative? yes, skip, else |B0
goto Bin2Dec24 ; branch, it's already positive |B0
;
; flag and "two's complement" the negative 32 bit product
;
bsf NegFlag ; indicate negative result |B0
comf Prod1,F ; two's complement Prod4:Prod1 |B0
comf Prod2,F ; |B0
comf Prod3,F ; |B0
comf Prod4,F ; |B0
incf Prod1,F ; |B0
skpnz ; |B0
incf Prod2,F ; |B0
skpnz ; |B0
incf Prod3,F ; |B0
skpnz ; |B0
incf Prod4,F ; |B0
;
; effect the /256 portion of the formula by ignoring LSB 'Prod1'
;
Bin2Dec24
clrf Digit1 ; clear output array |B0
clrf Digit2 ; |B0
clrf Digit3 ; |B0
clrf Digit4 ; |B0
clrf Digit5 ; |B0
clrf Digit6 ; |B0
; clrf Digit7 ; |B0
; clrf Digit8 ; |B0
movlw 24 ; 24 bits to do |B0
movwf BitCtr ; set bit loop counter |B0
BitLp rlf Prod2,F ; 24 bit single shift left |B0
rlf Prod3,F ; |B0
rlf Prod4,F ; |B0
movlw Digit1 ; |B0
movwf FSR ; setup indirect access |B0
; movlw 8 ; use this for 8 digit output |B0
movlw 6 ; use this for 6 digit output |B0
movwf DigCtr ; set digit loop counter |B0
AdjLp rlf INDF,F ; shift digit left 1 bit |B0
movlw -10 ; |B0
addwf INDF,W ; chk/adj for decimal overflow |B0
skpnc ; |B0
movwf INDF ; |B0
incf FSR,F ; next digit |B0
decfsz DigCtr,F ; |B0
goto AdjLp ; |B0
decfsz BitCtr,F ; next bit |B0
goto BitLp ; |B0
return ; |B0
;******************************************************************