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

Can an interupt service routines use NON-global variables?

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



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

Can an interupt service routines use NON-global variables?
PostPosted: Mon Dec 20, 2004 12:10 pm     Reply with quote

My questions is, in general, is there a way to pass parameters into/out of the interupt service routines?

or do I always need to use global variables, when the scope needs to be in main().
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 20, 2004 12:19 pm     Reply with quote

Yes, you should use global variables.
The reason is that an isr is "called" by a hardware event.
You don't call it with code, as you do a normal function.
libor



Joined: 14 Dec 2004
Posts: 288
Location: Hungary

View user's profile Send private message

PostPosted: Mon Dec 20, 2004 4:04 pm     Reply with quote

Regarding your question in the subject: You can declare and use local variables in an ISR, you can also use static variables that preserve their values between the interrupts, but these will be out of scope for the code outside if the ISR. For passing parameters into the ISR you have to use global variables, for passing data out of the ISR beside using global variables you can also call a function from the ISR with parameters.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Dec 20, 2004 5:19 pm     Reply with quote

Thanks for the info.

I was trying to find a way pass a pointer to my buffer position
into the ISR. Global vars seem the only way to go, since I need the scope both inside the ISR and in main().
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 20, 2004 6:00 pm     Reply with quote

You can also use a function to return a value. But this will add extra time in the isr.

ptr = getBuffer();
asmallri



Joined: 12 Aug 2004
Posts: 1636
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Dec 20, 2004 9:36 pm     Reply with quote

treitmey wrote:
Thanks for the info.

I was trying to find a way pass a pointer to my buffer position
into the ISR. Global vars seem the only way to go, since I need the scope both inside the ISR and in main().


Generally you want to minimise the amount of time spent in an ISR - global variables are an efficient way to do this.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
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