Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

please help me , of necessity

Status
Not open for further replies.

alsadiq

New Member
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
 
Which part of the code don't you understand? You would be getting more helpful responses if you're more specific.
 
One other thing that might get you help is if you posted your code properly. Your original posted code is a difficult to read mess. When you post code, use the Code tags. Before pasting your code, click on the # symbol in the menu above the text entry box. Then paste. This keeps the code formatting intact so it's readable, like this: :)
Code:
;****************** 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
 
i will be happy if u can

thanks , i wanna understand division parts of this process because these parts are the main section of the code source
 
Basically they are doing division by subtraction. In 10/2, you can subtract 2 from 10, 5 times before there is none left. They count how many times you can subtract 2 from 10. One part is for remainder. One part for if you have gone too far.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top