Recommended software to install on your own laptop

I have spoken to several participants in this year’s RoboSumo who have installed PIC development software on their own laptops. This is an excellent idea and a reliable indicator that a person is beginning to really engage with the PIC programming element of the module. However, there is some confusion about exactly which software to install and in which versions, so I thought I’d write a post to clarify what I recommend. Others may suggest alternative development software, but this is what I use myself. The instructions provided here assume that you are running Windows. XC8 is also available for Linux and Mac OS, but these instructions are Windows specific.

Software to install: Text editor, C compiler, PICkit 2

If you want the simple version, this is it! Download and install the following (all free of charge):

  1. Download and install the Notepad++ text editor
  2. Download and install the XC8 C compiler from (165 MB approx). Accept all the default options and when you are prompted for an “Activation Key” just leave it blank. You will be running the compiler in “Free mode”.
  3. Download and install the PICkit 2 software application.

Explanation of each piece of software

  • Notepad++ is a plain text editor (similar to the Notepad program that comes with Windows, but with many extremely useful extra features). You’ll use this to type in the C code for your program (see example below), which you’ll save as a file called “main.c”.
  • XC8 is a C compiler. Basically it translates your C program (“main.c”) in a binary machine code file, called something like “main.hex”.
  • The PICkit 2 software is used to transfer the hex file (“main.hex”) to the flash memory of the PIC microcontroller (via the PICkit 2 hardware device – i.e. the USB programmer).

How to program the PIC with this software

The good news is that creating and building a new program using this software is easy peasy, especially compared to setting up a new project in MPLAB.

Firstly, create a directory for your program. For this example, I’m calling my folder “D:\RoboSumo\LED\”.

Type in your C program in Notepad++ and save it as “main.c” in that folder – i.e. “D:\RoboSumo\LED\main.c”. Here’s a really simple example C program for the PIC18F4620:

// PIC18F4620 example program
// Written by Ted Burke (
// Last update 28-2-2013

#include <xc.h>


int main(void)
	// Make RD0 a digital output
	TRISD = 0b11111110;
		LATDbits.LATD0 = 1; // Set pin RD0 high
		_delay(125000);     // 0.5 second delay
		LATDbits.LATD0 = 0; // Set pin RD0 low
		_delay(125000);     // 0.5 second delay

Copy the following build script (actually just a single command) into another new file in Notepad++ and save it as “build.bat” in the same folder – i.e. “D:\RoboSumo\LED\build.bat”

xc8 --chip=18F4620 main.c

At this point, your folder should contain two files:

Screenshot of PIC program folder

Open a command window and move to the directory where your program is stored, then type “build.bat” to run the build script. It will run the C compiler for you and (assuming there are no errors in your program) produce a file called “main.hex”. Here’s how it looks in the command window:

Screenshot of xc8 running in console

At this point, there should be a bunch of new files in your program folder, including the hex file (“main.hex”) you will be transferring to the PIC (circled in red below):

XC8 program folder screenshot

Make sure that the PICkit 2 (the hardware device) is correctly connected to your PIC circuit, then open the PICkit 2 program and click the “Auto Import Hex + Write Device” button at the bottom right corner of the window (circled in red below). Browse to the folder where your program is stored and select the hex file. You should see some messages indicating that the program is transferring. You may need to tick the “VDD On” check box to supply power to your circuit (also circled in red below).

PICkit 2 software screenshot

Because you selected “Auto Import Hex + Write Device”, the PICkit 2 software will continue monitoring the hex file you selected. Whenever you recompile the program, the updated hex file will be downloaded to the PIC automatically.

My workflow

When I’m working on a PIC program, I keep the following three windows open at all times:

  • Notepad++
  • A command window
  • PICkit 2 software

Once I have created and compiled a program, I find the following iterative workflow efficient:

  1. I make changes to my C code in Notepad++ and save them.
  2. I press Alt-Tab to switch quickly from Notepad++ to the command window.
  3. I press the up arrow key to return to my previous command, which is usually “build.bat”, in which case I can then just press Return to re-build the hex file.
  4. I keep an eye on the red light on the PICkit 2 to confirm that the software on the PIC is being updated automatically.
  5. I use Alt-Tab to switch back to Notepad++ and repeat the process from step 1.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s