problem with interrupt and goto command

General discussion on mikroC.
Post Reply
Author
Message
Teeravisit
Posts: 3
Joined: 21 Mar 2012 11:21

problem with interrupt and goto command

#1 Post by Teeravisit » 21 Mar 2012 11:56

I have a problem with interrupt. I try to stop blink LED connected at port D by using external interrupt (RB0).
My code is shown below. After "Build" I got an error "_interrupt_stop:label not found"
Please help to explain what is wrong?

void interrupt(void)
{
if(intcon.intf == 1){ goto stop;intcon.intf = 0;}
}

void main()
{
anselh.f4=0; //rb0 intrrupt
trisb.f0=1;
intcon=0b10010000;
trisd=0x00;
trisc.f1=1;

portd=0xaa;
while(1);
stop: portd=0xff;

}

veljovic
Posts: 10
Joined: 11 Mar 2012 02:59

Re: problem with interrupt and goto command

#2 Post by veljovic » 21 Mar 2012 22:28

Hello,

in one project I have same problem. simple code but not work.
I think that is problem in software (sometimes).

best regards,
ivan

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: problem with interrupt and goto command

#3 Post by janko.kaljevic » 22 Mar 2012 10:17

Hello,

Labels have function scope. So if all you need to do is to declare your statement in the same function where you use goto statement.
Please check Help file for details.

Best regards.

Teeravisit
Posts: 3
Joined: 21 Mar 2012 11:21

Re: problem with interrupt and goto command

#4 Post by Teeravisit » 22 Mar 2012 11:50

Thank you for your suggestion. But I'm not clear. It means I cannot use "goto" command out of the interrupt loop in this case, ain't it.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: problem with interrupt and goto command

#5 Post by janko.kaljevic » 23 Mar 2012 11:10

Hello,

This was implemented because of limitations that some architectures have.

Also we always recommend our users not to use goto labels since the same can be accomplished without them.
Please try to use exit for breaking from interrupts or just invoke your function.

Best regards.

Post Reply

Return to “mikroC General”