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 support@ccsinfo.com

Interrupt and variable trouble

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



Joined: 25 Nov 2009
Posts: 2

View user's profile Send private message

Interrupt and variable trouble
PostPosted: Wed Nov 25, 2009 3:17 pm     Reply with quote

I have problems with interrupts. In the handler, the variable is changed but not saved in the future if I use sleep in MAIN () examples.
Code:

volatile int nRepeatCounter ;                         
int* pnRepeatCounter = &nRepeatCounter;     

void main()
{

   init();                                                                               
   enable_interrupts(INT_RB);
   *pnRepeatCounter = 4;                         
   sleep();

}   

#INT_RB
void buttons()
{
   disable_interrupts(INT_RB);

   if(!input(DOWN_BUTTON))
   {
      if(*pnRepeatCounter == 0) *pnRepeatCounter= 100;   
       (*pnRepeatCounter)--;       
   }
}

nRepeatCounter will already 3! if write volatile int nRepeatCounter = 4 and coment it in main likewise.
If I comment sleep() it normal work. How true save values interrupt from handler? I can't use normal other func without it.
sorry for my bad english.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 25, 2009 3:21 pm     Reply with quote

Always post your PIC and compiler version.
Ttelmah
Guest







PostPosted: Wed Nov 25, 2009 3:30 pm     Reply with quote

There are a whole suite of problems with what is posted though...

First, there is no while...true in the main, so the code will fall off the end.
Second, port B is not read in the interrupt handler, so if it wasn't for disabling the interrupt, it'd be called for ever.
Third, Port B is not read in the main, so the handler _will_ almost certainly be called as soon as the interrupt is enabled.

I think if these were fixed, the problem would actually disapear, though it is not clear what the 'problem' really is...

Best Wishes
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Nov 26, 2009 3:20 am     Reply with quote

To follow on from Ttelmah

init is not defined.
There are no fuse definitions. (Is the WDT enabled ?)
DOWN_BUTTON is not defined.
Not sure if the settings you are using allow wakeup from an interrupt.
Why are you using a pointer to the variable ?
How are you monitoring the value ?
Slimy



Joined: 25 Nov 2009
Posts: 2

View user's profile Send private message

PostPosted: Thu Nov 26, 2009 4:20 am     Reply with quote

This is not all code of course all defined. Think problem
will be fix like this
Code:

 while(1)
{
  sleep;
}

but not sure Smile.
I have next problem. I have a structure
Code:

typedef  struct {

         long  button : 2;       // 2 bit button 
         long  codeLow : 6;     // 10 bit code   
         long  codeHigh : 3 ;    //
         long  reverce : 1 ;               
         long  trueButton : 1; 
         long  trueCode : 1 ;                   
         long  occupy : 1 ;         
                                                                         
   }frame_struct;
   
frame_struct frame;   

Need to convert it in long type where minor bit is button and major occupy. How do it?
I try like this
Code:

long frameToLong()
{
   return (frame.codeHigh << 9) | (frame.codeLow << 2) | frame.button;
}

but not sure thats its best way and it will true work.
Who knows what will happen if one of the fields will increase in the cycle of overflow? Will the transfer of the senior field, or simply start with 0
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