hutt123
Newbie level 3
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
}
}
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
}
}