PIC Programming on OS X


Finally! I’ve been trying to setup some kind - any kind - of PIC programming environment on my OS X box. Most of them come with Windows applications and there are a few Linux tools out there, but I wanted an OS X environment.

I didn’t get a pure one however. I did have to use Apple’s X11 and most of the tools are Linux based, but I can now compile and write code to a chip. Since I am just starting out I am not too picky on what kind of chips I can write to, I just needed something to get me started. So if you are in the same boat here are some somewhat detailed steps to getting setup.

The programmer I am using is the Microchip PICKit 1 Flash Starter Kit (but I’ll show you a couple others too). To start off with you’ll need Apple’s X11 environment and Fink.

Get those installed. Then fire up the X11 terminal (by launching the program). Fink will put it’s stuff into a directory called /sw. /sw is kind of like a little mini unix file system separate from the main OS X one. It’s important to note that Fink will install stuff into that /sw file system not the normal OS X one. Now we’ll need to install some libraries with Fink.

Using fink install gtk+2, popt, and libusb. This is done in the X11 window by typing

$ sudo /sw/bin/fink install gtk+2

then type your password. Replace gtk+2 with the others and repeat.

Now we’ll have to build a few programs from source. Here’s what you’ll need: gpsim-0.21.11 - visual debugger (http://www.dattalo.com/gnupic/gpsim.html) gtk+extra-2.1.1 - required by gpsim (http://gtkextra.sourceforge.net/) gputils-0.13.3 - compiler, linker, etc (http://gputils.sourceforge.net/) usb_pickit, picp-0.6.7, or pk2-1.34 - to burn the program to the chip (depends on your chip programmer) (http://home.pacbell.net/theposts/picmicro/ http://charm.cs.uiuc.edu/users/olawlor/projects/2003/microchip/)

Starting with the most important, untar the gputils tar into a directory (I put all these downloads into ~/PIC_Programming). In the X11 window navigate to the gputils directory and type

./configure --prefix=/sw

After it does all it’s checks type

$ make

after it’s done with it build type

$ sudo make install

Once that’s finished you should be able to run /sw/bin/gpasm (that the assembly compiler if you hadn’t guessed) - gplink, gplib, gpdasm, and gpvo are also created.

Now you can compile, but you’ll probably want to test the code after you write it. Thats where gpsim comes in.

gpsim took forever to get to work, and in the end the chips I am playing with are not even supported in the debugger (12F675). The ones it supports are listed on the home page so check it out if you are going to try to use this for something real. Anyway here is what I did to get it to work.

First you have to compile and install gtk+extra. I tried everything under the sun to get this to compile and sadly I didn’t write down exactly what I did. It had a great deal of trouble finding gtk+2 (which you installed with Fink above). Before you run configure set an environment variable to point to where gtk2 is (I think that’s why it complains anyway):

$ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/sw/lib/pkgconfig

Then run the whole configure, make, sudo make install and don’t forget –prefix=/sw when you do configure.

With gtk+extra in we can install gpsim. This one requires you to jack with the code a bit. Open the file input.cc and comment out the lines


Then open up gpsim/main.cc and change the extern “C” line to read:

extern "C" {
	#include "/sw/include/popt.h"

Once that’s done, make sure that PKG_CONFIG_PATH environment variable is still set and then run configure (yes with the –prefix=/sw), then make and make install.

When you go to run gpsim, make sure you give it a processor and a hex file even just to test. If you don’t, the application seems to hang. For example, just to see if it works I typed:

$ /sw/bin/gpsim -p p16f877 myprog.hex

You can compile, and test, now on to burning (or whatever the proper term is). This really depends on the kit you have I have the PICKit 1, but the firmware is version 2. This coder http://charm.cs.uiuc.edu/users/olawlor/projects/2003/microchip/, bless his heart, wrote a an uploader for PICKit 1 with firmware version 1 and puts it out in binary form from Linux and OS X. If you have one of those grab the pre-made binaries and your in business.

If you’re like me and have firmware version 2 grab the source for 2004/11/12. Once you compile that, you’ll be able to burn to firmware version 2 (good enough for learning).

To get it to compile, edit the Makefile and change line 7 to


and line 8 of usb_pickit.c to

	#include "/sw/include/usb.h"

With this one just type make and it should create a program in that directory called usb_pickit. If you have a PICkit2, Picstart Plus, Warp-13, or JuPic programmer check out http://home.pacbell.net/theposts/picmicro/ and compile one of those programs. I misread what I was doing at first and actually compiled both picp and pk2 before I realized I couldn’t use them. They both required a bit of tweaking for the /sw offset.

In the end though, it works :)

N.B. HI-TECHhas a cool, Free C environment for writing PIC programs - there is a Windows, Linux, and… gasp… Mac OSX version too - and wouldn’t you know it it’s based on Eclipse.