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
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.
Thanks for the reply If you don't mind can you give one small example program? Because iam new to interrupt concept. In my application iam using external interrupt as a switch. Normally program is in loop1(Infinite loop), when I pressed switch, control should go to loop2. Thanks Regards Nattu
If you don't mind can you give one small example program? I'll try.
#include <REG51.H> bit loopswitch = 0; void ex0_isr (void) interrupt 0 /*external interrupt routine*/ { (do some stuff) loopswitch = 1; } 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(!loopswitch) /* loop1*/ {} while(1) /* loop2 */ {} }
http://www.keil.com/download/list/c51.htm http://www.keil.com/books/8051books.asp http://www.8052.com/books.phtml http://www.8052.com/book
Thank you for the reply Now it is working well. Regards Nattu
Now it is working well. Good. Hopefully, you also learned from the example instead of just copying it.