This will be laughably easy for someone who has worked with the dsPIC33 and XC16 compiler, but has already cost me a day. Hopefully someone can save me any more wasted time!

Could someone please tell me what I have done wrong here? All I am trying to do is shut off some LED's using an external interrupt.

/* Device header files */
#include <stdlib.h>
#include <xc.h>

int main(int argc, char** argv) {

// setup internal clock for 80MHz/40MIPS
// 7.37/2=3.685*43=158.455/2=79.2275
CLKDIVbits.PLLPRE=0;        // PLLPRE (N2) 0=/2
PLLFBD=41;                  // pll multiplier (M) = +2
CLKDIVbits.PLLPOST=0;       // PLLPOST (N1) 0=/2

ANSELE = 0x0000; //set all of port B as Digital
TRISE=0xF0;//configures part of port B as output
LATE=0x0F; // writes data to port B

RPINR0= 0x5400;//set pin 1 as interrupt 1
INTCON2 = 0x0000;   /*Setup INT0, INT1, INT2, interupt on falling edge*/
IFS1bits.INT1IF = 0;    /*Reset INT1 interrupt flag */
IEC1bits.INT1IE = 1;    /*Enable INT1 Interrupt Service Routine */
IPC5bits.INT1IP = 4;    /*set low priority*/

//Main Program
while (1);
return (EXIT_SUCCESS);

//_INT1Interrupt() is the INT1 interrupt service routine (ISR).
void __attribute__((__interrupt__)) _INT1Interrupt(void);
void __attribute__((__interrupt__, auto_psv)) _INT1Interrupt(void)
   LATE=0x00; // writes data to port B
   IFS1bits.INT1IF = 0;    //Clear the INT1 interrupt flag or else
   //the CPU will keep vectoring back to the ISR

Thanks in advance!!!

  • \$\begingroup\$ Please give us some more info about your problem/errors \$\endgroup\$ Commented Dec 15, 2013 at 8:48
  • \$\begingroup\$ It compiles fine, loads onto the MCU but it does not detect the interrupt when I bring 0x54 high. \$\endgroup\$ Commented Dec 15, 2013 at 16:38

1 Answer 1


I see three missing things.

Missing dspic33 number??

AD1PCFGL = 0xFF, or whatever the datasheet tells you, to turn off the adc on those pins, if necessary. ANSEL is for choosing adc input, not turning them into digital.

Input pins TRISXbits.TRISX? = 1, to turn your pin into an input.

  • \$\begingroup\$ Thanks for the reply Erik! Ill give that a shot after work. \$\endgroup\$ Commented Dec 16, 2013 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.