;*************
;Varibles used
;*************
;ADH = stores first 2 bits of ADRESH
;ADL = stores the 8 bits of ADRESL
;AD1,AD2,AD3,AD4 = working variables inside BCD conversion
;D1,D2,D3,D4 = show variablesused in display
;*************************
;main program starts here
;*************************
Main call Multiplex
decfsz Count,F ;show display 20 times
goto $-2
movlw .20
movwf Count
call AD ;call AD convertion
goto Main
;***********************************
;increment routine updating 4 digits
;***********************************
Incr incf AD1,F
movf AD1,W
xorlw .10
btfss STATUS,Z
return
clrf AD1
incf AD2,F
movf AD2,W
xorlw .10
btfss STATUS,Z
return
clrf AD2
incf AD3,F
movf AD3,W
xorlw .10
btfss STATUS,Z
return
clrf AD3
incf AD4,F
movf AD4,W
xorlw .2
btfss STATUS,Z
return
clrf AD4
return
;**************
;AD conversion
;**************
AD bsf ADCON0,GO
btfsc ADCON0,GO
goto $-1
movf ADRESH,W ;get upper 2 bits
movwf ADH
bsf STATUS,RP0
movf ADRESL,W ;get lower 8 bits
bcf STATUS,RP0
movwf ADL
;**********************
;10 bit BCD conversion
;**********************
BCD clrf AD1
clrf AD2
clrf AD3
clrf AD4
btfss ADH,1
goto __256
btfss ADH,0
goto __512
movlw .7
movwf AD3
movlw .6
movwf AD2
movlw .8
movwf AD1
goto Trans
__512 movlw .5
movwf AD3
movlw .1
movwf AD2
movlw .2
movwf AD1
goto Trans
__256 btfss ADH,0
goto Trans
movlw .2
movwf AD3
movlw .5
movwf AD2
movlw .6
movwf AD1
goto Trans
Trans movf ADL,W
xorlw 00h
btfsc STATUS,Z
goto $+4
call Incr
decfsz ADL,F
goto $-2
;****************************************
;move working variables to show variables
;****************************************
movf AD1,W
movwf D1
movf AD2,W
movwf D2
movf AD3,W
movwf D3
movf AD4,W
movwf D4
return