Voltsx4 bsf Voltx4,0 ; call this if u want a 0-20V display, else
Volts ; 0-5V = 0-255 adc. (8bits) => 1V=51 out of 255, .1=5. Derive decimal display from this.
;Inputs: Read binary voltage from 'voltage' variable (0-5V) =>(0-255 binary)
;uses Tmp2 as ADC binary voltage input variable -low byte, Offset as binary Input Variable High byte needed for x4 display
; Voltx4,0 is set if 0-20V display required. Otherwise 0-5V
; volts from a 9.1k/27K resistor 1/4 voltage divider feeding the PIC ADC.
call Vcalc; returns with with Tmp=V and Tmp1= decimal V
goto Vdecimal ; display current voltage.
Vcalc movf Voltage,w
Vcalc1 call WregX100 ; source in wreg,results in TempL/H
movlw .51; 1 Volt in binary (divisor)
call Div16X8; divisor in wreg,Dividend in TempL/H & results in TempL/H, with 500 as a max value => 5.00V
btfss Voltx4,0 ; test if to x4 the input, must be set from before .
return
movlw .10; divisor
call Div16X8; divide by 10, leaving 50 as a max value => 8 bit
movlw .4 ; multiplier
call Mult8X8; for 50 x 4 = 200 max value => 20.0V, results in TempL/H
return
; now get patterns for com. cathode. digital display of volts in human readable digits
Vdecimal
call Bindec1; decimal display of # in TempL/H
btfss Voltx4,0 ; test if to x4 the input, must be set from before .
bsf Hundreds,7; set 2 decimal places (5.00V)
btfsc Voltx4,0 ; test if to x4 the input, must be set from before .
bsf Tens,7; set 1 decimal place (20.0V)
return
;*********************************************************************************************************************************************
Bindec1 ; Converts 2 byte binary (tempL/TempH) into 4 digit decimal display.
; might be a good idea to clear the display digits (Thousands,Hundreds,Tens,Units) before this executes.
call Thou ; get thousands in decimal
Call Hundred ; get hundreds
call Ten ; get tens & units.
return
Thou movlw .3 ; high byte set to 3 = 768
movwf FixedH ; high byte of # to be subtracted.
movlw .232 ; low byte
movwf FixedL ; 768 + 232 = 1000's column
ThouCount
call Subtract
xorlw .1 ; check for returned wreg value. A zero occurs if a 1 was returned
btfss STATUS,Z ; branch if 1 was returned, else
goto Fixremainder ; due to last subtraction the remainder went -ve, so we fix this.
incf Thousands,f
goto ThouCount
Fixremainder ;restore remainder to continue calculating for next decimal column.
movf FixedL,w ; low byte
addwf TempL,f ; TempL=TempL + FixedL
movf FixedH,w ; hi byte
btfsc STATUS,C ; check for carry, set if TempL + FixedL >255
incfsz FixedH,w ; Increment due to carry set ,if zero skip next.
addwf TempH,f ; TempH=TempH+FixedH (+1 if carry was set)
return
Hundred movlw 0 ; high byte set to 0
movwf FixedH ; high byte of # to be subtracted.
movlw .100 ; low byte
movwf FixedL ; 0 + 100 = 100's column
HdrdCount
call Subtract
xorlw .1 ; check for returned wreg value. A zero occurs if a 1 was returned
btfss STATUS,Z ; branch if 1 was returned, else
goto Fixremainder ; due to last subtraction the remainder went -ve, so we fix this.
incf Hundreds,f
goto HdrdCount
Ten movlw .10 ; for small magnitude digit displays load TempL with under 100 and call this directly.
subwf TempL,f; test for 10 if carry clr wreg is under 10
btfsc STATUS,C ;skip if carry clr (-ve result) , else
incf Tens,f; incr the tens column
btfsc STATUS,C ; skip if carry clr (-ve result), else
goto Ten ; now check for 20,30 etc
movf TempL,w
addlw .10; as last calc was -ve recreate +ve number.
DispLEDS ; for just a display with under 10 magnitude, call this directly with the # in wreg. Then clr the tens,hundreds & thousands bytes after.
call Dpattern
Movwf Units ; store 7 seg display pattern for units
movf Tens,w
call Dpattern
movwf Tens; store 7 seg display pattern for tens
movf Hundreds,w
call Dpattern