|
|
View previous topic :: View next topic |
Author |
Message |
ron Guest
|
strange question about interrupts.. |
Posted: Sun Jun 29, 2008 10:51 am |
|
|
hi
while i do external interrupt (with pic16f690), the interrupt come back to the point it was before called.
i want that after interrupt done, the program will start again from the beginning of - my the while(1). for example:
do interrupt code...
while(1)
{
a
b
c
}
if while calling to interrupt he was at c, i want that when interrupt is finished i will go over again to a...and not to c...
how can i do that ?
thanx ! |
|
|
Ttelmah Guest
|
|
Posted: Sun Jun 29, 2008 12:14 pm |
|
|
You can't.
You need to rewrite your loop, with something along the lines of:
Code: |
int8 state=0
//Interrupt handler here
#int_xxxxx
void int_handler(void) {
//code to actually handle the interrupt itself
state=0;
}
//Then in the main
while (true) {
switch (state) {
case 0:
state++;
enable_interrupts(global);
a();
disable_interrupts(global);
break;
case 1:
state++;
enable_interrupts(global);
b();
disable_interrupts(global);
break;
case 2:
state++;
enable_interrupts(global);
c();
disable_interrupts(global);
break;
case 3:
state=0;
enable_interrupts(global);
d();
disable_interrupts(global);
break;
default:
state=0;
}
}
|
Normally the state variable, is incremented in each 'case', so the system executes 'a', then 'b', then 'c', and finally 'd'.
When the interrupt occurs, the state gets reset, so execution begins again at 'a', as soon as the current function completes.
Note that the actual 'loop', has the interrupts disabled, while the state is changed.
Best Wishes |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Jun 30, 2008 10:59 am |
|
|
Another way to deal with it would be to do a() and b() and c(), but keep their results in some kind of "provisional" buffer. Part of the interrupt routine would be to set a flag--call it "interrupt_occurred". Then after the loop in main() had done its work, you could test the flag and if there hadn't been an interrupt, install the provisional results. On the other hand, if the interrupt had occurred, discard the provisional results and clear the flag, then loop again.
It depends a lot on what you really need this kind of code for. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|