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.
;******************************************************************
;
; BC2DC - convert binary °C*16 to decimal °C*10 in D3:D0 vars
;
; formula is: °C*10 = (10*(Celsius*16))/16
; = (10*(TempH:TempL))/16
;
; D3:D0 result '-250' to '1250' (°C*10)
;
BC2DC
movlw d'10' ; multiplier 10 |B0
call Multiply ; do 10 x TempH:TempL |B0
goto Div16 ; |B0
;******************************************************************
;
; BC2DF - convert binary °C*16 to decimal °F*10 in D3:D0 vars
;
; formula is: °F*10 = (18*(Celsius*16)+(320*16))/16
; = (18*(TempH:TempL)+( 5120))/16
;
; D3:D0 result '-670' to '2570' (°F*10)
;
BC2DF
movlw d'18' ; multiplier 18 (9/5*10) |B0
call Multiply ; do 18 x TempH:TempL |B0
;
; add (32 * 10 * 16) to result
;
movlw low (.320*.16) ; add (320 * 16) to Product |B0
addwf ProdL,F ; |B0
skpnc ; |B0
incf ProdH,F ; |B0
movlw high (.320*.16) ; |B0
addwf ProdH,F ; |B0
skpnc ; |B0
incf ProdU,F ; |B0
;
; divide result by 16
;
Div16
movlw d'4' ; |B0
movwf Count ; |B0
DivNext
clrc ; clear C |B0
rrf ProdH,F ; |B0
rrf ProdL,F ; |B0
decfsz Count,F ; all done? |B0
goto DivNext ; no, branch, else |B0
;
; check for negative number result
;
bcf TempH,7 ; clear "negative" flag |B0
btfss ProdH,3 ; negative result? |B0
goto Bin2Dec ; no, branch, else |B0
;
; convert it to a postive number
;
bsf TempH,7 ; set "negative" flag |B0
movf ProdL,W ; temperature low |B0
sublw h'00' ; two's complement it |B0
movwf ProdL ; ^ is that a verb (grin)? |B0
movf ProdH,W ; temperature high in W |B0
skpc ; borrow? no, skip, else |B0
incf ProdH,W ; temperature high + 1 in W |B0
sublw h'00' ; two's complement it |B0
movwf ProdH ; |B0
;
; Peter Hemsley's 12-bit Bin_to_BCD (ProdH:ProdL binary input
; and D3:D0 unpacked BCD output)
;