Got some PIC microcontrollers but don’t know how to program them? Read through this article to learn how to program PIC microcontrollers.
Introduction
Nowadays, it’s easy to program modern development boards. You simply hook them up via a USB cable to your PC, run your programming environment, choose your board and chip type, write your code, and then upload it with a click of a mouse button. Thanks to the advent of the Arduino ecosystem, the process of programming a chip or board has become much easier.
However, as you’ll see later, not every chip works with Arduino. Several chip manufacturers choose to have their own proprietary programming peripherals and software. One of them is Microchip, which keeps its popular PIC MCUs programmed by its proprietary programmers and software.
Here, you’ll learn how to program PIC microcontrollers with different programmers and development environments.Â
How are PIC Microcontrollers Programmed
Like other microcontrollers, PIC microcontrollers can be programmed in-system through ICSP (In Circuit System Programming). ICSP means the chip can be programmed inside a circuit, no need to take out the chip in order to program it, as long as you have access to the ICSP lines.
However, PIC microcontrollers have a unique set of classic ICSP lines: Reset, VDD, VSS, ICSPCLK, and ICSPDATA. These lines are very different from what Arduino has. The table below compares standard 6-pin Arduino and PIC MCU ICSP lines.
ICSP Line | Arduino | PIC | ||
---|---|---|---|---|
Pin no. | Function | Pin no. | Function | |
Reset | 5 | RESET | 1 | RESET |
Power | 2 | VDD | 2 | VDD |
Ground | 6 | VSS | 3 | VSS |
Clock | 3 | SCK | 4 | ICSPCLK |
Dat1 | 4 | MOSI | 5 | ICSPDAT |
Dat2 | 1 | MISO | 6 | Reserved |
To add to the complexity, Arduino development boards usually employ a bootloader. Through this bootloader, an external programmer is not needed. With this, popular Arduino development boards, such as the UNO or MEGA, do not need external programmers. These dev boards have a built-in USB-to-UART chip which serves as a communication interface between your PC’s USB port and the MCU. A bootloader code is written inside the chip, which effectively self-programs the chip through commands on the PC. Note, however, that you have to reprogram the bootloader code with an external programmer in case the code gets corrupted.
HOw to Setup the PIC MCU ICSP Lines
The ICSP lines should have a direct connection between the PIC and the programmer through the circuit lines. The reset pin usually needs a pull-up resistor for signal integrity purposes. It is not recommended to obscure these lines with passives like resistors, capacitors or diodes, although for some instances, programming still works even with the added components.
HOw to Program a PIC MCU
USing Offcially Supported External Programmers
Microchip has proprietary programmers like the PicKit, ICD, SNAP, and PM3 programmers. It officially supports these programmers and employs timely firmware updates. Additionally, Microchip is known for having good customer support for its tools and devkits.
You use these programmers in combination with an IDE or programming software. Before, the popular software to use was MPLAB IDE. MPLAB was simple and easy to use during those times.
The next iteration to the series is MPLAB-X. MPLAB-X IDE programmed not only PIC MCUs but other MCUs and devices as well like AVR MCUs (Atmel), SAM ARM Cortex MCUs, EEPROMS and memory, and others. MPLAB-X also supports several plug-ins and can even do performance analysis and data visualizations, among others.
USing Third-PArty External Programmers
Interestingly, several third-party PIC MCU programmers have been developed by other people. One such popular programmer among hobbyists is the PIC K150 programmer. It is cheaper than the official tools and can program many classic PIC MCU chips. It is also easy to use although it uses legacy software.
PIC K150 was originally produced by Tony Nixon for Kits r us, a DIY electronics shop. It is firmware upgradeable and uses the PIC16F628A as it’s main chip.
In order to program using the PIC K150 programmer, you’ll have to use their software. Below is a video rundown on how to use it.
Create your Own Programmer
If you don’t want to buy an external programmer, you can create your own COM port or USB based programmer. These programmer’s parts are made up of common off the shelf components and can program classic PIC MCU chips.
- usbpicprog – an open source Microchip PIC programmer for the USB port.
- JDM COM Port Programmer – COM Port programmer using serial made by Jens D. Madsen
You may also create your very own ‘Pickit clone’ (PIckit 2-based) using a PIC18F2550 and some off-the shelf components as seen below.