BIN_TO_DEC ; This routine converts an 8-bit number to Decimal and stores the answer in 3 GPR's; HUNS, TENS & ONES
; HUNS holds amount of hundreds (i.e. 0000 0010 = 2x100), TENS holds amount of tens (i.e. 0000 0010 = 2x10) & ONES holds amount of ones (i.e. 0000 0101 = 5x1)
BCF INTCON, GIE ; Disable Interrupts
INCF TEMPHI ; Preload TEMPHI + 1
CLRF HUNS ; HUNS = 0000 0000
MOVLW D'246' ; MOVE Decimal'246' to W
MOVWF TENS ; TENS GPR = 1111 0101
MOVWF ONES ; ONES GPR = 1111 0101
DECFSZ TEMPHI, F ; Decement TEMPHI register
GOTO $+2 ; NOT 0, skip next instruction
GOTO $+7 ; IS 0, TEMPHI = 0000 0000, skip next 6 instructions and calculate how many tens and hundreds
INCFSZ ONES, F ; Increment ONES register, skip if 0
GOTO $-D'4' ; NOT 0, GOTO here - 4 instructions
INCFSZ TENS, F ; IS 0, Increment TENS register skip if 0
GOTO $-D'7' ; GOTO here - 7 instructions & reset the ONES register to D'246'
INCF HUNS, F ; TENS overflowed, Increment HUNS
GOTO $-D'10' ; GOTO here - 10 instructions & reset the ONES and TENS registers to D'246'
SUBWF TENS, F ; W still holds D'246 so subract it from TENS register to determine how many 'TENS'
SUBWF ONES, F ; W still holds D'246 so subract it from ONES register to determine how many 'ONES'
; TENTHS = Fraction * 10 / 16 (Pommies routine to convert 4 bit number wher each bit represents 0.625 degrees, into rounded deciaml number)
MOVLW B'00001111' ;
ANDWF TEMPLO,F ;
MOVF TEMPLO,W ;
ADDWF TEMPLO,F ; *2, C=0
RLF TEMPLO,F ; *4, C=0
ADDWF TEMPLO,F ; *5, C=0
RLF TEMPLO,F ; *10
MOVLW B'00001000' ;
ADDWF TEMPLO,F ; Rounding
SWAPF TEMPLO,W ; Pseudo divide by 16
ANDLW B'00001111' ;
MOVWF TENTHS ;
; Leading zero suppression & minus (-) sign if Temperature Negative
MOVF HUNS, W ; Does HUNS equal 1 or 2? MOVF instruction affects Z bit of STATUS register
BTFSC STATUS, Z ; Test Z bit of STATUS register to see if HUNS = 0000 0000
MOVLW B'00001010' ; Jump Pointer for blank arrangement
BTFSC SCRATCHPAD_BYTE1, 7 ; Is Temperature Negative?
MOVLW B'00001011' ; YES, Jump Pointer for - arrangement
MOVWF HUNS ;
BTFSS STATUS, Z ; Test Z bit of STATUS register to see if HUNS = 0000 0000
GOTO $+5 ; HUNS is not, therefore do not blank TENS
MOVF TENS, W ; Does TENS equal 0?
BTFSC STATUS, Z ; Test Z bit of STATUS register to see if last instruction = 0000 0000
MOVLW B'00001010' ; Jump Pointer for blank arrangement
MOVWF TENS ;
BSF INTCON, GIE ; Disable Interrupts
GOTO GET_TEMP