Question:
Question about switch-case statements!?
English Man
2015-10-14 09:33:01 UTC
I am writing a C program for a microcontroller.

In this program I have 4-case statements, with each case having a function corresponding to each different case. Each respective function keeps on looping until the user changes the switched option.

An external button used to change the switched option interrupts the program to service an Interrupt Service Routine.

Now since the interrupt service routine is changing the option, I want that when the program returns from the ISR, instead of continuing the function that it was doing, it jumps out of the case statement and goes to the new function required according to the new case.

How can I do this please?
Three answers:
?
2015-10-14 09:54:13 UTC
I don't know if this is the best way to do it, but you could have the interrupt routine set a global or class-level variable that you could then check. Instead of while(true) you could have while (!isInterrupted). The function would then return, and you'd have another loop in the main function that would make it check the case statements again and set isInterrupted back to false.
?
2015-10-14 10:22:52 UTC
volatile int state;

going=1;

while(going){

switch(state){

case 1:

...



break;

case 2:

...

break;



case 10:

going =0;

break;

}

}
?
2015-10-14 11:22:23 UTC
C++ programming language.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...