DUMMY_LOAD
; DUMMY TEMPERATURES ;------------------------------------------------------
; MOVLW B'00000111' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = 2000
; MOVLW B'11010000' ; C = 125.0
; MOVWF TEMPLO_C ; F = 257.0
; MOVLW B'00000101' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = 1360
; MOVLW B'01010000' ; C = 85.0
; MOVWF TEMPLO_C ; F = 185.0
; MOVLW B'00000011' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = 913
; MOVLW B'10010001' ; C = 57.0625
; MOVWF TEMPLO_C ; F = 134.7
; MOVLW B'00000001' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = 401
; MOVLW B'10010001' ; C = 25.0625
; MOVWF TEMPLO_C ; F = 77.1
; MOVLW B'11111111' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = -2
; MOVLW B'11111110' ; C = -0.125
; MOVWF TEMPLO_C ; F = 31.8
; MOVLW B'11111111' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = -10
; MOVLW B'11110110' ; C = -0.625
; MOVWF TEMPLO_C ; F = 30.9
; MOVLW B'11111111' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = -162
; MOVLW B'01011110' ; C = -10.125
; MOVWF TEMPLO_C ; F = 13.8
MOVLW B'11111110' ; Load Dummy Temperature
MOVWF TEMPHI_C ; Decimal = -402
MOVLW B'01101110' ; C = -25.125
MOVWF TEMPLO_C ; F = -13.2
; MOVLW B'11111100' ; Load Dummy Temperature
; MOVWF TEMPHI_C ; Decimal = -880
; MOVLW B'10010000' ; C = -55.0
; MOVWF TEMPLO_C ; F = -67.0
; DUMMY TEMPERATURES ;------------------------------------------------------
DISPLAY_TEMP
TEST_IF_NEGATIVE
BCF FLAGS, 1 ; Clear Negative Flag
BTFSS TEMPHI_C, 7 ; Test if Temperature is negative (2's complement format)
GOTO COPY ; NOT Negative, skip "UNDO_2SCOMPLEMENT"
BSF FLAGS, 1 ; Set Negative Flag; used later
COPY
MOVF TEMPLO_C, W ; Copy Celsius Temperature Data into Fahrenheit Registers for conversion
MOVWF TEMPLO_F ;
MOVF TEMPHI_C, W ;
MOVWF TEMPHI_F ;
; The following 3 routines convert the Celsius Temperature Data into Fahrenheit * 10.
; This is acheived by dividing by 8 and adding the original number, which gives 18 times the value.
; If you now add 320 you will have the temperature in Fahrenheit times ten.
; After the conversion it is simply a matter of displaying the data with the decimal shifted one place to the right.
; Example
; 25 Degrees C = B'0000000110010000' = D'400'
; 400 / 8 = 50
; 50 + 400 = 450
; 450 + 320 = 770
; 770 / 10 = 77 Degrees Fahrenheit
ADD_4 ; Adding 4 ensures number is correctly rounded after DIVIDE_BY_8 routine
BCF STATUS, Z
INCF TEMPLO_F, F
BTFSC STATUS, Z
INCF TEMPHI_F, F
INCF TEMPLO_F, F
BTFSC STATUS, Z
INCF TEMPHI_F, F
INCF TEMPLO_F, F
BTFSC STATUS, Z
INCF TEMPHI_F, F
INCF TEMPLO_F, F
BTFSC STATUS, Z
INCF TEMPHI_F, F
DIVIDE_BY_8
RRF TEMPHI_F, F ; Divide 16 bit number by 8 by shifting right 3 times
RRF TEMPLO_F, F ; / 2
RRF TEMPHI_F, F ;
RRF TEMPLO_F, F ; / 4
RRF TEMPHI_F, F ;
RRF TEMPLO_F, F ; / 8
MASK_BITS ; This routine sets or clear the upper 3 bits of TEMPHI_F depending on weather or not the temp is negative or positive
BTFSS TEMPHI_C, 7 ; Is temp negative?
GOTO $+D'7' ; No
MOVF TEMPLO_F, F ; Temperature may be negative but result after ADD_4 may have caused TEMPLO_F to overflow
BTFSC STATUS, Z ; Did TEMPLO_F overflow?
GOTO $+D'4' ; Yes, clear upper 3 bits of TEMPHI_F
MOVLW B'11100000' ;
IORWF TEMPHI_F, F ; No, Set upper 3 bits
GOTO $+D'3' ;
MOVLW B'00011111' ; Clear upper 3 bits
ANDWF TEMPHI_F, F ;
ADD_ORIGINAL
BCF STATUS, C ; Add original number
MOVF TEMPLO_C, W ;
ADDWF TEMPLO_F, F ;
BTFSC STATUS, C ;
INCF TEMPHI_C, F ;
MOVF TEMPHI_C, W ;
ADDWF TEMPHI_F, F ; Temperature is now 18 x the value
ADD_320
MOVLW B'01000000' ;
ADDWF TEMPLO_F, F ;
BTFSC STATUS, C ;
INCF TEMPHI_F, F ;
MOVLW B'00000001' ;
ADDWF TEMPHI_F, F ; Result is now C x 18 + 320 (= F x 10)
BTFSS TEMPHI_F, 7 ; Test if number negative (2's complemented)
GOTO BIN_TO_DEC_F ; No, skip undo 2's complement
COMF TEMPLO_F, F ; Invert TEMPLO
COMF TEMPHI_F, F ; Invert TEMPHI
INCFSZ TEMPLO_F, F ; Increment TEMPLO once; After inverting the data, add one to acheive equivalent positive number (see 2's complement)
GOTO $+D'2' ; No overflow skip next instruction
INCF TEMPHI_F, F ; Overflow occured, increment upper byte
BIN_TO_DEC_F ; This routine converts a 16-bit number held in TEMPHI_F:TEMPLO_F to Decimal and stores it in 4 GPR's; THOUS, HUNS, TENS & ONES
; Example 1225;
; THOUS holds amount of thousands (i.e. 0000 0001 = 1x1000)
; 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)
; These registers are then used as jump pointers when calling digits to display
INCF TEMPLO_F ; Preload TEMPHI + 1
INCF TEMPHI_F ; Preload TEMPHI + 1
CLRF THOUS ; HUNS = 0000 0000
MOVLW D'246' ; MOVE Decimal '246' to W
MOVWF HUNS ; ONES GPR = 1111 0101
MOVWF TENS ; TENS GPR = 1111 0101
MOVWF ONES ; ONES GPR = 1111 0101
DECFSZ TEMPLO_F, F ; Decement TEMPHI register
GOTO $+D'4' ; NOT 0, skip next instruction
DECFSZ TEMPHI_F, F ; Decement TEMPHI register
GOTO $+D'2' ; NOT 0, skip next instruction
GOTO $+D'9' ; NOT 0, skip next instruction
INCFSZ ONES, F ; Increment ONES register, skip if 0
GOTO $-D'6' ; NOT 0, GOTO here - 4 instructions
INCFSZ TENS, F ; IS 0, Increment TENS register skip if 0
GOTO $-D'9' ; GOTO here - 7 instructions & reset the ONES register to D'246'
INCFSZ HUNS, F ; TENS overflowed, Increment HUNS
GOTO $-D'12' ; GOTO here - 10 instructions & reset the ONES and TENS registers to D'246'
INCF THOUS, F ; TENS overflowed, Increment HUNS
GOTO $-D'15' ; GOTO here - 10 instructions & reset the ONES and TENS registers to D'246'
SUBWF HUNS, F ; W still holds D'246 so subract it from TENS register to determine how many 'TENS'
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'