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

PIC16F877A ext Interrupt problem

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



Joined: 08 Dec 2011
Posts: 2

View user's profile Send private message

PIC16F877A ext Interrupt problem
PostPosted: Wed Dec 28, 2011 6:27 am     Reply with quote

hi all,
My problem is my main program would not jump to external Interrupt when i press the button switch. I have connected a 5K pull up resistor to RB0 and a button switch which one end to ground and the other to RB0. I m using PCWH ver 3.219. Please help to rectify the problem. Thank you.
Code:
 
  #include <stdio.h>

#use delay(clock=20000000)
#fuses HS,NOWDT   // and set the fuses



#int_EXT   //denote the following function as the ISR for a falling edge on INT0
void ext_isr(void)
{
output_bit(pin_A5,0);
 
}
 
void main()
{
   output_bit(pin_a5,1);

   port_b_pullups(TRUE);  //activate puulups on port B for ext interrupt
   ext_int_edge(0,H_TO_L);  //set external interrupt to falling edge
   enable_interrupts(INT_EXT); // enable each interrupt
   enable_interrupts(global); // allow the PIC to be interrupted

  while(1)     // just sit here.. and let the ISRs do the work
      ;
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Wed Dec 28, 2011 9:03 am     Reply with quote

I have just tidied the code a little, and run it, with your compiler version, and it works fine:
Code:

#include <16F877A.h>
#device adc=16
#FUSES NOWDT, HS, PUT, NOBROWNOUT, NOLVP
#use delay(clock=20000000)

#int_EXT   //denote the following function as the ISR for a falling edge on INT0
void ext_isr(void) {
   output_low(pin_A5);
}

void main(void) {
   setup_comparator(NC_NC_NC_NC);
   setup_spi(FALSE);

   output_high(pin_a5);

   port_b_pullups(TRUE);  //activate pullups on port B for ext interrupt
   ext_int_edge(H_TO_L);  //set external interrupt to falling edge
   clear_interrupt(INT_EXT); //it may have become set during initialisation

   enable_interrupts(INT_EXT); // enable each interrupt
   enable_interrupts(global); // allow the PIC to be interrupted

   while(TRUE)     // just sit here.. and let the ISRs do the work
      delay_cycles(1);
}

Only major tweaks were to clear the interrupt after setting it up, and ensure that the other things on pin A5, were turned off.
Like this, it runs.

Best Wishes
echentj



Joined: 08 Dec 2011
Posts: 2

View user's profile Send private message

16F877A Interrupt problem
PostPosted: Wed Dec 28, 2011 10:20 pm     Reply with quote

Hi Ttelmah,
Thank you for your effort, The code that you game me, it worked perfectly. But when i power down my circuit and power it up again, the LED will blink once only and then it goes off. Mean time i've added some statements to your code, but i still cant get it work. Below is the code that i had changed.
Kindly please comment. Thank you.

Code:
#include <16F877A.h>
#device adc=16
#FUSES NOWDT, HS, PUT, NOBROWNOUT, NOLVP
#use delay(clock=20000000)
byte junk;

#int_EXT   //denote the following function as the ISR for a falling edge on INT0
void ext_isr(void) {
   
   output_low(pin_A5);
   clear_interrupt(INT_EXT);
    junk=input_b();
   
}

void main(void) {
   
   setup_comparator(NC_NC_NC_NC);
   setup_spi(FALSE);

   output_high(pin_a5);

   port_b_pullups(TRUE);  //activate pullups on port B for ext interrupt
   ext_int_edge(H_TO_L);  //set external interrupt to falling edge
   clear_interrupt(INT_EXT); //it may have become set during initialisation

   enable_interrupts(INT_EXT); // enable each interrupt
   junk=input_b();
   enable_interrupts(global); // allow the PIC to be interrupted
   junk=input_b();
   while(TRUE)     // just sit here.. and let the ISRs do the work
      delay_cycles(1);
}
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