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

Problem updating variable in ISR

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



Joined: 12 Sep 2009
Posts: 19

View user's profile Send private message

Problem updating variable in ISR
PostPosted: Fri May 03, 2013 11:33 am     Reply with quote

I am not an experienced C programmer and I am trying to get some code to decrement a variable every time the ISR is run. The first routine below works, so I know the ISR is working, but the second routine doesn't seem to do anything. It should be decrementing my LED display that is connected to port_C. It might just be that I still don't quite get global variables (along with other things). Any help would be appreciated!

Code:
#include <main.h>
#int_EXT

//int x=255;

void  EXT_isr(void)
{
   Output_C(255);
//   x--;
   delay_ms(1000);

}



void main()
{
   int x;
   
   setup_lcd(LCD_DISABLED);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   ext_int_edge(H_to_L);
   setup_oscillator(OSC_8MHZ);

   while(TRUE)
   {
      output_C(x);
      x++;
      delay_ms(100);
   }

}


2nd code:

Code:
#include <main.h>
#int_EXT

int x=255;

void  EXT_isr(void)
{
//   Output_C(255);
   x--;
   delay_ms(1000);

}



void main()
{
   int x;
   
   setup_lcd(LCD_DISABLED);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   ext_int_edge(H_to_L);
   setup_oscillator(OSC_8MHZ);

   while(TRUE)
   {
      output_C(x);
//      x++;
      delay_ms(100);
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 03, 2013 11:55 am     Reply with quote

Quote:
#include <main.h>
#int_EXT

int x=255;

void EXT_isr(void)
{
// Output_C(255);
x--;
delay_ms(1000);

}

The #int_xxx directive must be placed just above the interrupt routine.
See this post::
http://www.ccsinfo.com/forum/viewtopic.php?t=46477&start=4
ccowley



Joined: 12 Sep 2009
Posts: 19

View user's profile Send private message

Thank you! That worked!
PostPosted: Fri May 03, 2013 1:35 pm     Reply with quote

Thanks for the help! That worked perfectly. I also had to get rid of the "int x;" that was in MAIN, but that was just a holdover from the previous program I forgot to change before I posted.

Thanks again!
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