View previous topic :: View next topic |
Author |
Message |
smoglu
Joined: 23 Jun 2010 Posts: 7
|
immediate change by external interrupt |
Posted: Thu Jul 08, 2010 9:49 am |
|
|
Hi.
In the code below, I change the value of "action" once external interrupt is triggered (by a button ). Then, the action according to action's value is executed, after the last one is completed in "case x:" part. However, I want it to immediately change its action once the button is pressed, for example making it jump to beginning of switch statement. How can I do that?
Thanks.
Code: |
#include <16F876A.h>
#fuses HS, NOPROTECT, PUT, BROWNOUT, NOWDT, NOLVP
#use delay(clock=20000000)
int8 action;
#int_EXT
void ext_isr(void)
{
if(action < 6){ action += 1;}
else { action = 1;}
}
void main()
{
action = 1;
ext_int_edge(L_TO_H);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1){
switch (action) {
case 1://some action
break;
case 2://some action
break;
case 3://some action
break;
case 4://some action
break;
case 5:
//some action
break;
case 6:
//some action
break;
}
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 08, 2010 2:23 pm |
|
|
Explain the purpose of your program. It will help us get an idea of
the correct way to structure it. In other words, tell us what your
project is about, and the basic user interface. |
|
![](templates/subSilver/images/spacer.gif) |
smoglu
Joined: 23 Jun 2010 Posts: 7
|
|
Posted: Thu Jul 08, 2010 8:40 pm |
|
|
The project is simple. There are 20 leds connected to PIC I/O, and they turn on and off according to some pattern. For example, one pattern: only first one of them is on and then only second ... goes up to 20th one, then comes back to first and repeats. When the button is pressed, another pattern should begin immediately. There are a total of 6 patterns. |
|
![](templates/subSilver/images/spacer.gif) |
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Jul 09, 2010 2:03 am |
|
|
The way you would solve this problem depends on how you are cycling through your routines.
If each one is a separate loop then you will need to check for a change in action within each routine and exit that routine back to the main loop (switch) when action has changed.
If the routine is within the main loop (which includes the switch) and you just perform a different output once each time round the loop based on action then it should just work.
If you are using an interrupt routine to change the display based on action, this should also just work.
So I assume you have a separate function which includes a loop for each pattern which you call from your switch. You therefore need to monitor the action value within each of these and return back to the main loop when it changes.
try posting some more code. |
|
![](templates/subSilver/images/spacer.gif) |
smoglu
Joined: 23 Jun 2010 Posts: 7
|
|
Posted: Fri Jul 09, 2010 7:19 am |
|
|
Ok, I guess I found the solution. But I need to wait for tomorrow to try it out. So after I try it, I will share my problem and my solution together. |
|
![](templates/subSilver/images/spacer.gif) |
|