I have worked on ultrasonic distance meter and i have found a difficulty to understand the following source code of Capture process , i will be over the moon if anyone can help me and explain this process in an simple way
;****************** Capture Process ********************
capture
bcf pir1,ccp1if ;Clear CCP1 int flag
clrf p_countl ;Clear L count
clrf p_counth ;Clear H count
clrf ccp1con ;CCP1 off
division
movfw s_adj ;Read adjustment data
subwf ccpr1l,f ;Capture - adjust
btfsc status,z ;Result = 0 ?
goto division2 ;Yes. "R = 0"
btfsc status,c ;Result < 0 ?
goto division1 ;No. "R > 0"
goto division3 ;Yes."R < 0"
division1 ;( R > 0 )
movlw d'1' ;Set increment value
addwf p_countl,f ;Increment L count
btfss status,c ;Overflow ?
goto division ;No. Continue
incf p_counth,f ;Increment H count
goto division ;Jump next
division2 ;( R = 0 )
movfw ccpr1h ;Read CCPR1H
btfss status,z ;CCPR1H = 0 ?
goto division1 ;No. Next
movlw d'1' ;Set increment value
addwf p_countl,f ;Increment L count
btfss status,c ;Overflow ?
goto digit_set ;Jump to digit set
incf p_counth,f ;Increment H count
goto digit_set ;Jump to digit set
division3 ;( R < 0 )
movfw ccpr1h ;Read CCPR1H
btfss status,z ;CCPR1H = 0 ?
goto division4 ;No. Borrow process
goto digit_set ;Jump to digit set
division4
decf ccpr1h,f ;CCPR1H - 1
movlw d'255' ;Borrow value
addwf ccpr1l,f ;CCPR1L + 255
incf ccpr1l,f ;CCPR1L + 1
goto division1 ;Next
;****************** Capture Process ********************
capture
bcf pir1,ccp1if ;Clear CCP1 int flag
clrf p_countl ;Clear L count
clrf p_counth ;Clear H count
clrf ccp1con ;CCP1 off
division
movfw s_adj ;Read adjustment data
subwf ccpr1l,f ;Capture - adjust
btfsc status,z ;Result = 0 ?
goto division2 ;Yes. "R = 0"
btfsc status,c ;Result < 0 ?
goto division1 ;No. "R > 0"
goto division3 ;Yes."R < 0"
division1 ;( R > 0 )
movlw d'1' ;Set increment value
addwf p_countl,f ;Increment L count
btfss status,c ;Overflow ?
goto division ;No. Continue
incf p_counth,f ;Increment H count
goto division ;Jump next
division2 ;( R = 0 )
movfw ccpr1h ;Read CCPR1H
btfss status,z ;CCPR1H = 0 ?
goto division1 ;No. Next
movlw d'1' ;Set increment value
addwf p_countl,f ;Increment L count
btfss status,c ;Overflow ?
goto digit_set ;Jump to digit set
incf p_counth,f ;Increment H count
goto digit_set ;Jump to digit set
division3 ;( R < 0 )
movfw ccpr1h ;Read CCPR1H
btfss status,z ;CCPR1H = 0 ?
goto division4 ;No. Borrow process
goto digit_set ;Jump to digit set
division4
decf ccpr1h,f ;CCPR1H - 1
movlw d'255' ;Borrow value
addwf ccpr1l,f ;CCPR1L + 255
incf ccpr1l,f ;CCPR1L + 1
goto division1 ;Next