Serial PIC Programming
Once you have written a short test routine in MPLAB, and it compiles
cleanly to the required .HEX file, you need to get the code onto the
PIC. The simplest (and cheapest!) method of programming a PIC is to
build your own serial programmer, or buy a cheap kit. The idea is to
feed the PIC a 5V serial clock and data line, a 13.4V programming
line (/MCLR), and a couple of +5V and GND connections.
These five-to-seven connections are all you need to program the
extensive MicroChip family of serially-programmable PICs. A low-cost PIC
programmer is available from Peter H. Anderson (select the
Starter Package for PIC Newcomers). This excellent kit includes a
breadboard, all the required parts, detailed assembly instructions,
a wall wart, parallel cable, and TWO 16F84 PICs and 4MHz resonators -
all for US$49.
There are many other cheap serial PIC programmers available, and if
you use scrounged parts from the Department of Electronics, you could
probably build a serial PIC programmer for no cost! The style of
programmer is often referred to as a "David Tait"-style programmer, as
Mr. Tait is known as "the father of printer port PIC programmers".
David Tait retired from PICs a while ago, but you can still browse
through his huge archive here.
Once you've built and tested the serial programmer (don't be fooled
by the parallel port implementation - it only uses one data line for
transferring your code), you will need software to interface with the
PIC, correctly blow the fuses on the PIC, download your HEX code to the
PIC, and verify that the memory locations of the PIC are accurate. This
software is offered for hundreds of dollars from MicroChip and the like,
but again a much cheaper solution is available.
Bojan Dobaj distributes
an excellent software package called P16PRO, which will program almost
any MicroChip PICmicro. It's available at http://www.geocities.com/SiliconValley/Peaks/9620/,
or from his webpage at http://www.bigfoot.com/~bojan.dobaj.
This software package is freeware for the PIC16F84, and asks for a small
donation to program other PICs. While the documentation bundled with
the software isn't the best - Bojan is quick to respond to email.
If you're using the P16PRO software with a serial-programmable PIC
on an el-cheapo parallel port downloader -- then you're doing something
that millions of others have, and you can read the slew of documentation
available on the web. If you're using a RadioShack CDN$130 PIC
programmer, expect minimal support and no available fix for any problems
you encounter. Needless to say, I have an obvious bias.
There are a number of settings associated with the P16PRO software,
and several of the settings are subtle. If you've built and tested
Peter H. Anderson's basic PIC
programmer, as he describes in the documentation, you can use
the settings outlined below. For other programmers, you should use
trial and error to find the correct settings.
For Peter H. Anderson's programmer:
- Reboot your computer into DOS mode (or use the DOS-only laptop)
- Find and execute the P16PRO executable (c:\p16pro\p16pro.exe)
- Goto the "Settings" menu
- Select "Device" and pick your PIC
- Select "Fuses" and set:
- Oscillator: XT
- Watchdog Timer: Off
- Power Up Timer: Off
- Code Protect: Off
- (Although we set the configuration bits through software in
the two demonstration programs shown above)
- Select "Other" and set:
- Your LPT port
- Save on Exit
- Show Program Data
- Show Data for 8X
- Hex Type INH8M
- Verify On
- Blank Check After Erase On
- Select "Hardware" and set as follows (for the PIC16F84):
+-------------------------- Hardware Setup------------------------+
ª
ª OutData Clock Vdd Vpp Vpp1 Data In
ª
ª (+) D0 ( ) D0 ( ) D0 ( ) D0 ( ) D0
ª ( ) D1 (+) D1 ( ) D1 ( ) D1 ( ) D1
ª ( ) D2 ( ) D2 (+) D2 ( ) D2 ( ) D2
ª ( ) D3 ( ) D3 ( ) D3 (+) D3 ( ) D3 ( ) ERROR
ª ( ) D4 ( ) D4 ( ) D4 ( ) D4 (+) D4 ( ) SELECT
ª ( ) D5 ( ) D5 ( ) D5 ( ) D5 ( ) D5 ( ) PAPER END
ª ( ) D6 ( ) D6 ( ) D6 ( ) D6 ( ) D6 (+) ACK
ª ( ) D7 ( ) D7 ( ) D7 ( ) D7 ( ) D7 ( ) BUSY
ª
ª ( ) Neg ( ) Neg ( ) Neg (+) Neg ( ) Neg ( ) Neg
ª
ª < Cancel > < OK >
ª
+-------------------------------------------------------------------+
Note that Vdd and Vpp1 are not actually controlled by this
programmer. But, they have to be set to something. The "neg"
indicates negative logic. That is, in the case of Vpp, D3 is
normally high and the +13.4 programming voltage is off. The
programming voltage Vpp is applied when D3 is brought low.
The flip-side of this coin is that you should change the Vpp1
column to be the same as the Vpp column if you're using the
PIC16F874. This is because the software wants to use two different
voltages, and the standard programmer doesn't support that.
Remember to save this information from the "Settings" menu.
From the main screen of the P16PRO software, load the HEX files
available above, cross your fingers, and press F4. If everything is
working correctly, the green programming LED will flash, the code will
download, and you're done!