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.

Pic 18f4550 external interrupt problem

Status
Not open for further replies.

hutt123

Newbie level 3
Joined
Jan 19, 2012
Messages
3
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,314
Hi,

I am trying to use pic 18f4550 external interrupt INT0 but when I am trigger it there is no response. Can someone check my code pls ?

#include <p18f4550.h>
#include <portb.h>

#pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB
#pragma config WDT = OFF //Disable watchdog timer


void main (void);
void InterruptHandlerHigh (void);

void main()

{

/************* Configure Ports ***************************************/

ADCON1 = 0x0F; // Set all pins to digital
TRISB = 0b00000011; // Set portb bit zero & one as input
TRISD = 0; // set portd output
PORTB = 0b00000000; // clear port b
PORTD = 0b00000000; // clear port d

/***** Configure external interrupt INT0 *****/

INTCONbits.INT0IF = 0; // CLEAR INT0 Flag
INTCONbits.INT0IE = 1; // Enables the INT0 external interrupt
INTCON2bits.INTEDG0 = 1; // Interrupt on rising edge

INTCON2bits.RBPU = 1; // All PORTB pull-ups are disabled


RCONbits.IPEN = 1; // Enable priority levels on interrupts
INTCONbits.GIE = 1; // Enables all high priority interrupts
INTCONbits.PEIE = 1; // Enables all low priority interrupts

/****************************************************************************/
while(1)
{
if(PORTBbits.RB1 == 1)
{
LATDbits.LATD7 = 1;
}
else
{
LATDbits.LATD7 = 0;
}
}
}

void InterruptHandlerHigh () ;
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
_asm goto InterruptHandlerHigh _endasm
}

#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh ()
{
LATDbits.LATD7 = 1;
if(PORTBbits.RB1 == 1)
{
INTCONbits.INT0F=0; // reset INT0 external interrupt flag
}

}
 

Change your ISR to:
Code:
//void InterruptHandlerHigh () ;
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void){
	_asm goto InterruptHandlerHigh _endasm
}

#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh (){

	if(PORTBbits.RB1 == 1){
		LATDbits.LATD7 = 1;
	}
	INTCONbits.INT0F=0; // reset INT0 external interrupt flag

}

The way you had it set up, interrupt would continue until RB1 is pulled high.

What are you trying to observe? How did you deduce that there is no response?

One problem is, your ISR is doing the same thing that the infinite loop is. It's going to be easier to observe the interrupt if you remove what is being done in the infinite loop.

Hope this helps.
Tahmid.
 
Hi, Tahmid thanks for replying. My scope is to learn how to operate pic18f4550 external interrupt so that I can use it in other applications. In order to test the above code I am using pickit3 of Microchip which enables me to debug each line of the code on the actual prototype circuit being under test. When I am pressing the push button in order to apply 5V on pin 33 of pic18f4550 the debugger does not go in the interrupt routine and i cannot understand why.
 

you are using INT0 and RB1. i think that INT0 is assuciated with RB0, while INT1 should be used with RB1
 
Hi, Tahmid the problem was in the debugging because when I tried it without debugging it worked. Thanks again for your help :)

---------- Post added at 15:50 ---------- Previous post was at 15:46 ----------

Hi yuvko, I was only trying the code in the debugging mode but right know i had tried directly(without debugging) and it worked. Thanks anyway for your help :)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top