hi all..
am using msp430f2618 controller and am getting error if i tried to use goto statement in my port change interrupt subroutine and i placed the label name in my main loop ..how to rectify this error??
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
hi all..
am using msp430f2618 controller and am getting error if i tried to use goto statement in my port change interrupt subroutine and i placed the label name in my main loop ..how to rectify this error??
Hi,
goto is not recommended in C programming (with exception on certain specific cases). My guess is that because you are using goto, the RETI instruction which should be executed at the end of your ISR is never reached, and somehow the memory stack content is messed up. You basically can call functions inside your ISR; but don't use goto.
The goto statement is exclusively for jumpt to a local target label. You cannot (and must not!) jump from one function to another (this would totally mess-up the stack!). That's how goto is defined.
If you get an error on your use of goto, then you're trying to do something you really, really shouldn't do if you ever want to get a working program.
I guess you're trying to control the program flow based on interrupts. The one and only situation where this can (and must) be done is when you're writing a thread scheduler for a multitasking OS, that handles different threads and different stacks.
In every other case, the ISR should set a global flag (a global volatile variable) and the main code just checks it and acts accordingly. Something like this:
main:
while(1) {
enter LPM (CPU stops here until an ISR wakes it up agian because something happened)
switch (flag)
case 1: do what has to be done in case 1
case 2: or do what has to be done in case 2
...
flag = 0
}
ISR:
flag=x
exit LPM
**Attention** This is a public forum