How to program the PIC microcontroller in my projects

Quite a few of my electronics projects use an 8-bit Microchip PIC microcontroller. To avoid repeating the programming instructions and to get less questions about the subject, I collected the necessary information to this page to help hobby builders not so familiar with PICs.

Basics

All PIC microcontrollers used in my projects are in-system programmable. This means that the firmware can be programmed or updated without removing the microcontroller from the circuit. For this purpose, there is a connector on the PCB to connect a programmer to ICSP pins of the microcontroller.

Programmer

The current official programmer from Microchip, targeted for hobby users is PICkit4. It is quite reliable, and has support for the latest controllers. It costs about 60 €. To use it, you need to download the complete MPLAB X IDE software package (600 MB), and install the MPLAB IPE software. It is not very easy to use, but it will get the job done. If you are planning to do development yourself with PICs, the PICkit4 is decent choice.

But if you just want to build one of my projects, easier and cheaper alternative is to get a PICkit2. It has been obsolete for many years, but clones are available from e.g. eBay or Aliexpress for about 10 €. Do not buy PICkit3 or PICkit3.5. The PICkit2 is more reliable, and with my modified PICkit2- software, it can program all the PICs used in my projects.

Another interesting option is this project which uses Arduino as a PIC programmer. You can try it if you already have Arduino. But I can't recommend to buy Arduino just for that purpose. I have tried that project, and haven't got it working reliably with Arduino Uno. At the time of writing, the latest version 0.99 always gives me error 'Serial port failed to receive a byte, read returned 0'. The fix suggested here by WydD didn't help in my case. Using an earlier version 0.97 I was able to program PIC16F15355, but not PIC16F1788. If you have better success with the Arduino method, let me know!

Programming cable

All my my projects have a 5-pin or 6-pin header on the PCB, where a PICkit2/3/4 can be connected directly. In case of 5-pin header, just match pin 1 (indicated by a triangle on board and PICkit). Pin 6 is usually not needed, so leaving that out saves some PCB area.

On all of my projects there is also a footprint on the PCB with 6 small pads and three small holes. With this, you don't need any connector on the board, but you need a Tag-Connect cable instead.  For PICkit the suitable cable is TC2030-PKT-NL, but it is very hard to find. Alternatively you can get TC2030-MCP-NL and build an adapter. The -NL in the codes specifies a 'no-legs' version of the cable. If it is not available, you can also get the 'legged' version of the cable and just break the legs by bending them with finger. The Tag-Connect cables are very handy but also very expensive, that's why I have included both the Tag-Connect footprint and the 5-pin header footprint if there is room on PCB.

Powering during programming

The PIC of course needs power when it is being programmed. It can be powered from external supply or from the programmer itself. When using the PICkit2- software, it automatically detects if there is external supply connected and if not, power is supplied from PICkit. With the IPE software the power from programmer must be separately enabled from the advanced options menu.

Bootloader

Some of my projects use a bootloader. A bootloader is a small program in the microcontoller which allows to program or update the main application to the microcontroller without a programmer. Usually the new firmware is transferred to the microcontroller via some interface that the main application is already using. For example the JAKADAPTER and J-ACE use USB bootloader, which allows to update the firmware via USB. In this case a software is needed which uploads the new firmware to the microcontroller. If you are building a project which uses bootloader, you will anyway need a programmer to program the PIC for the first time.

page created 11.2.2017
last updated 6.6.2021 webmaster@kair.us