PIC ICSP gives you a convenient way of programming PIC Micros without removing the chip from the development or production board. In fact it is the only way to program PIC microcontrollers so you will find the ICSP interface on all devices.
All you need is a programmer that provides the ICSP connector (usually a six pin molex/dupont connector) which you plug into your target board. For example PicKit2/Pickit3 uses the ICSP connections shown in the diagrams below.
It is simply a defined serial interface. One signal (VPP) is held high (at a high voltage 8-13V) to signal that programming is commencing. The the data and clock lines are toggled to drive programming data into the device and the high voltage allows the internal Flash to be programmed.
ICSP stands for In Circuit Serial Programming. If you are careful you can program the microcontroller without removing it from the target board i.e. in-circuit.
It is microchip's proprietary method of programming the complete range of "re-programmable" microcontrollers and is present in every microchip device. Basically it is a serial receiver interface that accepts address and data information that the microcontroller itself programs into the memory areas such as Flash memory and EEPROM memory.
The programmer is controlled from the PC using an IDE and for the PicKit2/3 this will be MPLAB X IDE. This program loads up your hex file (that you want to burn into the PIC device) and sends commands to the programmer to do that job via the ICSP signals that you connect to your PIC device (see below).
Here are two reset circuits and ICSP connections (I usually use the simpler one below!).
The programming input pin Vpp doubles up as the reset input. Note In newer PIC chips you can program the MCLR to be an input pin with the reset action taken care of internally (The 16F877A requires an external reset control).
Note the headers below also show the PICkit3 pinout.
PIC ICSP circuit diagram showing connection of a 16F877A ICSP schematic. The ICSP connector is HDR2 in the first image and HDR1 in the second image.
The PIC ICSP reset circuit is an over the top over-protected circuit that you would use if you were being ultra cautious or producing a developed PCB design. It stops high volts going back to the 5V power line (D2), has a fast shut down when 5V is off (D1) - allows fast rest from power Off-to-On and has a defined rise time for a delayed reset start.
As you can see pin 6 on the ICSP connector - the PGM connection - is not connected. PGM is a specialised programming control pin, useful only in a production environment, and is used for low volt programming (See Section below on PGM). PIC chips come with the PGM interface enabled so that a PIC chip can be inserted into a production board and can be programmed by another device at the system level voltage. So you could have a situation where several PIC devices are connected to a master device and are re-programmable in the unit possibly over the web etc.
The important point is that a high voltage programmer such as a PICKit2/3 can always override the PGM interface and program the chip regardless of whether the PGM input is high or low and for single board use you set the PGM control inactive - this is a setting within the programming software such as MPLAB X etc. If the LVP mode is not turned off then the pin is not usable as normal I/O it can only be used for PGM signal.
The easiest way to use the programmer in-circuit is to use the board power but you have to stop the programmer generating output voltage and instead accept input voltage. The following screen shots show you how to do this in the MPLAB X IDE.
From the dashboard (lower left of the IDE),
First Click the spanner icon within the Dashboard to bring up the Properties window.
In the properties window select the PICkit3 category
Now in the right pane select the dropdown box labelled power and UN-click the checkbox saying:
Power Target circuit from PICki3:
Now the programmer will expect 5V from your target board. It will complain if power is not there.
The easiest way to program the device is using the MPLAB X IDE
Once you have either compiled a program using one of the compilers XC8, XC16 or XC32 etc. then hit the programming button to download the program into the PIC chip via the ICSP programmer PICkit3.
The programming button looks like this:
You can find out how to program a device using a pre-built hex file here.
PIC ICSP provides 6 connections from the pic ICSP programmer to your board as follows :
|1. VPP (or MCLRn)||Programming voltage (usually 13V).|
|2. Vcc||Power (usually 5V).|
|3. GND||Ground (zero volts).|
|4. PGD - Data||usual port and connection RB7.|
|5. PGC - Clock||usual port and connection RB6.|
|6. PGM - LVP enable||usual port and connection RB3/RB4.|
The above are PICkit3 pinouts.
Note: With the connections made in this order on the connector it will not matter if the connector is placed the wrong way round as GND and VCC are then applied to clock and data. If VCC and GND had been at opposite ends of the connector then there would be a problem.
Vpp connects to the reset input of the pic microcontroller labelled MCLR. During programming or verify this signal is raised to the programming voltage (13.5V) - or VCC+3.5V. This signals to the microcontroller that programming/verification is about to start and for older parts, supplies current.
Note: Older pic micros used this line to directly power the programming circuit that updates the Flash memory. So this connection had to supply some current. With the newer parts that allow LVP (Low Volt programming) the programming voltage is generated internally so the Vpp signal from the pic ICSP is only used as an indicator i.e. it doesn't have to supply current.
This connection may supply power to your board - usually using a 5V regulator (probably a 7805). This is ok for some use as you can develop a prototype board without needing any other power supply (just a power brick that plugs into the pic programmer circuit).
The only problem with it is that the programmer circuit is not designed for your circuit (does it have a heatsink) and it can also introduce noise to your circuit. If the programmer uses a 78L05 then you will only get 100mA maximum current output.
The ground reference - 0V.
These are the signals that do the work. Data (PGD) and clock (PGC) transmit data to the pic micro. First data is sent either high or low voltage (0/1). After a suitable time the clock is strobed low to high - rising edge clocking the data into the microcontroller.
PGD is also the line driven by the pic micro during verify i.e. it is bi-directional.
You do not need to worry about this pin - it is for Low Volt Programming (see below).
The purpose of this pin (on the ICSP connection) is to hold PGM low so the microcontroller does not enter LVP mode. It will usually be done using a pull down resistor e.g. 10k.
Note: If you program the microcontroller with LVP mode off then this signal will have no effect.
Note: PIC microcontrollers shipped with LVP enabled - so if you use a brand new chip you can use it in LVP mode. The only way to change the mode is by using a high voltage programmer.
It is there in case you use a device that is enabled for LVP - low volt programming. Basically when you use a new device that has never been programmed before LVP programming is enabled by default (p58, p148 - 16F88 datasheet DS30487C) so the resistor holds LVP mode off (low). This is implied in other datasheets and not specifically stated e.g. for the 18F2550.
However in MPLABX If you program the chip using a project file (from the on site projects) it is turned off anyway because I turned it off in MPLABX project settings. Once programmed off it is never turned on again unless you change it in a compiler project setting.
You can forget about PGM especially if you have programmed the chip for the 1st time using a high-volt programmer (e.g. pickit3). Remember you can always program the device regardless of the LVP setting using a high-volt programmer i.e. LVP is an additional feature. If the LVP mode is not turned off then the pin is not usable as normal I/O it can only be used for the PGM signal - which is why you really want to turn it off.
The purpose of LVP is to allow complete programming using only Vcc i.e. 5V and no higher voltage and that means you don't have to have a dedicated power supply voltage e.g. 12 V to program the device. i.e. you could program multiple devices on a board from one central microcontroller using LVP.
The actual LVP control is in the CONFIG1 register ( p130 16F88 datasheet DS30487C - probably different for other devices) so it is either set in the IDE (MPLABX etc.) or using a #pragma directive (see your compiler documentation).
Note: You can only program the LVP bit off using a high volt programmer.
Using LVP means you do not need a bootloader so valuable program memory is saved - but you have to arrange the hardware to do it..
Note that the diagram from pic ICSP application note 'DS33023A' specifically goes out of its way to not design it for you saying RB6 and RB7 should be isolated but this depends on your circuit! This is not very helpful so I have included the circuit I use on my development board (See the diagram shown earlier):
To ensure you can program and verify correctly two 10k resistors isolate the programmer (and RB6 and RB7) from the rest of the circuit i.e. they stop signals at the other side from interfering with RB6 and RB7 during programming. If you don't use the isolation resistors then loading or driving the pins can stop programming all together.
For example if you put an LED on RB6 (PGD) that draws 20mA when on. The output voltage (when the output is on) will be pulled so low that the pic ICSP programmer will not be able to read back the desired voltage i.e. it will give a verification failure.
This method is useful for devices with large pinouts but if you use a smaller device you may want to use the programming pins for driving LEDs i.e. large current output and this will load the programming pins PGD and PCK too much. For instance when using a 12F675 with 8 pins it is better to move the device on a solderless breadboar (if these pins are loaded). Here's an example schematic of that solution (see 12F675 Calibration Schematic - you wire up a small solderles breadboard with that layout)..
Click PIC ICSP Setup for more details on how to setup your ICSP system.
Click PIC Parallel Port Programmer for a Parallel port (legacy) PIC ICSP programmer project schematic.
The Arduino shiftOut() function can simply control many different serial interfaced chips. Find out how it works and how fast it operates.
A tutorial on using the ADS1115 precision 16 bit ADC for low power use.
Learn how to use the TP4056 properly. There's a right, and a wrong way, to use it to safely charge Lithium Ion batteries.
The MCP4922 chip is an SPI interfaced 12 bit DAC but how fast can it go? Find out here.
The MCP4725 chip is a 12 bit DAC with memory that outputs voltage that you can use for many dfferent purposes. Find out what they are in this page.
The MCP4728 chip is a four channel 12 bit DAC, with memory that outputs voltage that you can use for calibration, anywhere you want a fixed voltage.