OK, so for the past year or so I have been battling with the idea of in-circuit programming for the PIC microcontroller. Should have been easy but it just wouldn’t work for me. I used my clone ICD 2 but there was no communication. I tried my works PicKit2 but I had the same problem. The chips could not be Identified.
Because of this I decided to try the bootloader method. This was successfully implemented on the PIC16F877 and I still use it today. But.., I found it very difficult to find suitable bootloader firmware for PICs other than PIC16f873/877. So I was back step 1, battling with ICSP.
After some research, trial and error, and the a little bit of luck, I finally cracked the code. Do you want to know how I did it…?
What is ICSP
ICSP or ‘In Circuit Serial Programming’ is a method of programming microcontrollers while they are actually in the circuit that they will be operating in. This has a few advantages.
- Circuits can be mass produced and then programmed at your leasure
- The firmware can be updated with out removing the microcontroller
- The ICSP system can also be used to debug the software while it is still in the circuit.
What does this mean to the hobbyist on a budget? OK, so you have designed a circuit which requires firmware but has no ICSP facility. Your first version of the firmware was not correct for your application so you remove the microcontroller, place it in the programmer, program the new firmware then return it to the circuit for evaluation. Once or twice won’t really damage the microcontroller but the more you revise your firmware, the more you remove the microcontroller with potentially more damage to it’s legs. If the legs break, you will have to replace the microcontroller or do a quick bodge/patch up. With the ICSP system this isn’t a problem because the microcontroller stays in circuit therefore sustaining no damage. Nice!
What Do We Need?
“OK quit your jibber jabber, just tell us what to do!” (sorry Mr. T just walked in the door). I work with the PIC microcontroller so I use my ICD2 programmer. I also use a PicKit2 which is a dedicated incircuit programmer. Both programmers work fine.
Connections to the PIC will be as follows,
- Vpp which is connected to the MCLR pin of your PIC. This pin also needs to be tied to Vdd of the PIC via a 10K resistor.
- Vdd which is connected to the Vdd of the PIC (normally 5V with ref. to Vss)
- Vss which is connected to Vss of the PIC
- PGD which is connected to PGD on the PIC
- PGC which is connected to PGC on the PIC
- PGM is not used
Now as I understand it, the pin out for the ICD2 and PicKIT2 are normally standard but the other end can be of any type required by the end solution. What I’m saying is beware of strange connectors on the end of the programmers cable, they may not be what you expect. I find that if I mimic the pin numbers from the programmer to the target circuit, fault finding can be made a lot easier knowing that the ICSP is wired correctly and that the PIC can be programmed. After all, a PIC with no firmware is just a piece of useless silicon or a piece of still moist chewing gum, no good to anyone. But sorry, I digress.
Now before I go into what the pins do i think it would be a good thing to know what will happen when you have a working ICSP connection to your circuit. It’s simple really.
- Open MPLAB.
- Select device type .
- Select programmer type.
- Click the reset icon for the programmer.
- Assuming you have the PIC in circuit and the connections are sound, you will get confirmation of the device type and it will indicate if a new operating syatem needs to be down loaded.
Getting the confirmation of the device type shows that you have full commications so your ready to roll. If you get no message at all, check your connections, check your settings and check your circuit. There is no way around it, check, check and check again.
What do the pins do?
I’m not going to claim to be the master of ICPS or anything like that so I won’t be going into great detail. What follows is a basic description of the pins from the icd2/ PicKit2.
Pin 1 -MCLR/ Vpp
This is the reset pin for the PIC. High for normal operation and Low for reset. Also, during ICSP operation, this pin is driven up to 13V and also to ground. Therefore, the application circuit must be isolated from the voltage coming from the programmer.
Pin 2 – Vdd
This is the supply voltage for the PIC. Although some PICs can be programmed at 3.3V, it is highly recomended to program the PIC at 5V. If you are running a system on a lower voltage, you may have to completely isolate the PIC from the main circuit to ensure correct ICSP operation and protection for the rest of the circuit.
Pin 3 – VSS
This is the common return, ground, 0V (what ever you want to call it). Vdd is measured in relation to Vss.
Now pins 2 and 3 are the supply lines which give the PIC its power. This is fairly simple to remember. But what you may not know is that some pics have a analog Vdd (AVdd) and an analog Vss (AVss). These must also be connected to ensure correct ICSP operation.
Pin 4 – PGD
This is the data line for the PIC during ICSP operation.
Beware, Do not..,
- Place a pull up resistor on this line during ICSP operation. This will create a potential divider effect when programming and the signal will be degraded.
- Place a capacitance on this line. this will prevent fast transistions of the line again degrading the signal.
Pin 5 – PGC
This is the data clock line for the PIC during ICSP operation.
Beware, Do not..,
- Place a pull up resistor on this line during ICSP operation. This will create a potential divider effect when programming and the signal will be degraded.
- Place a capacitance on this line. this will prevent fast transistions of the line again degrading the signal.
During ICSP operation it is advisable to isolate these pins from the rest of the circuit maybe with a switch or a set of jumpers (paisley perhaps), but I find the best way is to dedicate these lines to progamming. That way, you know what components are going to affect the process.
Pin 6 – PGM
Not used, Dont care.
Don’t connect it anywhere and you will be just fine.
And that’s it, or atleast the very basics. But if you want some more information which is more technical and not just the ramblings of an old man from Spondon, you could try the links below:
That’s all folks, I hope this is helpful. Good bye and happy ICSP-ing.

