View previous topic :: View next topic |
Author |
Message |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
Can an interupt service routines use NON-global variables? |
Posted: Mon Dec 20, 2004 12:10 pm |
|
|
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(). |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 20, 2004 12:19 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
libor
Joined: 14 Dec 2004 Posts: 288 Location: Hungary
|
|
Posted: Mon Dec 20, 2004 4:04 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Dec 20, 2004 5:19 pm |
|
|
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(). |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Dec 20, 2004 6:00 pm |
|
|
You can also use a function to return a value. But this will add extra time in the isr.
ptr = getBuffer(); |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Dec 20, 2004 9:36 pm |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
|