Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] pic16f877a external interrupt isr seems to stall the entire program.

Status
Not open for further replies.

pcsandhya82

Member level 3
Joined
Jul 31, 2010
Messages
58
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bangalore
Activity points
1,732
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.

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');
							
        }	
}
 

Please post your schematic diagram..

And it is not advised to use delays in interrupt service routine...

The problem of hanging occurs when your controller is always in interrupt..

Try changing the state of PortB internal pull-ups..
 

Hi Arun,

A
nd it is not advised to use delays in interrupt service routine...

The problem of hanging occurs when your controller is always in interrupt..

Try changing the state of PortB internal pull-ups..

I know it is not advisable to use delays, but using delays should not cause the problem that i stated.
if the controller is always in interrupt, it should at least execute what is written in ISR, I have written that it is not doing so.
PORTB is externally pulled down. Then why should I change the internal pull ups?

I have explained how I wired up the circuit.its nothing much , just a switch and 10k pull down on RB0. and the simulation works, thats why i didnt post the circuit.

Any other insights?

Thanks.

- - - Updated - - -

Hi all,

Actually it does not even simulate!! I m attaching the whole project folder, Proteus 7.1 SP2 and MPLAB 8.60 and HiTech C.

:-(
 

Attachments

  • eint_16f877a.rar
    138.5 KB · Views: 83

Hi all,

Actually it was a compiler issue. My program worked on windows xp machine. May be Hitech C Lite has a problem working with 64bit machines.
Jayanth, Thank you.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top