How to Interface External Interrupts with dsPIC Friendly

Interfacing External Interrupt with dsPIC30F4011

Tags: Interfacing External Interrupts with dsPIC30F4011 friendly, Circuit Diagram to Interface ExtInterrupt with dsPIC friendly, C Program to interface ExtInterrupt with dsPIC30F4011 friendly,
Overall rating
DsPIC30F4011 Evaluation Board

The dsPIC30F4011 Evaluation board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through USB port.

Microchip’s dsPIC30F (dsPIC30F4011), Evaluation Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 16-bit Microcontrollers.

External Interrupts

An interrupt caused by an external source such as the computer operator, external sensor or monitoring device, or another computer. Interrupts are special events that require immediate attention.

Interfacing External Interrupts

Fig. 1 shows how to interface the External Interrupt to microcontroller. Interrupts cause the processor to cease the running task to serve a special task for which the interrupt event had occurred. After the special task is over, the processor resumes performing the original task.

The processor can also serve these events by polling method. But polling is an inefficient technique as compared to interrupts. In the polling method, the processor has to continuously wait for the event signal. Thus it always remains busy using extra resources.


Fig. 1 Interfacing External Interrupts to Microcontroller

Interfacing External Interrupts with dsPIC30F4011

We now want to display some messages in PC when occur an external interrupt signal in dsPIC30F4011 Evaluation Board. The Interrupt signal is occurred by using switches. When the switch is pressed to LOW, then the external interrupt is occurred.

The Vectored Interrupt Controller (VIC) takes 32 interrupt request inputs and programmable assigns them into 3 categories, FIQ, vectored IRQ, and non-vectored IRQ.

The dsPIC30F4011 Evaluation board has two numbers of External Interrupts, connected with I/O Port lines (PORTE.8, PORTD.0 & PORTD.1) as switches.

Pin Assignment with dsPIC30F4011



dsPIC Lines


Tactile Switch






SW2 – (INT0)



SW3 – (INT2)



SW4 – (INT1)



Circuit Diagram to Interface Ext-Interrupt with dsPIC

Source Code

The Interfacing External Interrupt with dsPIC program is very simple and straight forward, that accessed by using switches. When the two external interrupts occurring, some messages are displayed in PC through serial port at 9600 baud rate. The C program is written in Mplab software & compiled the code by using Microchip C30 Compiler.

C Program to interface Ext-Interrupt with dsPIC30F4011



#include "p30f4011.h"







#define XTFREQ     20000000

#define FOSC       XTFREQ/4

#define BAUDRATE   9600

#define BRGVAL     ((FOSC/BAUDRATE)/16)-1


#define INT0   IFS0bits.INT0IF

#define INT1   IFS1bits.INT1IF

#define INT2   IFS1bits.INT2IF


void Interrupt_init(void);

void DelayMs(unsigned int);


int main()




   ADPCFG = 0xffff;

   TRISB = 0x0000;














   return 0;



void Interrupt_init(void)


   INTCON1 = 0x0000;

   INTCON2 = 0x0000;  


   IFS0   = 0x0000;

   IFS1   = 0x0000;


   IEC0   = 0x0001;

   IEC1   = 0x0081;

   IPC0   = 0x0007;

   IPC4   = 0x0006;

   IPC5   = 0x5000;



void _ISR _INT0Interrupt(void)



   INT0 = 0;    


   LATBbits.LATB3 ^=1;



void _ISR _INT1Interrupt(void)



   INT1 = 0;    


   LATBbits.LATB4 ^=1;







void _ISR _INT2Interrupt(void)





   INT2 = 0;    

   LATBbits.LATB5 ^=1;



void DelayMs(unsigned int Ms)


   unsigned int delay_cnst;





     for(delay_cnst = 0;delay_cnst <276;delay_cnst++);





To compile the above C code you need the Mplab software & Microchip C30 Compiler. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without dsPIC30F4011 Evaluation Board.

The PICKIT2 software is used to download the hex file into your microcontroller IC dsPIC30F4011 through USB.

Testing the External Interrupts with dsPIC30F4011

Give +9V power supply to dsPIC30F4011 Evaluation Board; the serial cable is connected between the dsPIC30F4011 Evaluation Board and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show which external interrupt is selected.

When you pressed the external interrupt key, the screen should update which interrupt is now pressed. The Interrupts are controlled by using switches. If any data is not coming in Hyper Terminal, then you just check the serial cable is working or not. Otherwise you just check the code with debugging mode in Mplab. If you want to see more details about debugging just see the videos in below link

  • How to Create & Debug a Project in Mplab using dsPIC30F.

General Information

Join the World's Largest Technical Community

we respect your privacy.