This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Goto

Hi

Can I use GOTO statement in interrupt routine?

Example code is:

#include <REG51.H>

void ex0_isr (void) interrupt 0 /*external interrupt routine*/
{

goto NEXT;

}

void main(void) /* main program*/

{

IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2)
EX0 = 1; // Enable EX0 Interrupt
EA = 1; // Enable Global Interrupt Flag state

While(1) /* loop1*/
{
; ; /* interrupt well occur in this loop */

}


NEXT: while(1) /* loop2 */

{

; ;

}

}




Normally interrupt well occur in one loop after exciting the interrupt service routine

Again it well come to same loop. But my use is interrupt should come in one loop after that it should goto to next loop that's why here iam using GOTO state ment.


Can you give one example?

How to generate a interrupt in one loop and send into other loop.

Thanks

Regards

Nattu

Parents
  • Can I use GOTO statement in interrupt routine?

    No, you cannot. C only allows GOTO within functions, for good reason.

    Even if you could (or tried to construct anything like that in assembly), it would break your program in several horrible ways that are just too awful to think about.

    Interrupts must be exited by using a RETI instruction. A GOTO will not set the '51 interrupt logic the correct state.

    How to generate a interrupt in one loop and send into other loop.

    If that is all you want to do, why are you even bothering with GOTOs ?

    Simply set a global flag in the ISR which will be evaluated by the first while loop.

Reply
  • Can I use GOTO statement in interrupt routine?

    No, you cannot. C only allows GOTO within functions, for good reason.

    Even if you could (or tried to construct anything like that in assembly), it would break your program in several horrible ways that are just too awful to think about.

    Interrupts must be exited by using a RETI instruction. A GOTO will not set the '51 interrupt logic the correct state.

    How to generate a interrupt in one loop and send into other loop.

    If that is all you want to do, why are you even bothering with GOTOs ?

    Simply set a global flag in the ISR which will be evaluated by the first while loop.

Children