|
|
View previous topic :: View next topic |
Author |
Message |
echentj
Joined: 08 Dec 2011 Posts: 2
|
PIC16F877A ext Interrupt problem |
Posted: Wed Dec 28, 2011 6:27 am |
|
|
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: 19551
|
|
Posted: Wed Dec 28, 2011 9:03 am |
|
|
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
|
16F877A Interrupt problem |
Posted: Wed Dec 28, 2011 10:20 pm |
|
|
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);
} |
|
|
|
|
|
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
|