Email Address:

Lost your password?

This is the legacy website; please use the new website.

Programming PIC Controllers: How It's Done

Many SILICON CHIP projects include a PIC microcontroller as the central component. But how do you program the PIC if you're not buying a kit or if you want to upgrade the firmware to a later version? Here's a step-by-step guide to doing it yourself.

by Mauro Grassi

For many electronics enthusiasts, programming the PIC micros that are now used in so many SILICON CHIP projects is something of a mystery. If you buy a kit, it usually doesn’t matter because the micro will be supplied pre-programmed. Alternatively if you’re building a project from scratch, then you’ve either got to pay someone to do it for you or learn how to do the job yourself.

A similar problem arises if the PIC fails and has to be replaced or if you want to update the firmware to a later version. It’s not uncommon for the firmware to be revised after a project has been released, usually to add extra features but also sometimes to fix any bugs.

Fortunately, programming PICs is straightforward although you do require a low-cost PIC programmer (more on this shortly). By following the simple steps outlined in this article, you will be able to program almost any Microchip microcontroller, including the popular 16F, 18F, dsPIC33F, PIC24F and PIC32 families.

A few basics

PIC microcontrollers have onboard non-volatile memory (FLASH) that stores the program code (some also have onboard EEPROM for storing persistent data). This program code is referred to as the “firmware”. The term “non-volatile” simple means that the firmware remains in memory even when the power is turned off.

Click for larger image

Programming (or reprogramming) can be done in at least two ways: (1) through “ICSP” (In Circuit Serial Programming) or (2) through “RTSP” (Run Time Self Programming). The latter
option requires a “bootloader” program to be running on the target device. A bootloader is a separate program that can write a new firmware image onto a microcontroller. The firmware image is supplied to the bootloader usually via a USB or serial connection, or from some other storage medium (eg, a memory card).

In most cases, however, a bootloader will not be used. It adds complexity to the code and the bootloader itself needs to be initially programmed. As a result, many micros are programmed using ICSP.

Some projects include the necessary ICSP interface as part of the design (ie, it’s incorporated into the PC board). Otherwise, you will need to remove the PIC micro from its socket and program it externally.

What’s needed

Assuming you have your target device (ie, the PIC micro), you will need the following: a PIC programmer, a PC with suitable software and a breadboard if your programmer does not have a ZIF (Zero Insertion Force) socket.

The programmer we recommend to start with is the PICKit3, which is a low-cost USB programmer (and debugger) from Microchip. There are other more expensive programmers available and they usually have advanced features that the PICKit3 lacks, such as bulk programming and better debugging options.

That said, the PICKit3 is suitable for all hobby work and for prototyping and development. It’s portable, inexpensive and can even provide power to your target board (through the USB).

The PICKit3 can program almost all Microchip microcontrollers and its firmware can be upgraded to enable support for future devices. The device itself is based on a Microchip microcontroller and it can update its own internal firmware using RTSP. This is an important feature because the programming algorithm for a future device may change (different Microchip microcontrollers have different programming requirements).

Share this Article: 

Privacy Policy  |  Advertise  |  Contact Us

Copyright © 1996-2021 Silicon Chip Publications Pty Ltd All Rights Reserved