iRX Project: Getting Started

ROBERT D. POOR
MIT MEDIA LABORATORY
December 1998
r@mit.edu

The goal of the Getting Started project is to work through the mechanics of putting together your PIC development environment and then compiling, downloading, and running a simple PIC C program.

The hello.c program used in this example is very simple - it repeatedly flashes the red LED on an iRX 2.1 board and prints out "Hello, World." on the serial port - but demonstrates many elements common to other projects. You'll more about the code itself in the Hello Project. The basic steps for this project are:


Gather required hardware

For this project (and every project in this seminar), you'll need the following hardware:
A PC running Windows 95.
A PICStart Plus programmer from Microchip. The PICStart Plus can be purchased from Digi-Key. List price (as of Jan 1999) is $199, but if you're a school or university, be sure to ask for the educational price of $149. In some cases, your local Microchip representative may be able to get you a good deal; check the Microchip web pages for the representative for your area.

Alternately, if you're on a budget, you might consider the PIC-1+ programmer from ITU Technologies, which lists for $59 (as of Jan 1999) or only $39 in kit form. (Suggestion: If you buy a PIC-1+, pay the extra $15 for the ZIF socket -- it's worth it!)

One or more iRX 2.1 PIC Development boards. These boards aren't commercially available, but you can learn about how to make them yourself in the iRX 2.1 web pages.

For this particular project, you will also need to put together a serial cable to connect the iRX board to your PC. The wiring for the cable is also described in the iRX 2.1 web pages.


Install required software

For this and other PIC development projects, you will need:
The PCM C Compiler from Custom Computer Software. This is not freeware, but at $99 for a basic licence and $50 for additional site licenses, it's well worth the price. CCS has been very responsive to fixing bugs and providing upgrades. The PCM C compiler also ships with a large body of example code.

When you install PCM, make sure that the PCINCLUDE variable is set up to point to the include directories for PCM.

MPLAB, Microchip's Integrated Development Environment for PIC programming. MPLAB includes a text editor, project manager, a comprehensive simulator/debugger, assembler, and drivers for the PICStart Plus programmer. It also provides a convenient interface to the PCM C compiler (see above), so you can compile files without ever leaving MPLAB.

Best of all, you can download the latest version of MPLAB free of charge from the Microchip Web site.

Once you have downloaded and installed MPLAB on your machine, you must configure MPLAB to recognize the PCM C compiler. To do this, launch a DOS window and type "CCSC +SETUP".

Assuming your software and paths are correctly set up, you should see the following from PCM:


Create an MPLAB project

Before you can compile the C source file, hello.c, to its corresponding machine code file, hello.hex using MPLAB, you must first create a project. In my studied opinion, the user interface to MPLAB's project manager leaves much to be desired (read: it's truly horrific), so this section takes you step by step through the process of setting up a project in MPLAB.

Step 1

Create hello directory & hello.c

Create a directory in which you want the firmware to reside. In this example, we'll call it "hello". Use your browser to fetch the source file for hello.c and copy it into that directory.

Step 2

Create a new project in MPLAB

Launch MPLAB and select Project=>New Project

Step 3

Create hello.pjt

Navigate your way to your hello directory and create a new project named "hello.pjt".

Step 4

Configure Development Mode

MPLAB will bring up the Edit Project dialog window. First, you'll have to tell MPLAB what kind of processor you're using. Next to the Development Mode label, click on [Change]:

Step 5

Specify PIC16F84

Select MPLAB-SIM Simulator, and in the processor pull-down list, select PIC16F84. Click [Reset].

Step 6

Select CCS compiler

Now you have to tell MPLAB that you want to use the CCS compiler (rather than the built-in assembler). Click on the Language Tool Suite and select CCS:

Step 7

Set up node properties

Next you will tell MPLAB about the files that comprise the project. Click first on hello[.hex] and then on Node Properties:

Step 8

Select PCM compiler

You will get a window that establishes the compiler options. (You say your Node Properties window looks different than this? Did you remember to select CCS as the Language Tool in step [6]?) Under Compiler, check the PCM box and click OK:

Step 9

Add hello.c to Project Files

Now, finally, MPLAB will deign to let you add a source file to the Project Files List. Click on Add Node:

Step 10

Select your hello.c file and click [OK]:

Step 11

...oh joy

... and notice that your hello.c file is now listed in the Project Files List. Click [OK]:

There. That wasn't so bad, was it? Well, okay, yes it was so bad - that's why I took the time to write this up.


Compile hello.c

Now that you've taken the time to create the hello project, compiling it is a simple task. Simply click on Project=>Make or push the F10 key:

Assuming that all the paths are set up correctly and your program is free of errors, you should see the compiler window flash by briefly, followed by this window:

Congratulations. You've successfully created hello.hex, the file that will be downloaded into the PIC's program memory in the next step.


Download the hello.hex file to a PIC

[1] Make sure the PICStart Plus has power and is plugged into the serial port on your computer.

[2] Make sure a PIC16F84 is inserted in the ZIF socket on the PICStart Plus and that the gate is closed.

[3] Select Picstart Plus => Enable Programmer

This will bring up the programming window. Take a moment to check the following settings:

  • Is the device set to PIC16F84?
  • Is the clock type set to HS?
  • ...
If not, fix the settings. (These should have been set by the #fuses directive in the source code. If they're wrong, it could be indicitave of some other problem.) Click on the [Program] button.

...need programmer in order to complete screenshots...


Running the program on an iRX board

[1] Close the PICStart Plus Programming dialog (in MPLAB)

[2] Launch Hyperterm

[3] In New Connection, type "irx9600" and OK.

[4] In Phone Number dialog, Connect Using direct to COM1 and [OK]

[5] In COM1 Properties, Bits Per Second 9600, Data Bits 8, Parity None, Stop Bits 1, Flow Control None

[6] If you now save the configuration, you can use it for subsequent sessions.

In subsequent sessions, you can simply [Cancel] out of the New Connections dialog and File=>Open irx9600.ht. Alternately, if you double click on irx9600.ht (or a shortcut to it), it will launch Hyperterm and configure it for the iRX.


What you should see...


[back...]
[home...]