Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can I use GOTO statement in interrupt routine?

Status
Not open for further replies.

narithota

Full Member level 1
Joined
Apr 21, 2006
Messages
95
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
2,077
Hi

Can I use GOTO statement in interrupt routine?

Example code is:

#include <REG51.H>

void ex0_isr (void) interrupt 0
{

goto NEXT;

}

void main(void)

{

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)
{
; ; /* interrupt well occur in this loop after that it should goto to next loop */

}


NEXT while(1)

{

; ;

}

}




Normally interrupt well occur in one loop after excuting 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.

My compiler is showing fallowing error:


INTEREX1CODE.C (14): error C233: 'NEXT': undefined label

Thanks

Regards
Nari
 

Re: Interrupt

Hi Nari,

try putting a colon after the NEXT label
Code:
NEXT while(1)      // <--- Here the colon ':' after next is missing

{ 

; ; 

}

tha code should look like this
Code:
NEXT: while(1) 

{ 

; ; 

}

i am not sure but i think there is no problem to use goto in an ISR but after all using goto is not good at all.
thank you,
shereef
 

Interrupt

Salam,

No you can't use GOTO instruction to jump to area outside interrupt ISR. because the interrupt will be active forever will not return to ISR for proper ending (for example pop the saved registers from stack which stored them before handle your ISR)

Instead you can call function inside ISR to do certain job and return to ISR.

NOTE: Your ISR must be small and fast as possible as you can.

Bye
 

Re: Interrupt

sphinx is absolutely right in this ....

because the interrupt will be active forever will not return to ISR for proper ending (for example pop the saved registers from stack which stored them before handle your ISR)

after all use interrupts to set only configurations to tell your main SW that the event has occurred

Instead you can call function inside ISR to do certain job and return to ISR.
calling functions inside ISRs is not good at all SPECIALLY like the functionality that you have here which is a while(1) loop, ISRs should have very small execution time, for every instruction that you put in an ISR you should justify well that it doesn't fit anywhere else in the program except in the ISR.

Thank you,
shereef

PS. Sphinx you didn't send the data for the jtag emulator :)
3ala el-3emoom shokran ya 3am 3ala el-gad3ana :!:
 

Re: Interrupt

you can also set a flag inside the ISR and then check for it in the main loop

Fire in the Wire :idea:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top