Understanding ICSP for PIC Microcontrollers




Programming microcontrollers isn't hard. Building a programmer makes a great first electronics project. The goal of this instructable is to explain the simple 'in circuit serial programming' method used with Microchip PICs.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Why ICSP?

Programming a big DIP (through hole) chip is easy. Pop it into a socketed programmer, burn, and return to the application circuit. Test and repeat.

Things get more difficult with smaller (surface mount) chips. There are no standard sockets for QFN, SSOP, QFP, or even the large SOIC .300 packages. There are really expensive ($100s) clips that can attach to, and program, these chips. A different clip is needed for each chip type and pin count you use.

There is an alternative. Its called ICSP.
ICSP means 'in circuit serial programmer(ing?)'. It is a way of programming a PIC while it is still attached to the application circuit. Thats right, no more chip swapping.

1. There are no programming sockets for small package chips. Clips are expensive.
2. Its a pain to move chips in & out of the programmer during development. Impossible for surface mount parts.

Step 2: What Is ICSP?

Five connections are needed to program a PIC while attached to an application circuit. I add a 5 pin header to my circuit boards to make this connection quick and easy.

The basics of PIC programming.
Five connections are required to program a PIC. Power, ground, a programming voltage, clock, and data.

+ (Vdd)/-(Vss) These are the power & ground connections (Vdd, Vss). Pretty standard. If you are using a programmer with 'real' voltage levels (NOT a JDM2!), your application can run from its own power supply when programmed, eliminating these connections.

Vpp This is the programming voltage. PICs enter programming mode when ~13 volts are placed on the MCLR/Vpp pin (usually pin 1 on modern PICs, more on that below).

Clock/Data or PGC/PGD The clock and data lines are used to write and read the PIC firmware. These are usually the same pins as PORTB6 & PORTB7.

Exercise:Identify the ICSP connection points on the PICs in the pictures below.

If the PIC fits, wear it.
I get a lot of questions about my JDM2 design on instructables. The most frequent is "Will it program PIC X?'"' - here is how you can tell:

1) Look at the data sheet. Find the 'Pin Diagram' that looks something like the picture below.
2) Identify the location of the pins that must be connected for programming (Vpp, Vdd, Vss, Data, & Clock).
3) Look at the socket connection on the programmer. Can you match the required pins with a socket on the programmer?

Step 3: How ICSP?

Depending on your design, you can now make all the required connections and program your PIC. There are a few catches that you should know about. Design for ICSP is important. Microchip provides a nice PDF application note about designing for ICSP.


Here are some tips and examples of ICSP designs from my previous instructables.

Tip #1, Threat level: Important
Don't connect anything else to the CLOCK and DATA pins (usually RB6 & RB7, PGC & PGD).
Just don't do it. There are situations where very clever engineering types get away with it, but don't do it. The components attached to the pins will skew the clock and data signals, resulting in unpredictable programming. Additionally, if you ever want to use an in-circuit serial debugger, you can't. Just don't do it.

Tip #2 Threat level: Explosive
Always use a diode between the programming voltage and system voltage.
If using MCLR (master clear) on a PIC you must provide some voltage on the MCLR pin through a 10Kish resistor. This is also the pin to which you will apply ~13 volts to enter programming mode. I put a 1n4148 (equivalent) diode between the resistor and MCLR/Vpp pin (as shown in the schematic and rendering below). This keeps the programming voltage on the Vpp pin, preventing destruction of other components on your board.

Tip #3 Threat level: (re)tired
Low voltage programming is holding you back, man.
I have never been successful with LVP. I have never seen it work (consistently) with my own eyes. Just bite the bullet and spend $2.50 to build a JDM2 programmer.

Step 4: ICSP Programmers

ICSP does not require a different programming protocol. A socket-based programmer already produces the required signaling, but sends it to the socket rather than through wires. Most socket programmers can be used as an ICSP by rigging wires from the socket to the application circuit.

For example, the original JDM2 programmer (here: http://www.jdm.homepage.dk/newpic.htm ) can be used to do ICSP programming by bringing the 5 required signals to a header. This can be seen in the programmer here: http://www.belza.cz/digital/jdm.htm . To keep things handy, I remade this design in Eagle Cad and attached it to this instructable. Watch the transistor orientation, one of the footprints may be incorrect (I made this more than a year ago, I don't remember anymore).

Similarly, my updated JDM2 programmer (here: https://www.instructables.com/id/EN28KZDDYVEP286GRI/ ) can be used for ICSP by sticking wires into the DIP sockets and connecting them to the target PIC.

*****JDM2s use funky voltages...connect it to the circuit WITHOUT external power (or even ground) connected to the application circuit. Remove the ICSP connections before applying power. Failure to do this is not destructive, but will result in failed programming*******

Another option is a (semi-)proper ICD programmer. ICD allows you to control firmware execution on your PIC by setting break points in the code or reading out memory and port values. An ICD can also animate the execution of code, power the application circuit, and program the PIC. It does all this through the same 5 pin ICSP connection we have discussed. Several ICSP clones that you can make yourself can be seen here: http://www.icd2clone.com/wiki/Main_Page . I built the PiCS (rev B) a few months ago and love it.

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    22 Discussions


    Question 7 weeks ago

    Help! I have a F2117TE2DH microcontroller I need to debug/adapt. It is approx 160 mm square and has 128 pins! So far I have been unable to find any kind of clip or plug which will allow me to safely connect to it, unsurprising when you consider the pin pitch is 0.5 mm!

    Correct me if I'm wrong but you seem to be saying all I actually need to connect to is/are
    Vpp, Vdd, Vss, Data, & Clock and the remaining pin values do not matter? If so this is brilliant news but I need to be very clear about this before cracking the champagne!


    6 years ago on Introduction

    how do i program a 40 pin pic like for example the 18f4550? It has 2 vss pins and 2vdd pins, do i only need to connect to one set of them?

    Also if anyone knows, when using a jdm2 to program a pic thats not in circuit, do i need to have any resistors or diodes or anything to prevent explosions or w/e? I find it odd that i see little details discussing explosions and its hard to understand what exactly they mean, but the odd part is if explosions are happening why arn't they just included into the programmers origional skematic to begin with so there's no extra work and thinking involved?


    6 years ago on Introduction

    I want to program PIC12F629 with readymade .hex code. Which programmer should I use? I would like to know the best and cheapest programmer available. I bought PICKIT2 clone from India but I had very bad experience with it. I couldn't program with it.
    Can you please suggest me good programmer?


    13 years ago

    On my site www.blueroomelectronics.com I've posted the schematic for a simple MPLAB ICD2 clone. I'll be updating the site with a full assembly manual and I've had PCBs made.

    inchworm 3d.png
    2 replies

    7 years ago on Step 3

    Great guide. I like your list of pitfalls in step 3, those can be the most confusing part of this.


    8 years ago on Step 3

    Were you pulling your PGM pin low/high when attempting LVP?


    9 years ago on Introduction

    awright, im an elecronics student at norwich tech, Ct, and my teacher wants me to transfer the code i used on the parallex basic stamp to a PIC. he said that the code is pretty much the same, but some minor changes would need to be made. what sort of changes would that include? (this is the project)

    2 replies

    Reply 9 years ago on Introduction

    It's a different language altogether, and needs different tools. You'd need to redo most of the work. In the absence of a reasonable argument for the switch, I suggest you decline to do so.


    9 years ago on Introduction

    nice instructable,
    I've been using ICSP for a few years, and its basically the same configuration your using except I like the 5+5 pin headers (like the USB headers plug into on the motherboard).

    for the diode in the MCLR pull-up I used the BAV99W SMT device, works great.


    11 years ago on Introduction

    Hi Ian, First off, great job on the instructable! Even though I'm a complete noob in the electronics realm, the setup makes a lot of sense the way you present it. My question though is what kind of projects would this be useful in? I am looking to create a programmable series of electroluminescent tiles which will light up in preset patterns as a wall art piece. Would this kind of microcontroller work in such a set up? Or am I completely off? Thanks for any information anyone has to set me straight!


    13 years ago

    Firstly, good introduction to ICSP.

    Up until now I've been using a Velleman kit to program my PICs and was quite pleased with it. I have, however purchased some PICs that do not fit the onboard sockets. No problem I thought as I read through the documentation and found out from the circuit diagram that the unit is merely a socketed ICSP programmer. I imagined I could still use the unit to program the new chips I purchased, however the supplied software with the kit (velleman # k8048) does not include a memory map for the PICs I purchased - does this mean I cannot program them?

    Do you know of any freeware that will allow me to use the K8048 ICSP programmer with the PIC16C72A?

    Here is a link to the K8048 circuit diagram:

    2 replies

    Reply 11 years ago on Introduction

    I've used WinPIC with the K8048, it was my first programmer, I only played with the 877 and 877A's with it and that was via the ICSP socket, its a great starter programmer, but I do recommend getting a CCS ICD or a MPLAB ICD2 (I use both)


    Reply 12 years ago

    winpic is a great free program to program pics, a k8048 velleman driver is available too, you may find that the icsp port is poor on the k8048, it will only program certain pics, not too sure why. my solution was to make an icsp cable picking up the relevant pincs from a turned dil socket plugged into one of the sockets on the board, hope this helps. simon