CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

immediate change by external interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
smoglu



Joined: 23 Jun 2010
Posts: 7

View user's profile Send private message

immediate change by external interrupt
PostPosted: Thu Jul 08, 2010 9:49 am     Reply with quote

Hi.
In the code below, I change the value of "action" once external interrupt is triggered (by a button Smile ). 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;
   }
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 2:23 pm     Reply with quote

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.
smoglu



Joined: 23 Jun 2010
Posts: 7

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 8:40 pm     Reply with quote

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.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Jul 09, 2010 2:03 am     Reply with quote

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.
smoglu



Joined: 23 Jun 2010
Posts: 7

View user's profile Send private message

PostPosted: Fri Jul 09, 2010 7:19 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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