View previous topic :: View next topic |
Author |
Message |
Vic481 Guest
|
Variables in interrupt procedure |
Posted: Tue Feb 20, 2007 12:31 am |
|
|
Hi,everybody!
I'm a newbie in Picc (before i worked with 8051&z80). And which is the best way to solve THIS problem:
Code: | #int_TIMER2
TIMER2_isr()
{
int i;
if(i==0) {output_high(PIN_A0);i=1;} else {output_low(PIN_A0);i=0;}
output_high(PIN_A0);
}
#int_TIMER0
TIMER0_isr()
{
int i;
int16 j;
if(i<29>=current_temp) i=0;}
} |
I mean when this procedures's execution, their local variables not stored in some kind of stack( i know, it's absent in pic16) and change after other procedure execution. If i declare all variables as global, there's no problem. it's the only way out,or i messed something? Tnx. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 20, 2007 12:39 am |
|
|
Notice that this line is messed up ?
Quote: | if(i<29>=current_temp) i=0;} |
That's because HTML was enabled when you posted your code.
Please post your code again (in this same thread), but this time disable
HTML before you press the Submit button. There is a tickbox just below
the posting window to do this. It looks like this:
Quote: | x Disable HTML in this post |
|
|
|
Guest
|
|
Posted: Tue Feb 20, 2007 12:44 am |
|
|
Sorry :-(
Code: | #int_TIMER2
TIMER2_isr()
{
int i;
if(i==0) {output_high(PIN_A0);k=i;} else {output_low(PIN_A0);i=0;}
output_high(PIN_A0);
}
#int_TIMER0
TIMER0_isr() // 1ms
{
int i;
int16 j;
if(i<=29) {output_high(PIN_A1);j=0;i++;} else
{output_low(PIN_A1);
if (j++>=current_temp) i=0;}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 20, 2007 1:11 am |
|
|
If you want local variables inside a function to retain their value,
then declare them as static.
Example:
Code: | int8 func1(void)
{
static int8 value = 0;
value++;
return(value);
} |
You need to get a book on C. It will have all the basic items
about the language in it, such as static variables. Or, look at
some online C tutorials. Use Google to find them. |
|
|
Vic Guest
|
|
Posted: Tue Feb 20, 2007 1:17 am |
|
|
to PCM programmer: thanks!!
i'll be read! |
|
|
|