View previous topic :: View next topic |
Author |
Message |
maxD
Joined: 16 Dec 2013 Posts: 22
|
question in interrupts |
Posted: Sun Dec 29, 2013 5:22 am |
|
|
following code is for led blinking
when i press push button led on and blinks till i press it again(then it will off)
Code: |
#include<18f2550.h>
#fuses NOWDT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
//#use rs232(baud=9600,UART1,ERRORS, parity=N,bits=8)
BYTE blink=0;
#INT_EXT
void led()
{
if(!input(PIN_B0)&&!blink)
{
blink=1;
}
else if(!input(PIN_B0)&&blink)
{
blink=0;
}
else
{}
}
#use delay(clock=20000000)
void main()
{
int i=0;
enable_interrupts(INT_EXT_H2L);
enable_interrupts(GLOBAL);
do{
if(blink)
{
output_high(PIN_B1);
output_low(PIN_B1);
}
}while(TRUE);
} |
problem is i want to know after isr finished working what will be the next line the pic begin to execute
is it start from do
or from void main()?
thanks!!!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Dec 29, 2013 6:21 am |
|
|
probably neither
The PIC will execute the next instruction that follows the one WHEN the interrupt occurred.
Let's say your program has 12 lines of code and the interrupt occurred during the 7th line.The PIC fishes that line,then does the ISR, then returns to the 8th line and carries on.
This is the usual way it's done. A programmer can alter this if course if he so desires but NOT recommended for the novice programmer.
hth
jay |
|
|
maxD
Joined: 16 Dec 2013 Posts: 22
|
|
Posted: Sun Dec 29, 2013 7:08 am |
|
|
thanks |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Dec 29, 2013 11:52 pm |
|
|
temtronic wrote: | probably neither
The PIC will execute the next instruction that follows the one WHEN the interrupt occurred.
Let's say your program has 12 lines of code and the interrupt occurred during the 7th line.The PIC fishes that line,then does the ISR, then returns to the 8th line and carries on.
This is the usual way it's done. A programmer can alter this if course if he so desires but NOT recommended for the novice programmer.
|
wait wait...
A "line" of C code may compile to multiple instructions.
Let the OP understand that a line that simple states X += 2 can be interrupted somewhere in that line because it consists of multiple instructions.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Mon Dec 30, 2013 1:23 am |
|
|
Yes. An important distinction, especially if things like printf are involved. This is whey you get so many posts about values being corrupted, where a value is updated in an interrupt....
Best Wishes |
|
|
|