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.

How to call function one when flag set

Status
Not open for further replies.

five0

New Member
I has flag increment evertime when timer interrupt active, as simple code below
my "do_my_jobx" routine run many time until bit clear
How can I call funtion only one time, and wait until next set ?
Code:
;any Pic with timer interupt will do
;timer interrupt
	;save W,STATUS ,clear TMR0F
[COLOR="Blue"]	incf	flag[/COLOR]
	;restore STATUS,W
;RETFIE
mainloop
	btfss	flag,0
	goto	next01		;no bit set go next
	call	do_my_job0	;else do my job, I want one time only
next01	btfss	flag,1
	goto	next0x
[COLOR="Red"]	call	do_my_job1	;I want do_my_job one time till next set[/COLOR]
next0x	btfsc	flag,7
	call	do_my_job2	;I want do_my_job one time till next set
	goto	mainloop
	
do_my_job0
	nop
do_my_job1
	nop
do_my_job2
	nop
	return
 
Your problem here is really how you've labelled your GPR's - calling a counting register 'flag' isn't helping you.

A flag register should be just that, a register containing a number of flags.

So keep the flag register, but add a second one called 'count' or something similar - increment count in the ISR, and check what value it is - when it equals the correct value, then set the corresponding flag. The routine called in response to the flag should also clear the flag, this will prevent it been called more than once.
 
Status
Not open for further replies.

Latest threads

Back
Top