Hello.
A friend of mine is trying to make a PORTB external interrupt 0, bit 0 to happen, and i helped him , but now he modified my code, and i can't find anything wrong with it, and yet it doesn't work .
I was wondering if anyone can have a look, and point what can be wrong with it.
The code was supposed to enter a interrupt routine and do a small active "0" impulse.
#include <p18f4550.h>
#include <delay.h>
#pragma code REMAPPED_RESET_VECTOR=0x1000 // Car on utilise le Bootloader HID de Microchip
extern void _startup (void);
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
//#pragma config XINST = OFF
//pragma config WDT = OFF //Disable watchdog timer
void InterruptServiceHigh(void);
void InterruptServiceLow(void);
/***************************************************************/
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x1008
void InterruptVectorHigh(void)
{
_asm goto InterruptServiceHigh _endasm
}
#pragma code
/**************************************************************/
// Low priority interrupt vector
#pragma code InterruptVectorLow = 0x1018
void InterruptVectorLow(void)
{
_asm goto InterruptServiceLow _endasm
}
#pragma code
/**************************************************************/
// Interrupt Service Routine
// Interrupt pragma for high priority
#pragma interrupt InterruptServiceHigh
void InterruptServiceHigh(void)
{
if(INTCONbits.INT0IF)
{
PORTBbits.RB7=0;
Delay10TCYx (120);
PORTBbits.RB7=1;
}
INTCONbits.INT0IF=0; // reset INT0 external interrupt flag
INTCONbits.RBIF = 0;
}
#pragma code
/*************************************************************/
#pragma interrupt InterruptServiceLow
void InterruptServiceLow(void){
}
#pragma code
/*************************************************************/
void main(void)
{
/************* Configure Ports ***************************************/
TRISB=0b00000001; // Set portb bit zero & one as input
PORTB = 0;
PORTBbits.RB7=1;
/***** Configure external interrupt INT0 *****/
INTCONbits.INT0IF = 1; // SET 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
INTCONbits.RBIE = 1; //1= Enables the RB port change interrupt
INTCONbits.RBIF = 0; //1 = At least one of the RB7:RB4 pins changed state (must be cleared in software)
INTCON2bits.INTEDG0 = 0; //0 = Interrupt on falling edge
INTCON2bits.RBIP = 1; //RBIP: RB Port Change Interrupt Priority bit 1 = High priority
RCONbits.IPEN = 1; // Enable priority levels on interrupts
INTCONbits.GIE = 1; // Enables all high priority interrupts
INTCONbits.PEIE = 1; // Enables all low priority interrupts
INTCONbits.INT0IF=0; // reset INT0 external interrupt flag
while(1)
{
if(PORTBbits.RB0 == 0) //test button press
{
PORTBbits.RB2 = 1;
}
else PORTBbits.RB2 = 0;
}
}