dsPIC Programming Workshop


This workshop on dsPIC programming took place in room KEG-009 (DIT Kevin St) from 2-4pm on Wednesday 1-8-2012. Thanks to all those who participated. Here’s what we covered:

  1. We found out what software you need to install to get started with dsPIC programming (MPLAB X, XC16 C compiler, PICkit2). Links and further details are provided below.
  2. Everyone built a really simple dsPIC circuit on a breadboard.
  3. We compiled an example C program (shown below), downloaded the resulting hex file onto the dsPIC and then powered it up. It flashed an LED connected to one of the the digital outputs.

We didn’t really get into any detailed discussion about the features of the dsPIC today. However, for a 2-hour workshop I think we did pretty well to get the software installed on everyone’s laptop and try out a simple example. The dsPIC30F4011 is a great little microcontroller with tons of useful applications, so in subsequent workshops I plan to get stuck into some more interesting examples, building on what we did today.

dsPIC Development Software

I use the following software packages (all available for free from http://www.microchip.com/) for dsPIC programming:

  1. MPLAB X IDE v1.30 (301 MB)
  2. MPLAB XC16 Compiler v1.00 (98 MB)
  3. The PICkit2 application (version 2.61 or later)

I recommend installing them in that order. It probably doesn’t matter for the last one, but based on what I observed today, I certainly recommend completing the MPLAB X installation before beginning installation of the XC16 compiler.


In order to really get to grips with dsPIC programming, you need to get used to reading the documentation. It can be a bit intimidating at first, but just get stuck in there!

Also, worth a look are the documentation for the XC16 compiler and dsPIC Language Tools Libraries:

dsPIC Circuit

Here’s the basic dsPIC30F4011 circuit:

A simple C program

Here’s just about the simplest C program I could come up with for the dsPIC30F4011. I’ll update this slightly once I have a better handle on the code conventions of the new XC16 compiler. The version below gives a couple of warnings relating to the function __delay32, but it does compile successfully.

// This dsPIC30F4011 example program flashes an LED on RD0.
// Written by Ted Burke - last updated 20-8-2012

#include <xc.h>
#include <libpic30.h>

// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, Fcy=30MHz
_FWDT(WDT_OFF);                  // Watchdog timer off
_FBORPOR(MCLR_DIS);              // Disable reset pin

int main()
	// Configure all four port D pins (RD0, RD1, RD2, RD3)
	// as digital outputs
	TRISD = 0b1111111111110000;

	// Flash an LED on RD0 indefinitely at 1Hz
		_LATD0 = 0;          // LED off
		__delay32(15000000); // 500ms delay
		_LATD0 = 1;          // LED on
		__delay32(15000000); // 500ms delay

	return 0;

Further reading

One good place to look next is at my dsPIC30F4011 Super Example which sets up a lot more features on the chip so that you can try out PWM, serial communication, etc. I may need to update it slightly now that MPLAB X and XC16 are out, but I’ll do that soon. In the meantime, here’s the link:


Also, the blog for my final-year DT009 robotics module (Robotics 3.1) contains lots of dsPIC exmaples:


This entry was posted in PIC and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s