Getting started with a PIC16F877


Quick Guide
1) Buy dev board
2) Download the free CCS compiler
3) Install the Java 1.4 or greater runtime if you donít already have it
4) Install Teacher so you can upload programs
5) Get my blinking light project
6) Compile my project with the CCS compiler
7) Power up and plug your dev board into the serial port on your computer
8) Copy main.hex from your compile directory to C:\Program Files\Cerebellum Teacher
9) With a command prompt from the Cerebellum Teacher directory type "teacher main.hex" to upload the blinking light program
9) Press a button and the LEDs should start blinking


Details
I have been working on device drivers since graduating from college in 2001. However, I have fond memories of a class in college where I took a Motorolla 68HC11 development board and made a robotic car. With these fond memories in mind I went about searching the web for a good starting point for getting into the hobby of robotics. I didnít want any of those hold your hand kits out there, but I did want something that was well documented to use as a spring board into harder projects. Eventually I can across the following compiler and development board. This pair was amazingly simple to get up and running. Iím going to detail the reasons I chose the products I did and then how I got a very simple blinking led program working.

The first thing I went looking for was a development board. First off I eliminated the idea of just using simple gates and transistors to create something like a line following robot. I was looking for a microcontroller that I could reprogram to do different tasks rather than have a system designed for a single task. In the field of microcontrollers there is everything from BASIC Stamp microcontrollers, to PIC microcontrollers, to getting a PC and connecting some external boards to USB or serial ports. I understand there are tons of other microcontrollers, but these were the ideas I toyed with. After a little thought I decided on PIC because it was fairly cheap, had some good C compilers, and had numerous development kits available. I will likely do a USB/serial PC robot in the future, but for now I wanted to stay with a simpler system I had more control over.

With the PIC microcontroller chosen I wanted to get a development board that had all the processor outputs/inputs exposed and hand some stuff like debug LEDs and server/motor controller. I decided to go with the Cerebellum Microcontroller because it had all that along with a few example programs and excellent documentation. Here is a picture of the Cerebellum developer board.

If you have followed me to this point you can go and look at the documentation/examples for this board here. After reading though this you will know they have some header files that make using this board with the CCS compiler very easy. After downloading the free demo of this compiler, I found there was a bug in the Cerebellum Libraries for the CCS C compiler Biotrics provided on their downloads page. The easiest fix was to simply comment out the analog_custom_init function in cereb10-adc.h. Iíve provided a copy of this download with this fix already done in my blinking light project below.

So now you have a board and a compiler, but you need a way to download your compiled program to the board. For this we head back to the Biotrics download page to get their Teacher app. This needs the java run time environment if you don't already have it. I used version 1.4.2.

Now you have everything installed that you need. I wrote a very simple blink some LEDs when you press a button program using the Cerebellum Libraries. Iíve zip up this documented source code along with the library files and put it here. All you should need to do is open up CSS and then choose to open a project. Then choose this project and hit F9 to compile. Alternately you could create a new empty project and just copy main.c and library files (all the .h files) from this zip. Then compile it. Either method should generate a .hex file which you can then upload to your dev board with Teacher. Once you have your board powered up (red LED will be on) and itís connected to COM 1 serial port on your computer, you can upload the program by typing "teacher main.hex".

Now press a button and the LEDs should start blinking. Hopefully a congratulations is in order!
Please email any questions/comments/errors to robots@glacialwanderer.com.