CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

question in interrupts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
maxD



Joined: 16 Dec 2013
Posts: 22

View user's profile Send private message

question in interrupts
PostPosted: Sun Dec 29, 2013 5:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 29, 2013 6:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Dec 29, 2013 7:08 am     Reply with quote

thanks
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Dec 29, 2013 11:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 30, 2013 1:23 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group