Sie sind auf Seite 1von 17

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.

What is PIC ICSP?


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.

Note: [Advanced topic] I said above that it is the only way of programming a PIC
chip (using ICSP). This is true for all devices the 1st time that they are programmed.
However most PIC chips, bigger ones anyway, are capable of self programming
without using a programmer and if you program the chip with a bootloader then you
can upload data through any serial interface and re-program the rest of the chip. This
is the method used in the Arduino and can also be used with PIC chips.

How does the hex file get into to the


microcontroller?
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).

Note: Older programmers that are labelled Serial or Parallel both send serial data to
the PIC microcontroller through the PIC ICSP circuit. The 'Serial' or 'Parallel'
description refers only to the interface used from the PC to the PIC ICSP circuit.
Modern programmers such as the PicKit2/3 use a USB port. Again, a USB programmer
is merely referring to the PC interface and the output at the ICSP connector is exactly
the same as all the others.

PIC ICSP Circuit : PICKit 3


Connections
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: This is for the 16F877 and other 40 pin chips that have the same pinout for the
ICSP connector e.g. 18F2550 (or at least MCLR at top left and PGD and PGC at top
right).

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.
Here a PIC ICSP and full reset circuit :

Notes on the above circuit:


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.

ICSP Connections Description


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.

Using Board power with MPLAB X


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.

Microchip ICSP
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 Signals


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.

Note: The above ICSP signals are pin-ordered in the


same way as the standard PicKit2/3 = good!

VPP Signal (Signal a programming action)


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.

VDD/VCC Signal (Power)


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.

GND Signal
The ground reference - 0V.

PGC and PGD Signals (Clock and Data)


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.

PGM Signal (Low volt programming signal)


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.

Notes on the LVP (PGM) pin


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.

What is LVP for?

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.

Note: There are other ways to program on-board-chips e.g. by using a bootloader.


See the bootloader discussion - in short you use a high-volt programmer to load a
small program that listens to a port for a short while - if a code is received then it
enters programming mode listening for received data and programming that into the
program area of the device, A port can be any comms interface e.g. USB,ethernet,
SPI,I2C but is more commonly RS232. This method is used for many systems
commonly popular in Arduino and PICAxe.

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..

What circuit do you need on your target board?


Isolation of the ICSP PIC signals
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.
In-Circuit Serial Programming (ICSP) with the ME Labs Serial
Programmer or U2/USB Programmer
Our programmers may be used for in-circuit serial programming of serial programmable PI
expansion header J3.  The U2 programming header is detailed below.  Our other programm
pin-out.

If you're designing a PCB or circuit for ICSP, read the considerations below.  At the bottom
guide for connecting a board that is already equipped with a 10-pin header that matches o
Experimenter Board, for example.)
PIN SIGNAL
#
1 +5V always on (It is not recommended that you use this supp
Current capability is limited.)
2 Programming Voltage (Vpp) - Connect to MCLR/Vpp pin on
3 Reserved - do not connect
4 Switched Vdd (This pin should not be used to power your tar
target PICmicro only when one of our programming adapters
5 Reserved - do not connect
6 Programming Data - Connect to PGD or ICSPDAT on the tar
7 Reserved - do not connect
8 Programming Clock - Connect to PGC or ICSPCLK on the ta
9, Ground - A ground connection to your target board is require
10

Design considerations for ICSP-capable circuits  (Refer to schematic diagram below.)

1. If possible, dedicate the Programming Clock and Data pins to ICSP.  If you must also use thes
your board, some thought should be given to the type of hardware that is connected.  The best case
for normally-open, pushbutton inputs.  As long as you don't push the buttons while programming, the
all.

If loads are connected to the clock and data lines, they must not interact with the clock and data signa
problems.  High-impedance loads are usually ok.  LEDs with current-limiting resistors are less desirab
problems.

You should always prototype and test the ICSP connections before sending your PCB design out for

2.  The MCLR pin on the PIC will be driven to approximately 13V during programming.  This rai
that your circuit must allow 13V on the pin.  Don't connect the pin directly to the Vdd rail.  The second
circuit may need to be protected from this voltage.  If 13V on the MCLR pin might put at risk other com
diode in series with the RESET pullup to keep the 13V off of the Vdd line.
  
3.  Configure MCLR as a RESET pin if possible.  The programmer will attempt to reset the target device at t
process.  If the MCLR pin is configured as an input, the programmer may have problems putting the chip into p
problematic if the target has been previously programmed and is using the programming clock or data lines as

In some situations, there just aren't enough pins to allow the use of a RESET.  Your project will requi
input.  This is common on small, 8-pin PIC MCUs.  In these cases, it helps to set the clock and data p
at the beginning of your code.  This will allow you to cycle power to the part and start the programmin
executing.

In a PICBASIC PRO program intended for the PIC12F675, you might start with:

TRISIO = $FF   ' set all pins to inputs


PAUSE 1000     ' wait a second

This can make reprogramming much easier to accomplish when the programmer has no means to re
 
4.  Make sure the "low-voltage programming" pin is pulled to ground.  Low-voltage programming is not u
should always be disabled in the configuration settings.  Even so, the low-voltage programming pin (labeled P
ground when programming.  If it is left floating or in a high condition, it may interfere with the programming pro
pull the pin low when designing a board for ICSP.  For most 16F series parts, RB3 doubles as the PGM pin.  O
needs to be low.  Notable exceptions are the 16F62x and 16F64x family, which need RB4 to be pulled low.

5.  Always connect every available power pin to the appropriate power or ground source.  Man
pins that are labeled Vdd, Vss, AVdd, and AVss.  If even one of these pins is left unconnected, it may
This applies to analog supply pins even if you don't plan to use the analog functions.
 
6.  Use bypass capacitors between Vdd and Vss.  This is good practice in any case, but it's especially impo
of 0.1uF is the minimum recommended, but more is the norm.

7.  Connect a 5V supply to the Vdd pins on the PIC.  You can do this with the normal power suppl
external supply.  The ICSP header on the programmer has a 5V pin (pin-1) that can be used, but only
too much power.  The Vdd pin (pin-4) on the header shouldn't be used.  Such use will probably cause
and it's possible that it will damage the programmer hardware.

If your board is designed to run at a lower supply voltage like 3.3V and you can't safely connect 5V to
when erasing a flash PIC.  For some devices, a low-voltage erase option is available (Options > More
software).  Do not enable low-voltage programming in the configuration settings!  This setting has not
voltage for the PIC.

Some of the new PIC microcontrollers cannot by powered at 5V.  These parts usually require addition
programming.  See the following link for details:  PIC18FxxJ, PIC18FxxK, PIC24xJ, and dsPIC33FJ 3
Information

Note for PIC17C7xx:  These (practically obsolete) devices may also be programmed in-circuit. Howe
than are detailed here.  See the Microchip programming spec on these devices for more information.

 
The following schematic shows a typical ICSP connection for the PIC16F876
Connecting a programmer to a LAB-X board for in-circuit serial programming

Install the programming software according to the instructions included with your programm

Connect your programmer to the LAB-X board using a 10-pin ribbon cable (part# 10CAB).
to make the connection. The connectors on the programmer and LAB-X boards should line
connection.

If your LAB-X board has a ZIF socket, raise the lever. Insert the microcontroller into the soc
lower the lever to lock it into place. Make sure that the notch on the end of the microcontro
end of the socket.
If your LAB-X board does not have a ZIF socket, carefully line up the PICmicro microcontro
the socket and press it into place. Make sure the notch on the end of the microcontroller is
end of the socket.

Connect a 16VDC adapter (part# ACAD) to the programmer's power jack (not required for
may have different adapters for the programmer and LAB-X board. Make sure you power t
adapter.

Connect a 12VDC adapter (part# ACADX) to the LAB-X power jack. You must connect pow
order to program the microcontroller.

Run the programmer software on your computer and use the programming procedure to p
*The LED indicator on the EPIC will remain lit at half intensity when the EPIC is connected to the LAB-X board. The indica
programming operation is in progress.

How to Connect a In-Circuit Serial Programming (ICSP) Interface

Many microcontrollers come with In-Circuit Serial Programming (ICSP) connectors.

These connectors allow for in-circuit serial programming. This is programming in which data is moved to
a microcontroller serially and the microcontroller then executes these instructions.

Many microcontroller starter kits contain ICSP connectors.


One such starter kit is the Pickit 2 starter kit; its ICSP connector is shown below:

The ICSP connector is the 5-pin connector at the end of the development board. The PIC programmer
plugs directly into the ICSP connector, so that the microcontroller can be programmed.

The PIC programmer has a USB connector so that it can plug into the USB port of a computer. When
software is executed, the data runs from the computer, through the USB, into the PIC programmer,
through the ICSP connector, and then to the microcontroller, that executes the code.

However, in order for this to occur, the ICSP connector must be interfaced to the PIC programmer
properly, or else signals may be transmitted unclearly.

We will now discuss how to properly interface ICSP connectors, so that clear signals will be
communicated between the two. The biggest hang-up of ICSP connectors is that the serial
communication programming signals can get affected by the circuitry connected to the PIC. For this not
to happen, we must set up the connector properly to interface with the PIC programmer.

ICSP Pinout
Before we talk about how to interface the ICSP, you have to know each out the ICSP's pins, its pinout.
Below is a diagram of the pinout of the ICSP connector.

So, once again, with the ICSP, we have 5 connections: 5V (Vdd pin), Ground (Vss pin), Vpp (MCLR
pin), Data (PGD pin) and Clock (PGC pin).
If the clock or data pins are not able to send the correct signal, the PIC will not program properly and
you will get an error.

ICSP Connector Schematic


Now we will go over the actual schematic of how the ICSP connector should be interfaced with the PIC
programmer.

Below is a schematic of the Pickit 2 ICSP interface.

So the above schematic shows the ICSP connections. This is the correct schematic.

The schematic below will now show common errors when hooking up the ICSP connect to the
programmer.
This schematic shows all the possible connection issues to watch out for in connecting the ICSP.
Because of the way the ICSP feature works, you don't want to add any capacitance to the programming
connections, since this can delay the signals. Even the capacitance on the Vdd line should be precise,
as per the PIC programming specification. The PIC programmer actually cycles the Vdd line off and on
while sending the Vpp signal to the MCLR pin. This is done to put the PIC into programming mode. If
there is too much capacitance, it may slow the signal down and not meet the programming specs.

You also don't want to load down the clock or data signals. This is why capacitors should not be added
to these lines. Capacitors may slow, or load down, the signal and cause interference and signal
degradation. This why the capacitors are crossed out. The diodes connected to the Data and Clock
lines are also a mistake becasue the Data and Clock lines need two-way communication when
programming and verifying the part. A diode only allows one-way communication, so it cannot be
added. It's pretty obvious why they should not be on the line.

Less obvious is the diode between the MCLR reset circuit and the MCLR/Vpp pin. This is recommended
because the PIC programmer sends a high voltage signal to the Vpp line of around 12V-13.5V for a
short period of time. You don't want that signal feeding into your Vdd regulator. This is actually just a
safety precaution, though, because the current entering the MCLR pin is extremely small and the MCLR
pull-up resistor will knock it down to prevent any damage.

Another recommendation which is often not used are the series resistors on the PGC and PGC lines
between the PIC and the rest of the circuit. These resistors help isolate your circuit from the PGD and
PGC signals so that your circuit doesn't load down the PIC programmer. This is the most common area
where a problem may occur with ICSP. 100Ω resistors should not affect your circuit function but it
should be plenty of resistance to isolate the programmer.

You will notice that when you get your Pickit 2 starter kit board, it doesn't have any of the interfering
components (capacitors, etc.) that would cause signal issues but it also doesn't have the 100Ω
resistors. When using the starter kit for future projects, keep this in mind. Without the 100Ω resistors
added, it is possible that your circuitry tied to the PGC or PGD pin can prevent the PIC programmer
signals from getting through. By temporarily disconnecting those pins, the problem can be solved, but it
also can be solved by having these resistors in place.

Das könnte Ihnen auch gefallen