pcsandhya82
Member level 3
Hi all,
below is the code for external interrupt on RB0 of PIC16F877A controller. the issue is, external interrupt does not seem to be working with other peripherals. when the static void interrupt isr() routine is commented out, whatever is in the main program works. but as soon as the isr is uncommented, the program seems to hang. here is what i tried.
1. toggle RD0 in the main program, toggle RD7 in isr. works.
2.toggle RD0 in the main program, send character via uart in the isr. failed. no toggling, no transmission.
3.send character via uart in the main program, toggle RD0 in the isr. does not work.
4. toggle RD0 in main program, write character to LCD. does not work.
5.write LCD in main prog, toggle RD0 in isr. does not work.
it was necessary to remove the programmer board and power off and power on for the interrupt to work in the first case.only in the first case the isr and main program seemed to work fine together. in all the other cases, when i burn the program and press reset for execution, just nothing will happen. not even the main program runs. so in all the above cases, i commented out the isr routine (but kept the extIntInit function uncommented) and checked, then the main program runs. all these cases simulates fine in proteus. RB0 switch is connected to VCC, RB0 is pulled down externally. 5v is available in RB0 when i press the INT0 switch.LCD is four line, using RB<7:4> and PORTE.
my first guess was that PIC is going into infinite interrupt execution, but then atlest the ISR routine should run. that also does not happen in this case.
So, i am unable to figure out what is the problem here. Any help will be appreciated.
Thanks.
below is the code for external interrupt on RB0 of PIC16F877A controller. the issue is, external interrupt does not seem to be working with other peripherals. when the static void interrupt isr() routine is commented out, whatever is in the main program works. but as soon as the isr is uncommented, the program seems to hang. here is what i tried.
1. toggle RD0 in the main program, toggle RD7 in isr. works.
2.toggle RD0 in the main program, send character via uart in the isr. failed. no toggling, no transmission.
3.send character via uart in the main program, toggle RD0 in the isr. does not work.
4. toggle RD0 in main program, write character to LCD. does not work.
5.write LCD in main prog, toggle RD0 in isr. does not work.
it was necessary to remove the programmer board and power off and power on for the interrupt to work in the first case.only in the first case the isr and main program seemed to work fine together. in all the other cases, when i burn the program and press reset for execution, just nothing will happen. not even the main program runs. so in all the above cases, i commented out the isr routine (but kept the extIntInit function uncommented) and checked, then the main program runs. all these cases simulates fine in proteus. RB0 switch is connected to VCC, RB0 is pulled down externally. 5v is available in RB0 when i press the INT0 switch.LCD is four line, using RB<7:4> and PORTE.
my first guess was that PIC is going into infinite interrupt execution, but then atlest the ISR routine should run. that also does not happen in this case.
So, i am unable to figure out what is the problem here. Any help will be appreciated.
Thanks.
Code:
// after programming, remove pickit3, power off, power on.
//RB0 pulled down, RB0 LED disconnected, sw connected to VCC
//portc floating.
#include<pic.h>
#include"delay.h"
#include"LCD_4b.h"
#define _XTAL_FREQ 4000000
__CONFIG( HS & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT );
void delay1(unsigned int temp) {
unsigned int j,k,i=temp;
for(j=0;j<temp;j++)
for (k=0;k<255;j++);
}
void interrupt isr() {
GIE = 0;
RD0 = 0;
delay1(2000);
RD0 =1;
delay1(2000);
INTF = 0;
GIE = 1;
}
void uart_init(void) {
SPBRG = 25;
TXSTA = 0x24; //CSRC TX9 TXEN SYNC — BRGH TRMT TX9D
RCSTA = 0x90; //SPEN RX9 SREN CREN — FERR OERR RX9D
RCREG = 0x00;
}
void extIntInit() {
GIE =1;
INTF = 0;
INTEDG =1; //Interrupt on RISE/fall ing edge of RB0/INT pin
TRISB0 = 1;
INTE = 1;
}
main() {
LCD_init_4b();
extIntInit();
TRISD = 0x00;
PORTD = 0x00;
while(1){
write_char_4b('I');
}
}