PDA

View Full Version : How do I code an interrupt to act upon simultanious inputs?



Archangel
- 17th September 2006, 06:48
Hi Everyone,
Can this be done, using 2 buttons which work to control existing sub programs,
can I push them both so as to invoke an interrupt which would then clear the
counter variables and cancel whichever subprogram is running, I may have as many as 4 or 5 different subprograms, i would like to cancel any of them by pressing these 2 buttons, I can do this with an AND gate and a seperate input pin on the PIC, But is there a way to code it without using the gate or the extra input pin?

something like:
IF PortA.0 AND PortA.1 >= 2 THEN
ON INTERRUPT GOTO Cancel
RESUME

Cancel:
ButtonVar1 = 0
ButtonVar2 = 0
RETURN

Any input is Appreciated.
Thanks
JS

Melanie
- 17th September 2006, 09:40
When an INTERRUPT (any interrupt) occurs, your program will jump to the part of your program designated as your Interrupt Service Routine. It is the job of your ISR to determine what caused the Interrupt and then act on it. You can only have ONE ISR jump point, but once you're inside your ISR, then you can check what caused the Interrupt and act on it. Interrupts have rules (like not allowing interrupts to interrupt interrupts I know it looks corny but it is gramatically correct!, and resetting Interrupt Flags), so it's better to read up on them before figuring how you're going to plan your code.

Archangel
- 17th September 2006, 20:15
Hi Melanie,
Ya . . . actually I wasn't really in the planning stage yet, the psudo code posted was to give clarity to what I was attempting to do. As I understand it a pic cannot look at 2 simultanious inputs and make a descision based on that information. What I have tenitively decided to do is use a 7442 bcd decoder as switch decoder and buffer and use 1 pin of the pic as an interrupt input to clear the variables of all my for next counter loops(whichever one is running) if that will work. I am still too inexperienced in programming to know without trying if it will. I figure that's what breadboards are for. So I think my real question is, can a counter loop be decremented faster by code from outside the loop or by an interrupt driven event?

Thank You again,
JS

Melanie
- 17th September 2006, 23:16
Can you expand and give us the bigger picture.

What are you counting, how many counters, how fast is this count?

Are these push-buttons?

Are you timing how fast a button is being pushed?

What are you trying to achieve?

Knowing a few more details would aid in giving advice.