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 on change PORTA for PIC16F687

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







Interrupt on change PORTA for PIC16F687
PostPosted: Mon Mar 19, 2007 3:43 pm     Reply with quote

Hi I'm having a problem of getting an interrupt on change for PORTA (specifically pin RA4) to work. I tried to follow the example from CCS manual but that still didn't work.

I sincerely appreciate any help.

My code is as following

Code:

unsigned int8 last_a;
unsigned int8 port_a;

#int_RA
void RA_isr()
{
   unsigned int8 changes;

   port_a = input_a();
   changes = last_a ^ port_a;
   last_a = port_a;
   if (bit_test(changes,4)&& !bit_test(last_a,4))
   {
      //b4 went low
      SleepMode = 0;
   }

   delay_ms (100); //debounce

   //PIC_INTCON &= ~PIC_INTCON_RABIF;
   //clear_interrupt(INT_RA);
}

void main()
{
   /* Input-Output for Each Port */
   set_tris_a( 0x10 );
   set_tris_b( 0xFF );
   set_tris_c( 0x00 );

   /* Enable Interrupt on PIN_A4 and PIN_B7 */
   PIC_IOCA    = 0x10; 
   //PIC_INTCON |= PIC_INTCON_RABIE;

   enable_interrupts(INT_RA);
   enable_interrupts(GLOBAL);

   SleepMode = 1;
   port_a = 0;
   last_a  = 0;

   setup_oscillator(OSC_8MHZ);

   /* port C is for LED stuffs */
   #use fast_io (C)
   output_bit(LED0,0);
   output_bit(LED1,0);
   output_bit(LED2,0);
   output_bit(LED3,0);

   while(1)
   {
      if(SleepMode) {
         output_bit(LED2, 0);
         delay_ms(300);
         output_bit(LED2, 1);
         delay_ms(300);

         //sleep();
      } else {
         output_bit(LED0, 0);
         delay_ms(300);
         output_bit(LED0, 1);
         delay_ms(300);
      }
   }
}


It seems like when apply L->H for pin RA4 (using a switch), I see that the blinking pattern from LED2 stops, but I don't see the blinking pattern from LED0. But when I have it from H->L (flip the switch the other side) I see that the LED2 blinks again, which puzzled me because it looks as though the interrupt routine got stuck but never got out and the SleepMode never get set back to 0 (Laughing Question Question Question , not too sure though)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 19, 2007 8:54 pm     Reply with quote

Quote:

enable_interrupts(INT_RA);
enable_interrupts(GLOBAL);

SleepMode = 1;
port_a = 0;
last_a = 0;

I didn't look at your code in detail, but there are some problems
with the code above. You're enabling interrupts before you initialize
all your global isr flags and variables. You need to init your globals
first, and then enable interrupts. Also, you should use the CCS
clear_interrupt() function to clear INT_RA before you enable global
global interrupts. That way, if the INT_RA flag happened to be set
ahead of time, you won't get a spurious interrupt. You should also
read PortA to clear any "change condition" that may be set, before
you do any of the above.
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