PIC C18 External Interrupts INT0

Status
Not open for further replies.

natraj20

Member level 3
Joined
Oct 28, 2010
Messages
65
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Florida
Activity points
1,769
Hello guys,

Problem with the very basics.
I am stuck with the external interrupt INT0 at RB0.
Controller - PIC 18F47J53
MPLAB IDE, Microchip C Compiler

I could not figure out what is wrong with the following code. Kindly help me out to make this work!!

#include <p18f47j53.h>
#include <delays.h>
#include <portb.h>

#pragma config OSC = HS
#pragma config WDTEN = OFF
#pragma config XINST = OFF

void InterruptServiceHigh(void);
void InterruptServiceLow(void);

int x;

void main(void)
{

INTCONbits.INT0IF = 0;
INTCONbits.INT0IE = 1;
INTCON2bits.INTEDG0 = 1;

INTCON2bits.RBPU = 0;
//EnablePullups();

TRISE = 0;
TRISBbits.TRISB0 = 1;

RCONbits.IPEN = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;

while(1)
{
PORTE = 0x01;
}

}


// High priority interrupt vector

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


// Low priority interrupt vector

#pragma code InterruptVectorLow = 0x18
void InterruptVectorLow(void)
{
_asm
goto InterruptServiceLow
_endasm
}



// Interrupt Service Routine

// Interrupt pragma for high priority

#pragma code
#pragma interrupt InterruptServiceHigh
void InterruptServiceHigh()
{
// function statements

if(INTCONbits.INT0IF)
{
x = 0;

while(x <= 2)
{
PORTE = 0x01;

Delay10KTCYx(120); // Delay of 1 sec with 12 MHz

PORTE = 0x02;

Delay10KTCYx(120);

x++;
}
INTCONbits.INT0IF = 0;
}

// return from high priority interrupt

}


// Interrupt pragma for low priority

#pragma code
#pragma interrupt InterruptServiceLow
void InterruptServiceLow()
{
// function statements

// return from low priority interrupt

}
 

You have to set RB0/AN12/C3IND/INT0/RP3 as a digital port, such like:
Code:
ANCON1bits.PCFG12 = 1; // set RB0/AN12/C3IND/INT0/RP3 as a digital port
 
Thanks a lot Yager!!
It worked perfect with setting the pin as a digital one!
In the same controller, i tried to use an additional external interrupt RB2. It has not been explicitly given as an external interrupt INT2 but as a reprogrammable pin.
RB2/AN8/C2INC/CTED1/PMA3/VMO/REFO/RP5
I do not know what the flags INT2IF, INT2IE, INTEDG2 and INT2IP are associated with in this controller. Let me know how to trigger an interrupt at the RB2 pin.
Thanks again for taking time to help me out!
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…