The Fundamentals of Programming a PIC Microcontroller

May 24, 2018 Altium Designer

Two children programming a microcontroller

One thing I’ve learned from parenting: it can be incredibly difficult to teach a child something. While they might be very interested, and they might have all the time and resources in the world, if the child isn’t ready to learn or is missing some crucial building block, they might just not get the skill or lesson.

 

Thankfully, programming a PIC microcontroller is considerably easier. With the right programming tools, circuit, and functional firmware, you can get a PIC microcontroller to behave exactly as desired. Of course, to avoid unnecessary hassle and frustration down the line, it is still important to adhere to a few crucial steps.

The PIC Microcontroller

Despite the emergence of single-board embedded controllers like Arduino, Raspberry Pi, or BeagleBone, the PIC microcontroller still remains relevant among electronics engineers. Manufactured by Microchip, PIC microcontrollers are characterized by their ease of use, versatile features, and cost-effectiveness. PIC microcontrollers range from simple 8-bit microcontrollers to powerful 32-bit models.

 

The versatility of PIC microcontrollers made it popular not only amongst engineers but hobbyists as well. The broad range of peripherals, memory, and processing power provides a right fit for almost any application. You’ll probably find a PIC microcontroller in your washing machine or alarm system.

Tools You Need To Program A Microcontroller

Programming a PIC microcontroller today is significantly easier than it was a decade ago. Back then, some of the lower range of PIC microcontrollers required a dedicated programmer hardware to inject the firmware in. But if you’re starting with a PIC microcontroller today, downloading a firmware into the microcontroller is usually a simple process.

 

These are the tools you would need to program a PIC microcontroller today:

1. MPLAB X IDE

The MPLAB X IDE is a comprehensive development environment from Microchip. You’ll need the MPLAB X to write your firmware, compile and build it before you can program the PIC microcontroller. Unlike expensive IDE that you need to pay for in the past, the MPLAB X IDE is free for download.

 

Web developer in front of code on computer

The first step is getting your firmware right.

 

2. PICKIT 4

The PICKIT 4 is the latest in-circuit debugger from Microchip that allows you to efficiently download the program to the microcontroller. It is an improved version of its predecessor PICKIT 3 with the added feature of an SD Card slot, which facilitates programming on-the-go for various firmware. When programming the PIC microcontroller in the lab, you’ll need to connect the PICKIT 4 between the USB port of your computer and the programming pin of the microcontroller.

3. Programming Circuit

The programming pins for PIC microcontrollers are indicated in the datasheet. PIC microcontrollers support either In-Circuit Serial Programming (ICSP) or In-Circuit Debugging (ICD), with the latter allowing engineers to debug the firmware in real time.  It is important to include the circuitry for the programming interface in the design for the PICKIT 4 or PICKIT 3 to connect to.

Programming the Microcontroller

With all the programming tools ready and the prototype assembled, programming the microcontroller is almost intuitive. Traditional programming tools require you to power up the hardware before any firmware downloads. But the PICKIT programmers can be configured to power up the microcontroller as long as it doesn’t exceed its maximum current limit.

 

There are two ways to get the firmware into the PIC microcontroller. In the MPLAB X IDE, you’ll find options to ‘Run Project’ or ‘Debug Project’ and clicking ‘Run Project’ compiles and builds your firmware in production mode while the latter creates a debug version of the firmware footprint. You’ll want to take time to ensure that the final product is programmed with the production version of the firmware.

 

microcontroller with pins placed

Done correctly, your microcontroller will start running after the program is loaded.

 

Tips for Designing the Programming Circuit on a PCB

The programming pins arrangement on PICKIT 3 and PICKIT 4 are similar although PICKIT 4 has two additional reserved pin connections. The firmware is transferred through the PGD and PGC signal with a /MCLR pin to drive the microcontroller into programming mode.

 

You’ll want to route both the PGD and PGC in parallel and maintain the same length to ensure minimal signal corruption. Besides that, proper labeling on the orientation of the programming pins on the PCB is needed, as it’s easy to mistakenly plug in the PICKIT in reverse, risking damage to both the PCB and PICKIT alike.

 

Using a great PCB design software like Altium Designer helps you greatly in designing interference-free programming circuits for PIC microcontrollers.

Need more advice on programming a PIC microcontroller? Talk to an expert at Altium.

About the Author

Altium Designer

PCB Design Tools for Electronics Design and DFM. Information for EDA Leaders.

Visit Website More Content by Altium Designer
Previous Article
Increase Your Component and Trace High Density With Via-in-pad Technology
Increase Your Component and Trace High Density With Via-in-pad Technology

Via-in-pad technology gives designers significant routing flexibility. Learn more about via-in-pad designs ...

Next Article
Creepage and Clearance Design Rules Require More Than Integrated Flow
Creepage and Clearance Design Rules Require More Than Integrated Flow

Enough clearance and creepage must be designed into the printed circuit board to avoid arcing or catastroph...

Get My Altium Designer Free Trial Today or Call 1-800-544-4186

Get Free Trial