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

Variables in interrupt procedure

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







Variables in interrupt procedure
PostPosted: Tue Feb 20, 2007 12:31 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 12:39 am     Reply with quote

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








PostPosted: Tue Feb 20, 2007 12:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 1:11 am     Reply with quote

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







PostPosted: Tue Feb 20, 2007 1:17 am     Reply with quote

to PCM programmer: thanks!!
i'll be read!
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