Witam, Lisu2005, poradziłeś sobie z PICKit2? Ja też używam kolona i wykorzystuję to oprogramowanie . Nie wiem co prawda jak zachowa się na Win8, ja sam pracuję na " siódemce Ultimate". W każdym razie mi działa bez zarzutu również pod MPLAB 8.63
PICKIT™ 2
PROGRAMMER-TO-GO
USER GUIDE
1 Introduction
The PICkit 2 Programmer-To-Go functionality allows a PIC MCU memory image to be downloaded
into the PICkit 2 unit for later programming into a specific PIC MCU. No software or PC is required to
program devices once the PICkit 2 unit is set up for Programming-To-Go. A USB power source for the
PICkit 2 is all that is needed.
Information in this guide covers:
USB Power for PICkit 2 Programmer-To-Go
Supported PIC MCU Devices
Memory Image Size Limitations
PICkit 2 Programmer-To-Go Wizard Walkthrough
LED Status Codes
© 2008 Microchip Technology Inc.
Page 1 of 15
PICkit™ 2 Programmer-To-Go Users Guide
2 USB Power for PICkit 2 Programmer-To-Go
The PICkit 2 unit hardware prevents it from being powered by the target through the ICSP connector
VDD pin. Therefore, it must be powered by a 5 Volt supply through the USB mini-B port at the top of
the PICkit 2. Many options exist for providing power. Some of these include:
2.1
Any available PC USB port or USB hub port. (No USB communication is necessary; it is only
used to provide power)
A USB host port on a portable device.
A USB power adapter or charger with a USB mini-B connector, either from an automotive
power jack or an AC wall plug.
A portable battery charger or power source for cell phones or other portable devices with USB
mini-B connector.
A custom battery pack that supplies regulated 5 Volts into the PICkit 2 USB port.
Power Requirements
The USB power source used should meet the following minimum criteria:
Is able to supply at least 100mA of current to the PICkit 2 unit.
Provides a steady, regulated 4.5 Volt to 5.5 Volt output at a load of 30mA to 100mA. A 160
Ohm resistor between the USB power output and ground gives a quick check of the low end
30mA voltage. Use a 47 Ohm resistor to test voltage at about 100mA.
Note: Most portable chargers/power devices with their own batteries will not give an indication
when their internal battery voltage gets low and the output drops below 4.5 Volts. Therefore
it is up the user to be sure the device’s battery has sufficient remaining capacity to power the
PICkit 2 above 4.5 Volts.
2.2
Example Battery-based Portable USB Power Sources
The following three products are shown only for the purpose of illustrating the options available for
portable PICkit 2 Programmer-To-Go USB power sources. They are neither specifically endorsed nor
recommended by Microchip Technology Inc.
Note: Any battery-based power sources should be disconnected from the PICkit 2 unit when it is
not in use. Otherwise, the PICkit 2 unit will drain the power source battery.
© 2008 Microchip Technology Inc.
Page 2 of 15
PICkit™ 2 Programmer-To-Go Users Guide
2.2.1
Bluegears b-mobile Emergency Cell Phone Charger
This device is a small mini-B USB power source that can recharge its internal battery cell from a USB
port via the PICkit 2 mini-B USB cable. The Bluegears part number is BG01145. The flip-open cover
reveals a USB mini-B male plug that connects directly to the PICkit 2 unit USB port.
Figure 2-1 shows the device recharging itself off a USB port.
FIGURE 2-1:
BLUEGEARS B-MOBILE
Informational Points:
Rechargeable via USB port.
Small form factor.
Connects directly to PICkit 2 unit.
Approximate retail cost: $10 (US)
Manufacturer website: www.bgears.com
Potential Limitations:
Supplied voltage may not be much higher than 4.5 Volts even
when fully charged. Not recommended for use when PICkit
Programmer-To-Go is powering the target VDD.
Does not “pass-through” USB data when connected to both a
USB port and a PICkit 2 unit.
Rechargeable battery is not replaceable.
Figure 2-2 shows the Bluegears b-mobile being used with a PICkit 2 unit for Programmer-To-Go
operation. For the curious, the white button turns on a built-in LED flashlight when pressed.
FIGURE 2-2:
B-MOBILE POWERING PICKIT 2 UNIT FOR PROGRAMMER-TO-GO OPERATION
© 2008 Microchip Technology Inc.
Page 3 of 15
PICkit™ 2 Programmer-To-Go Users Guide
2.2.2
Swiss Gear Portable USB iPod Battery Charger
This device runs off of 2 standard AA batteries. It has a USB ‘A’ connector that any USB cable can be
plugged into to provide power to a USB device. Simply plug in the included PICkit 2 USB cable
between this device and the PICkit 2 for portable power.
FIGURE 2-3:
SWISS GEAR PORTABLE USB BATTERY CHARGER
Informational Points:
Uses field-replaceable AA batteries.
Connects to PICkit 2 unit using PICkit 2 USB cable.
Approximate retail cost: $10 (US)
Does not suffer from the limitations of the Energi To Go
Manufacturer model number is GA-6227-15F00
Potential Limitations:
Do not confuse with a similar Swiss Gear product which plugs into an AC outlet to provide USB
power, and does not use batteries.
© 2008 Microchip Technology Inc.
Page 4 of 15
PICkit™ 2 Programmer-To-Go Users Guide
2.2.3
Energizer Energi To Go Mini USB Cell Phone Charger
This portable cell charger device runs off two standard AA batteries, and connects via a short cable to
the PICkit 2 unit. Several versions of this product are available. The one that may be used with PICkit
2 is part number CEL2MUSB for “mini USB” cell phones. Please note: 2 versions of the CEL2MUSB
product are available. These look for current draw from the connected USB device before turning
“on”, and one version has a high detection threshold that is not turned on by the small current draw of
PICkit 2. The version that works with PICkit 2 has textured lines on the battery cover button. The
version that does not work has a smooth button. See Figure 2-5 for reference.
FIGURE 2-4:
ENERGIZER ENERGI TO GO
Informational Points:
Uses field-replaceable AA batteries.
Provides between 5.0 and 5.5 Volt output;
suitable for powering a target from PICkit 2.
Approximate retail cost: $20 (US)
Manufacturer website: www.energitogo.com
Potential Limitations:
Looks for a battery by pulsing USB voltage
output, which may cause PICkit 2 reset
problems. See NOTE following.
Separate cable may be lost.
Only some units will work with PICkit 2. See
Figure 2-5.
FIGURE 2-5:
HOW TO TELL COMPATIBLE UNITS
© 2008 Microchip Technology Inc.
Page 5 of 15
PICkit™ 2 Programmer-To-Go Users Guide
Note: The Energizer Energi To Go product pulses the USB voltage output to detect a connected
device, as shown below. This may cause the PICkit 2’s internal microcontroller to
improperly reset, as its Brown Out Reset (BOR) is not enabled. The BOR is not enabled
because it interferes with PICkit 2 VDD error detection.
Symptoms of the PICkit 2 not coming out of reset properly are that it does not blink the
Target LED twice to show it is ready for programming. If this happens, unplug the Energi To
Go from the PICkit 2 and plug it back in. Once the blue LEDs on the Energi To Go are
blinking, it will not pulse VDD again when reconnected.
3 PICkit 2 Programmer-To-Go Supported Devices
All devices in the following families supported by the PICkit 2 Programmer software are supported for
Programmer-To-Go operation. However, due to limited memory in the PICkit 2 unit the ProgrammerTo-Go function is limited in the size of the memory image that can be loaded. Table 3-1 lists supported
device families and program memory limitations.
TABLE 3-1:
PROGRAMMER-TO-GO SUPPORTED DEVICES
2
Program Memory Size Limitations
Supported Families
Supported Parts
By Bytes
By Maximum Used Address
1
no limit
3
no limit
3
1
no limit
3
no limit
3
Baseline
All
Midrange
PIC18F
PIC18 J-Series
PIC18 K-Series
PIC24
All
1
All
1
All
1
All
1,4
All
dsPIC33
dsPIC30
dsPIC30 SMPS
All
1
All
1
All
Note 1:
2:
3:
4:
1,4
107264 bytes
111872 bytes
107264 bytes
106560 bytes
0x1A2FF
0x1B4FF
0x1A2FF
0x1157F
106560 bytes
103872 bytes
3
no limit
0x1157F
0x10E7F
3
no limit
Supports all family parts that are supported by the PICkit 2 Programmer application. See menu Help & gt; ReadMe for
a list of part supported by the application. Large memory parts are supported; what is limited is the size of the
program code that can be programmed by PICkit 2 Programmer-To-Go.
Device EEPROM data, UserIDs, and Configuration memory are taken into account in these size limitations. For
the sake of simplicity, only the Program Memory size determines if the memory image will fit. Different device
families have different memory overhead requirements affecting the maximum size limitation.
These families have no practical memory size limit as no devices in the family exceed the actual limit.
PICkit 2 Programmer-To-Go does not support using the Programming Executive (Enhanced ICSP) for these
devices. When using PICkit 2 Programmer-To-Go with these parts they will always be programmed using low level
ICSP methods.
© 2008 Microchip Technology Inc.
Page 6 of 15
PICkit™ 2 Programmer-To-Go Users Guide
3.1
Increasing the Memory for PICkit 2 Programmer-To-Go
The memory in the PICkit 2 unit available for Programmer-To-Go code storage may be doubled, thus
doubling the Program Memory size limitations shown in Table 3-1.
To expand the memory it is necessary to replace the two 24LC512 64KB EEPROMs on the PICkit 2
PCB at U3 and U4 with two 24LC1025-I/SM 128KB EEPROMs. This increases the total EEPROM
memory from 128KB to 256KB. It is important to note that the 24LC1025 EEPROMs require the A2
pin tied to VCC for proper operation per the datasheet. The PICkit 2 circuit board has the A2 pads
connected to ground. Therefore, when replacing the 24LC512s with 24LC1025s, the A2 pin must be
lifted so it does not contact the pad, and wired to the VCC pin of the part.
It is also necessary to modify the PICkit 2 Programmer INI file so the software is aware of the expanded
EEPROM space. Follow the steps below to complete and use a memory upgrade for your PICkit 2 unit:
1
Open the PICkit 2 case by prying it apart with a small flat screwdriver at the three indentations
along the seam at a long edge of the case.
2 Remove the 24LC512 serial EEPROMs at reference designators U3 and U4 from the PCB.
3 Lift the A2 pins of two 24LC1025-I/SM serial EEPROMs so they do not contact the circuit
board pad when placed on the PCB.
4 Solder the two 24LC1025 EEPROMs in place at U3 and U4 on the PICkit 2 PCB.
5 Solder a wire from the lifted A2 pin to the VCC pin on both 24LC1025 EEPROMs.
6 Ensure the PICkit 2 Programmer application is closed
7 Open the INI file (C:\Program Files\Microchip\PICkit 2 v2\PICkit2.ini) in Notepad or
another text editor.
8 Find the following line in the INI file:
9
PTGM: 0
Edit the value to 1 as shown below and save and close the INI file
PTGM: 1
The PICkit 2 Programmer application will now recognize and use the doubled memory for PICkit 2
Programmer-To-Go in the PICkit 2 unit. It will indicate the INI file edit was successful by displaying
the following text at the bottom of the Programmer-To-Go Wizard dialog “Welcome” screen:
“256K PICkit 2 upgrade support enabled.”
IMPORTANT
When replacing the PICkit 2 serial EEPROMs with 24LC1025 devices, the A2 pin of the 24LC1025
devices MUST be lifted and connected to the VCC pin or the 24LC1025 serial EEPROMS will not
work.
An upgraded 256KB PICkit 2 unit may be used successfully with PICkit 2 Programmer software that is
still configured for the default 128K, though any downloads will be limited as per a 128KB unit.
However, the reverse is not true. A PICkit 2 unit with the default 128KB may not be used successfully
with PICkit 2 Programmer software that is configured to use the 256KB upgrade, even if the code size
is within the 128KB limits.
3.1.1
Third Party Tools with Additional Memory and Custom Firmware
For third-party work-alike tools that support more memory, set INI value “PTGM: 2”. This removes the
software limit checking on memory size.
© 2008 Microchip Technology Inc.
Page 7 of 15
PICkit™ 2 Programmer-To-Go Users Guide
3.2
Other Limitations of PICkit 2 Programmer-To-Go
PICkit 2 Programmer-To-Go only supports the WRITE programming operation. It cannot be set up to
READ, VERIFY (only), or BLANK CHECK a device. Note that an ERASE can essentially be set up by
leaving all the PICkit 2 Programmer software buffers blank.
If Programmer & gt; Verify on Write is checked, then PICkit 2 Programmer-To-Go will verify the device it
programs. The PICkit 2 Programmer-To-Go verify is accomplished by calculating a checksum of the
programmed device and comparing it with an expected value.
3.2.1
PIC18F: Preserve EEPROM Data on Write Limitation
When programming a device with the EEPROM Data memory region “Enabled” checkbox unchecked,
PICkit 2 will write Program Memory, User IDs, and Configuration words but preserve the existing
EEPROM Data memory in the device.
For most PIC18F devices, this may be done with PICkit 2 Programmer-To-Go.
However, on some of the PIC18F devices the EEPROM Data memory must be read from the device
first, then reprogrammed with the other memory regions. For these devices PICkit 2 Programmer-ToGo does not support preserving the existing device EEPROM Data. An error will be given in the
software if the user attempts to set up such an operation for an affected device.
4 Setting up PICkit 2 for Programmer-To-Go Operation
Before downloading a memory image to PICkit 2 for Programmer-To-Go operation, the PICkit 2
Programmer software options and buffers should be set up as desired during Programmer-To-Go
operation. In fact, it is highly recommended to test programming a target device from the software first,
with all desired options, to ensure the device programs as expected before downloading an image to
Programmer-To-Go.
© 2008 Microchip Technology Inc.
Page 8 of 15
PICkit™ 2 Programmer-To-Go Users Guide
4.1
Set Up Programming Data and Options
A checklist of steps includes:
1
Ensure the PIC MCU part number you wish to program is the active device.
Use the Device Family menu to select the proper family first. It must show up at the top of
the Device Configuration area of the PICkit 2 window. If a target part is not available to
connect to, select Programmer & gt; Manual Device Select. This allows the part number to be
selected from a combo-box.
2
Load the memory image to be programmed into the PICkit 2 buffers.
This may be done via File & gt; Import Hex or by a READ operation on an existing device.
3
Set the PICkit 2 Programmer software options as desired.
The following options affect Programmer-To-Go operation. For detailed information on an
option, please consult the PICkit 2 User’s Guide via Help & gt; PICkit 2 User’s Guide
Programmer & gt; Verify on Write
Programmer & gt; Hold Device in Reset
Tools & gt; Enable Code Protect
Tools & gt; Enable Data Protect
Tools & gt; Use VPP First Program Entry
Tools & gt; Fast Programming
The “VDD PICkit 2” device VDD box determines the provided VDD voltage, if PICkit 2
will power the device.
4
4.2
Test programming on a target device from the PICkit 2 Programmer software.
The Programmer-To-Go Setup Wizard
Once the memory image and programming options for intended target device are set up and tested, start
the Programmer-To-Go Setup Wizard via Programmer & gt; PICkit 2 Programmer-To-Go…
The wizard dialog will open to the “Welcome” screen. Click Next & gt; to go to the “Programmer Settings”
screen.
© 2008 Microchip Technology Inc.
Page 9 of 15
PICkit™ 2 Programmer-To-Go Users Guide
4.2.1
Programmer Settings Screen
The Programmer Settings screen allows the user to verify the memory image buffer settings, and select
the target VDD power options to be used. An example is shown in Figure 4-1.
Buffer Settings
Device:
Shows the selected target device. OSCCAL and BandGap values will be
preserved on applicable devices.
Buffer data source:
Displays the source of the current buffer memory image to be used.
Code Protect:
Data Protect:
Displays whether the device will be programmed with protection options
enabled or not. If these options are not set in the imported hex file, they may
be enabled via the Tools menu.
Memory Regions:
Indicates whether the entire device will be programmed, if device EEPROM Data
memory will be preserved, or if only EEPROM Data memory is to be written.
These options are determined the by the state of the Program Memory and
EEPROM Data “Enabled” checkboxes on the main application window.
Verify Device:
The device will be verified after programming by Programmer-To-Go if
Programmer & gt; Verify on Write is checked.
FIGURE 4-1:
WIZARD PROGRAMMER SETTINGS SCREEN
© 2008 Microchip Technology Inc.
Page 10 of 15
PICkit™ 2 Programmer-To-Go Users Guide
Power Settings
PICkit 2 Programmer-To-Go may optionally power the target device, though usually a target will have
its own power supply. It is recommended to use PICkit 2 Programmer-To-Go with a powered target
instead of powering it off PICkit 2.
Target has its own power supply:
Select this option if the target will not be powered from PICkit 2.
The minimum supported voltage for programming the device will
be displayed. If the device has a high Bulk Erase voltage but
supports a low voltage row erase method, a checkbox will be
present as shown in Figure 4-1. Check the box if the target VDD
will be below the voltage shown.
Power the target from PICkit 2:
Select this option to power the target from the PICkit 2 VDD pin.
The VDD voltage is set by the “VDD PICkit 2” Voltage box in
the main application window.
CAUTION
When powering a target from PICkit 2, ensure the USB power source provides sufficient Voltage and
current for programming the device. Depending on the power source used, PICkit 2 may not be able to
provide the desired VDD Voltage to the target. The maximum VDD the PICkit 2 can output is about
200 to 300mV below the USB power source voltage.
Target current and capacitance limitations are the same using Programmer-To-Go as for USB
operation. A maximum of 25mA is available to power the target, and target capacitance must not slow
the VDD rise time to longer than 500us.
Note: If the Low Voltage Row Erase method is used with a target device, code protected devices
cannot be programmed. Programming a protected device requires a Bulk Erase operation at or
above the given VDD threshold.
If all Programmer Settings shown in the dialog are appropriate, click Next & gt; .
4.2.2
Download to PICkit 2 Screen
This screen provides a summary of the settings from the previous screen, and indicates whether or not
Tools & gt; Fast Programming and Programmer & gt; Hold Device in Reset are enabled. For most situations,
both these options should be enabled.
© 2008 Microchip Technology Inc.
Page 11 of 15
PICkit™ 2 Programmer-To-Go Users Guide
FIGURE 4-2:
WIZARD DOWNLOAD SETTINGS SCREEN
Click Download to store the memory image and settings in the PICkit 2 unit and place it in
Programmer-To-Go mode.
4.2.3
Download to PICkit 2 Complete
The screen in Figure 4-3 will appear when the download is complete. The PICkit 2 unit’s “Target” LED
should now be blinking twice in succession to indicate it is in Programmer-To-Go mode and ready to
program.
Disconnect the PICkit 2 from the PC USB port. When any USB power source is applied, the PICkit 2
unit will power up in Programmer-To-Go mode, indicated by the blinking “Target” LED.
Click Next & gt; to view a wizard screen giving examples of Programmer-To-Go error codes (covered in
Section 5 of this document) or click Exit to close the Wizard dialog.
© 2008 Microchip Technology Inc.
Page 12 of 15
PICkit™ 2 Programmer-To-Go Users Guide
FIGURE 4-3:
WIZARD DOWNLOAD COMPLETE SCREEN
5 Using PICkit 2 Programmer-To-Go
To use PICkit 2 Programmer-To-Go to program a target device once it has been set up, follow the steps
below.
1
Connect a USB power source as discussed in Section 2 of this document to the PICkit 2 unit.
2
Ensure the PICkit 2 “Power” LED is lit, and the “Target” LED is blinking twice in
succession to indicate the unit is in Programmer-To-Go mode and ready to program.
3
Connect the PICkit 2 unit ICSP connector to the target. Ensure the target is powered
properly if not powering from PICkit 2.
4
Press the PICkit 2 pushbutton to begin programming.
During the programming operation the PICkit 2 “Busy” LED will remain lit continuously. The “Target”
LED will light if powering from PICkit 2, but will remain off if the target has its own power supply.
When the programming operation is complete, the PICkit 2 unit will provide feedback on the operation
via the unit LEDs. See table 5-1 for a list of display codes.
© 2008 Microchip Technology Inc.
Page 13 of 15
PICkit™ 2 Programmer-To-Go Users Guide
FIGURE 5-1:
PROGRAMMER-TO-GO PROGRAMMING OPERATION FEEDBACK CODES
LED States
Interpretation
Target LED (Yellow)
Busy LED (Red)
Code
Description
2 blinks in succession:
Off
Success / Ready
Continuous Rapid
Blinking:
VDD / VPP Error
Off
Off
Off
Off
2 blinks in succession:
3 blinks in succession:
4 blinks in succession:
Device ID Error
Verify Error
Internal Error
No errors were encountered during the
programming operation. PICkit 2
Programmer-To-Go is ready to program
again.
PICkit 2 was unable to set the VDD or VPP
voltage to the expected value. If PICkit 2 is
not providing VDD, then the error must be a
VPP error. See Chapter 3 of the PICkit 2
Users Guide for VDD and VPP information.
PICkit 2 received an unexpected
Device ID from the target. Ensure the
target part matches that selected when
PICkit 2 Programmer-To-Go was set
up. May indicate a bad ICSP
connection preventing PICkit 2 from
communicating with the target.
Not applicable to Baseline devices.
The target did not Verify successfully
after programming. Ensure the target
VDD meets the minimum required.
With Baseline devices, this error may
indicate ICSP communication
problems.
An unexpected internal ProgrammerTo-Go error occurred. If it happens a
second time, try downloading to the
PICkit 2 again.
To clear an error code, press the PICkit 2 pushbutton to return to the “Ready” state.
CAUTION
When the “Target” LED blinks, approximately 2 Volts will appear on the PICkit 2 ICSP connector
VDD pin. As the minimum target VDD allowed for PICkit 2 operation is 2.5 Volts, and the PICkit 2
VDD output contains a diode to prevent backpowering from the target VDD, this situation is not a
concern.
However, when PICkit 2 is set up to provide VDD to the target, the target will see the 2 Volt pulses
while the LED is blinking. Ensure this will not cause a problem for the target. If a short or heavy load
exists on the VDD signal when PICkit 2 is connected and blinking it may cause a VDD Error.
Disconnect the PICkit 2 from the target and clear the error by pressing the pushbutton.
© 2008 Microchip Technology Inc.
Page 14 of 15
PICkit™ 2 Programmer-To-Go Users Guide
5.1
Exiting Programmer-To-Go Mode
To exit a PICkit 2 unit from Programmer-To-Go mode, plug into a PC USB port and connect to (use) the
unit with either the PICkit 2 Programmer software, PK2CMD, or MPLAB IDE.
In the PICkit 2 Programmer software, use Tools & gt; Check Communications to connect to a PICkit 2 unit.
Note: Programmer-To-Go mode cannot be exited while the Busy LED is blinking to indicate an
error. Press the pushbutton to clear the error before attempting to connect.
© 2008 Microchip Technology Inc.
Page 15 of 15
Low Pin Count Demo Board
User’s Guide
© 2005 Microchip Technology Inc.
DS51556A
Note the following details of the code protection feature on Microchip devices:
•
Microchip products meet the specification contained in their particular Microchip Data Sheet.
•
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•
Microchip is willing to work with the customer who is concerned about the integrity of their code.
•
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,
RELATED TO THE INFORMATION, INCLUDING BUT NOT
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,
MERCHANTABILITY OR FITNESS FOR PURPOSE.
Microchip disclaims all liability arising from this information and
its use. Use of Microchip’s products as critical components in
life support systems is not authorized except with express
written approval by Microchip. No licenses are conveyed,
implicitly or otherwise, under any Microchip intellectual property
rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
PICMASTER, SEEVAL, SmartSensor and The Embedded
Control Solutions Company are registered trademarks of
Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Linear Active Thermistor,
MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM,
PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo,
PowerMate, PowerTool, rfLAB, rfPICDEM, Select Mode,
Smart Serial, SmartTel, Total Endurance and WiperLock are
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2005, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
Microchip received ISO/TS-16949:2002 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro® 8-bit MCUs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
DS51556A-page ii
© 2005 Microchip Technology Inc.
LOW PIN COUNT DEMO BOARD
USER’S GUIDE
Table of Contents
Preface ........................................................................................................................... 1
Chapter 1. Low Pin Count (LPC) Demo Board Overview
1.1 Introduction ..................................................................................................... 7
1.2 Highlights ........................................................................................................ 7
1.3 Devices Supported by the LPC Demo Board ................................................. 7
1.4 LPC Demo Board Overview ........................................................................... 8
1.5 Running the PICkit™ 2 Flash Starter Kit Default Demonstration ................... 8
Chapter 2. Mid-Range PICmicro® Architectural Overview
2.1 Introduction ..................................................................................................... 9
2.2 Memory Organization ................................................................................... 10
2.3 Instruction formats ........................................................................................ 10
2.3.1 Assembler Basics ...................................................................................... 11
Chapter 3. LPC Demo Board Lessons
3.1 Introduction ................................................................................................... 13
3.2 LPC Demo Board lessons ............................................................................ 13
3.2.1 Lesson 1: Hello World (Light a LED) ....................................................................... 14
3.2.2 Lesson 2: Delay Loop (Blink a LED) ....................................................................... 15
3.2.3 Lesson 3: Rotate (Move the LED) ........................................................................... 17
3.2.4 Lesson 4: Analog-to-Digital ..................................................................................... 19
3.2.5 Lesson 5: Variable Speed Rotate ........................................................................... 22
3.2.6 Lesson 6: Switch Debouncing ................................................................................ 23
3.2.7 Lesson 7: Reversible Variable Speed Rotate ......................................................... 25
3.2.8 Lesson 8: Function Calls ........................................................................................ 26
3.2.9 Lesson 9: Timer0 .................................................................................................... 27
3.2.10 Lesson 10: Interrupts ............................................................................................ 29
3.2.11 Lesson 11: Indirect Data Addressing .................................................................... 31
3.2.12 Lesson 12: Look-up Table (ROM Array) ............................................................... 33
Appendix A. Hardware Schematics
A.1 Introduction .................................................................................................. 37
Worldwide Sales and Service .................................................................................... 38
© 2005 Microchip Technology Inc.
DS51556A-page iii
Low Pin Count Demo Board User’s Guide
NOTES:
DS51556A-page iv
© 2005 Microchip Technology Inc.
LOW PIN COUNT DEMO
BOARD USER’S GUIDE
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most up-to-date information on development tools, see the MPLAB® IDE on-line help.
Select the Help menu, and then Topics to open a list of available on-line help files.
INTRODUCTION
This chapter contains general information that will be useful to know before using the
Low Pin Count (LPC) Demo Board. Items discussed in this chapter include:
•
•
•
•
•
•
•
About this Guide
Warranty Registration
Recommended Reading
Troubleshooting
The Microchip Web Site
Development Systems Customer Notification Service
Customer Support
DOCUMENT LAYOUT
This document describes how to use the Low Pin Count Demo Board User’s Guide as
a development tool to emulate and debug firmware on a target board. The manual
layout is as follows:
• Chapter 1. “Low Pin Count (LPC) Demo Board Overview” – An overview of
Microchip’s Low Pin Count Demo Board.
• Chapter 2. “Mid-Range PICmicro® Architectural Overview” – An overview of
the Mid-range PICmicro® Architecture.
• Chapter 3. “LPC Demo Board Lessons” – Contains a variety of lessons that
demonstrate how to utilize and experiment with the Low Pin Count Demo Board.
© 2005 Microchip Technology Inc.
DS51556A-page 1
Low Pin Count Demo Board User’s Guide
CONVENTIONS USED IN THIS GUIDE
This manual uses the following documentation conventions:
DOCUMENTATION CONVENTIONS
Description
Arial font:
Italic characters
Initial caps
Quotes
Underlined, italic text with
right angle bracket
Bold characters
N‘Rnnnn
Text in angle brackets & lt; & gt;
Courier font:
Plain Courier
Represents
Referenced books
Emphasized text
A window
A dialog
A menu selection
A field name in a window or
dialog
A menu path
MPLAB® IDE User’s Guide
...is the only compiler...
the Output window
the Settings dialog
select Enable Programmer
“Save project before build”
A dialog button
A tab
A number in verilog format,
where N is the total number of
digits, R is the radix and n is a
digit.
A key on the keyboard
Click OK
Click the Power tab
4‘b0010, 2‘hF1
Italic Courier
Sample source code
Filenames
File paths
Keywords
Command-line options
Bit values
Constants
A variable argument
Square brackets [ ]
Optional arguments
Curly brackets and pipe
character: { | }
Ellipses...
Choice of mutually exclusive
arguments; an OR selection
Replaces repeated text
Represents code supplied by
user
DS51556A-page 2
Examples
File & gt; Save
Press & lt; Enter & gt; , & lt; F1 & gt;
#define START
autoexec.bat
c:\mcc18\h
_asm, _endasm, static
-Opa+, -Opa0, 1
0xFF, ‘A’
file.o, where file can be
any valid filename
mcc18 [options] file
[options]
errorlevel {0|1}
var_name [,
var_name...]
void main (void)
{ ...
}
© 2005 Microchip Technology Inc.
Preface
WARRANTY REGISTRATION
Please complete the enclosed Warranty Registration Card and mail it promptly.
Sending in the Warranty Registration Card entitles users to receive new product
updates. Interim software releases are available at the Microchip web site.
RECOMMENDED READING
This user’s guide describes how to use the Low Pin Count (LPC) Demo Board. Other
useful documents are listed below. The following Microchip documents are available
and recommended as supplemental reference resources.
Readme for Low Pin Count (LPC) Demo Board
For the latest information on using the Low Pin Count (LPC) Demo Board, read the
“Readme for Low Pin Count Demo Board.txt” file (an ASCII text file) in the
PICkit 2 installation directory. The Readme file contains update information and known
issues that may not be included in this user’s guide.
Readme Files
For the latest information on using other tools, read the tool-specific Readme files in
the Readmes subdirectory of the MPLAB IDE installation directory. The Readme files
contain update information and known issues that may not be included in this user’s
guide.
PICkit™ 2 Microcontroller Programmer User’s Guide (DS51553)
Consult this document for instructions on how to use the PICkit 2 Microcontroller
Programmer hardware and software.
PIC16F685/687/689/690 Data Sheet (DS41262)
Consult this document for information regarding the PIC16F685/687/689/690 20-pin
Flash based, 8-bit CMOS Microcontroller device specifications.
MPLAB® IDE, Simulator, Editor User’s Guide (DS51025)
Consult this document for more information pertaining to the installation and features
of the MPLAB Integrated Development Environment (IDE) Software.
© 2005 Microchip Technology Inc.
DS51556A-page 3
Low Pin Count Demo Board User’s Guide
THE MICROCHIP WEB SITE
Microchip provides online support via our web site at www.microchip.com. This web
site is used as a means to make files and information easily available to customers.
Accessible by using your favorite Internet browser, the web site contains the following
information:
• Product Support – Data sheets and errata, application notes and sample
programs, design resources, user’s guides and hardware support documents,
latest software releases and archived software
• General Technical Support – Frequently Asked Questions (FAQs), technical
support requests, online discussion groups, Microchip consultant program
member listing
• Business of Microchip – Product selector and ordering guides, latest Microchip
press releases, listing of seminars and events, listings of Microchip sales offices,
distributors and factory representatives
DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICE
Microchip’s customer notification service helps keep customers current on Microchip
products. Subscribers will receive e-mail notification whenever there are changes,
updates, revisions or errata related to a specified product family or development tool of
interest.
To register, access the Microchip web site at www.microchip.com, click on Customer
Change Notification and follow the registration instructions.
The Development Systems product group categories are:
• Compilers – The latest information on Microchip C compilers and other language
tools. These include the MPLAB C18 and MPLAB C30 C compilers; MPASM™
and MPLAB ASM30 assemblers; MPLINK™ and MPLAB LINK30 object linkers;
and MPLIB™ and MPLAB LIB30 object librarians.
• Emulators – The latest information on Microchip in-circuit emulators.This
includes the MPLAB ICE 2000 and MPLAB ICE 4000.
• In-Circuit Debuggers – The latest information on the Microchip in-circuit
debugger, MPLAB ICD 2.
• MPLAB® IDE – The latest information on Microchip MPLAB IDE, the Windows®
Integrated Development Environment for development systems tools. This list is
focused on the MPLAB IDE, MPLAB SIM simulator, MPLAB IDE Project Manager
and general editing and debugging features.
• Programmers – The latest information on Microchip programmers. These include
the MPLAB PM3 and PRO MATE® II device programmers and the PICSTART®
Plus and PICkit® 1 development programmers.
DS51556A-page 4
© 2005 Microchip Technology Inc.
Preface
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
•
•
•
•
•
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Technical Support
Development Systems Information Line
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
In addition, there is a Development Systems Information Line which lists the latest versions of Microchip’s development systems software products. This line also provides
information on how customers can receive currently available upgrade kits.
The Development Systems Information Line numbers are:
1-800-755-2345 – United States and most of Canada
1-480-792-7302 – Other International Locations
DOCUMENT REVISION HISTORY
Revision A (May 2005)
• Initial Release of this Document.
© 2005 Microchip Technology Inc.
DS51556A-page 5
Low Pin Count Demo Board User’s Guide
NOTES:
DS51556A-page 6
© 2005 Microchip Technology Inc.
LOW PIN COUNT DEMO BOARD
USER’S GUIDE
Chapter 1. Low Pin Count (LPC) Demo Board Overview
1.1
INTRODUCTION
This chapter introduces the Low Pin Count (LPC) Demo Board and describes the LPC
Demo Board features.
1.2
HIGHLIGHTS
This chapter discusses:
• Devices supported by the LPC Demo Board
• The LPC Demo Board Overview
• Running the PICkit™ 2 Starter Kit Default Demonstration
1.3
DEVICES SUPPORTED BY THE LPC DEMO BOARD
For a list of supported devices, see the LPC Demo Board README file on the PICkit™ 2
Starter Kit CD-ROM.
8-pin DIP Flash Devices:
PIC12F508
PIC12F509
PIC12F510
PIC12F629
PIC12F675
PIC12F635
PIC12F683
14-pin DIP Flash Devices:
PIC16F505
PIC16F506
PIC16F630
PIC16F676
PIC16F684
PIC16F688
20-pin DIP Flash Devices:
PIC16F685
PIC16F687
© 2005 Microchip Technology Inc.
PIC16F689
PIC16F690
PIC16F785
DS51556A-page 7
Low Pin Count Demo Board User’s Guide
1.4
LPC DEMO BOARD OVERVIEW
The Low Pin Count Demo Board Works with the PICkit™ 2 Microcontroller
Programmer to help the user get up to speed quickly using PICmicro® microcontrollers.
This user’s guide is written in the form of Lessons intended for a person with some
exposure to assembly language but has never used a PICmicro® microcontroller.
The LPC Demo Board overview is shown in Figure 1-1.
FIGURE 1-1:
LPC DEMO BOARD
PICkit™ 2 Programming Header
14-pin Expansion
Header
20-pin
DIP Socket
Generous
Prototyping
Area
Potentiometer
Push Button
LEDs
1.5
RUNNING THE PICkit™ 2 STARTER KIT DEFAULT DEMONSTRATION
The Low Pin Count Demo Board comes preprogrammed with a demonstration program.
To use this program, connect the PICkit™ 2 Starter Kit to the PC’s USB port using the
USB cable. Start the PICkit™ 2 Microcontroller Programmer application and check the
target power box. The demo program will blink the four red lights in succession. Press
the Push Button Switch, labeled SW1, and the sequence of the lights will reverse. Rotate
the potentiometer, labeled RP1, and the light sequence will blink at a different rate. This
demo program is developed through the first 7 lessons in this guide.
DS51556A-page 8
© 2005 Microchip Technology Inc.
LOW PIN COUNT DEMO BOARD
USER’S GUIDE
Chapter 2. Mid-Range PICmicro® Architectural Overview
2.1
INTRODUCTION
This chapter describes the Mid-range PICmicro® Architectural Overview for the LPC
Demo Board.
SIMPLIFIED MID-RANGE PICmicro® BLOCK DIAGRAM
FIGURE 2-1:
INT
13
Flash
4k x 14
Program
Memory
8
Data Bus
Program Counter
RAM
256 bytes
File
Registers
8-Level Stack (13-bit)
Program 14
Bus
RAM Addr
9
Addr MUX
Instruction Reg
Direct Addr
Indirect
Addr
7
8
FSR Reg
Status Reg
8
3
Instruction
Decode and
Control
OSC1/CLKI
OSC2/CLKO
MUX
ALU
8
Timing
Generation
W Reg
Internal
Oscillator
Block
© 2005 Microchip Technology Inc.
DS51556A-page 9
Low Pin Count Demo Board User’s Guide
2.2
MEMORY ORGANIZATION
PICmicro® microcontrollers are designed with separate program and data memory
areas. This allows faster execution as the address and data busses are separate and
do not have to do double duty.
Data Memory is held in file registers. Instructions referring to file registers use 7 bits,
so only 128 file registers can be addressed. Multiple file registers are arranged into
“pages”. Two extra bits RP0 and RP1 (in the Status register) allow accessing multiple
pages. These two bits effectively become the top two bits of the file register address.
The additional pages may or may not be implemented, depending on the device.
Mid-range devices reserve the first 32 addresses of each page for Special Function
Registers (SFRs). SFRs are how the program interacts with the peripherals. The
controls and data registers are memory mapped into the SFR space. Addresses above
0x20 to the end of each page are General Purpose Registers (GPRs), where program
variables may be stored.
Some frequently used registers may be accessed from any bank. For example, the
Status register is always available no matter which bank is selected via the RP bits. The
last 16 bytes (0x70-0x7F) may also be accessed from any bank.
Program Memory is accessed via a 13-bit Program Counter (PC). The lower 8 bits are
accessible via SFR (PCL), and the upper 5 are at a PCLATH. See the
PIC16F685/687/689/690 Data Sheet’s (DS41262) Section on PCL and PCLATH for
more details on the PC. PCLATH becomes important when program memory size
exceeds 1k instructions, and also for the table look-up in Lesson 12.
Mid-range PICmicro® MCUs may be clocked by a number of different devices. Unless
otherwise noted, the lessons in this manual use the Internal Oscillator running at 4 MHz.
2.3
INSTRUCTION FORMATS
Most instructions follow one of three formats: Byte oriented instructions, Bit oriented
instructions and Literal instructions.
Byte instructions contain 7-bit data address, a destination bit, and 6-bit op code. The
data address plus the RP0 and RP1 bits create a 9-bit data memory address for one
operand. The other operand is the Working register (called W or Wreg). After the
instruction executes, the destination bit (d) specifies whether the result will be stored in
W or back in the original file register. For example:
ADDWF
data,f
adds the contents of Wreg and data, with the result going back into data.
Bit instructions operate on a specific bit within a file register. They contain 7 bits of data
address, 3-bit number and the remaining 4 bits are op code. These instructions may
set or clear a specific bit within a file register. They may also be used to test a specific
bit within a file register. For example:
BSF
STATUS,RP0
set the RP0 bit in the Status register.
Literal instructions contain the data operand within the instruction. The Wreg becomes
the other operand. Calls and GOTO’s use 11 bits as a literal address.
MOVLW'A'
Moves the ASCII value of ‘A’ (0x41) into Wreg.
DS51556A-page 10
© 2005 Microchip Technology Inc.
Mid-Range PICmicro® Architectural Overview
2.3.1
Assembler Basics
Numbers in the Assembler
Unless otherwise specified, the assembler assumes any numeric constants in
the program are hexadecimal (base 16). Binary (base 2), Octal (base 8), Decimal
(base 10), and ASCII coding are also supported.
Hexadecimal:
12 or 0x12 or H'12'
Decimal
.12 or D'12'
Octal
O'12'
Binary
B'00010010'
ASCII
A'c' or 'c'
Org (Origin)
Org tells the Assembler where to start generating code. Normally we start coding
at address ‘0000’, but it could be anywhere. Baseline devices have a Reset
vector at the last location in program memory, so it’s good practice to have a
GOTO instruction pointing to the beginning of the program.
End
End tells the assembler to stop assembling. There must be one at the end of the
program. It does not necessarily have to be at the end of the file, but nothing after
the end statement will be assembled.
Defining Data Memory Locations
There are three ways to name a location (see Example 2-1).
EXAMPLE 2-1:
DEFINING DATA MEMORY
#define Length
0x20
;c-like syntax
Length
0x20
;equate 0x20 with the symbol
0x20
;start a block of variables
;this will be at address 0x20
;this will be at address 0x21
;this is 2 bytes long, starting at
;address 0x22
;this will be at address 0x24
equ
cblock
Length
Width
Area:2
Girth
endc
Unless there is a reason to want a name to a specific location, the cblock/endc
method is preferred. The advantage is that as variables come and go through the
development process, the cblock keeps the block to a minimum. Using one of the other
methods, you may have to go back and find an unused location.
© 2005 Microchip Technology Inc.
DS51556A-page 11
Low Pin Count Demo Board User’s Guide
NOTES:
DS51556A-page 12
© 2005 Microchip Technology Inc.
LOW PIN COUNT DEMO BOARD
USER’S GUIDE
Chapter 3. LPC Demo Board Lessons
3.1
INTRODUCTION
The following lessons cover basic LPC Demo Board features. Refer to applicable
documents as needed. Any updates to the applicable documents are available on
Microchip’s web site.
The code and hex files are installed in C:\Microchip\PICkit 2 Lessons\. They
may also be found on the PICkit™ 2 CD-ROM under directory \PICkit 2 Lessons\.
3.2
LPC DEMO BOARD LESSONS
•
•
•
•
•
•
•
•
•
•
•
•
Lesson 1: Hello World (Light a LED)
Lesson 2: Delay Loop (Blink a LED)
Lesson 3: Rotate (Move the LED)
Lesson 4: Analog-to-Digital
Lesson 5: Variable Speed Rotate
Lesson 6: Switch Debounce
Lesson 7: Reversible Variable Speed Rotate
Lesson 8: Function Calls
Lesson 9: Timer0
Lesson 10: Interrupts
Lesson 11: Indirect Data Addressing
Lesson 12: Look-up Table (ROM Array)
© 2005 Microchip Technology Inc.
DS51556A-page 13
Low Pin Count Demo Board User’s Guide
3.2.1
Lesson 1: Hello World (Light a LED)
The first lesson shows how to turn on a LED. This is the PICmicro® microcontroller
version of “Hello World” and discusses the I/O pin structures.
New Instructions
BSF
Bit set
BCF
Bit clear
The LEDs are connected to I/O pins RC0 through RC3. When one of these I/O pins
drive high, the LED turns on. The I/O pins can be configured for input or output. On
start-up, the default is input. The TRIS bits use the convention of ‘0’ for output and ‘1’
for input. We want digital output so these must be configured.
EXAMPLE 3-1:
PICkit 2, LESSON 1: “HELLO WORLD”
; PICkit 2 Lesson 1 - 'Hello World'
;
#include & lt; p16F690.inc & gt;
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF &
_MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)
org 0
Start
BSF
STATUS,RP0
;select Register Page 1
BCF
TRISC,0
;make I/O Pin C0 an output
BCF
STATUS,RP0
;back to Register Page 0
BSF
PORTC,0
;turn on LED C0
GOTO
$
;wait here
end
Now lets look at the program that makes this happen.
;
Starts a comment. Any text on the line following the semicolon
is ignored.
#include
Brings in an include file defining all the Special Function
Registers available on the PIC16F690. Also, it defines valid
memory areas. These definitions match the names used in the
device data sheet.
__Config
Defines the Configuration Word. The labels are defined in the
p16F690.inc file. The labels may be logically ANDed
together to form the word.
Org 0
Tells the assembler where to start generating code. Code may
be generated for any area of the part. Mid-range PICmicro®
microcontroller devices start at address ‘0’, also called the
Reset vector.
BCF TRISC,0
Tells the processor to clear a bit in a file register. TRISC is the
Tri-state register for pin 0 of PORTC. A ‘1’ in the register
makes the pin an input; a ‘0’ makes it an output. We want to
make it an output, so the bit must be cleared.
BSF PORTC,0
Tells the processor to set pin 0 of PORTC. This will force the
I/O pin to a high condition turning on the LED.
GOTO $
Tells the processor to go to the current instruction.
For more information, refer to the I/O Ports Section of the PIC16F685/687/689/690
Data Sheet (DS41262).
DS51556A-page 14
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.2
Lesson 2: Delay Loop (Blink a LED)
The first lesson showed how to turn on a LED, this lesson shows how to make it blink.
While this might seem a trivial change from Lesson 1, the reasons will soon become
apparent.
New Instructions
CLRF
Clear file register
INCF
Increment file register
DECF
Decrement file register
INCFSZ
Increment file register, Skip next instruction if zero
DECFSZ
Decrement file register, Skip next instruction if zero
GOTO
Jump to a new location in the program
EXAMPLE 3-2:
Loop
BSF
BCF
GOTO
PICkit 2, LESSON 2: BLINK
PORTC,0
PORTC,0
Loop
;turn on LED C0
;turn off LED C0
;do it again
While adding a BCF instruction and making it loop will make it blink, it will blink so fast
you won’t see it. It will only look dim. That loop requires 4 instruction times to execute.
The first instruction turns it on. The second one turns it off. The GOTO takes two instruction times, which means it will be on for 25% of the time.
As configured, the PICmicro executes 1 million instructions per second. At this rate, the
blinking needs to be slowed down so that the blinking can be seen, which can be done
by using a delay loop.
Note:
© 2005 Microchip Technology Inc.
Counting cycles – Relating clock speed to instruction speed. The processor
requires 4 clocks to execute an instruction. Since the internal oscillator as
used in these lessons runs at 4 MHz, the instruction rate is 1 MHz.
DS51556A-page 15
Low Pin Count Demo Board User’s Guide
Increment or Decrement a File Register
The INCFSZ and DECFSZ instructions add or subtract one from the contents of
the file register and skips the next instruction when the result is zero. One use is
in the delay loop as shown in Example 3-3.
CLRF
Clears the counter location.
DECFSZ
Decrements the location, and if the result is zero, the next
instruction is skipped.
EXAMPLE 3-3:
DELAY LOOP
Short Loop
CLRF
Loop
DECFSZ
GOTO
Delay
Delay,f
Loop
Long Loop
CLRF
CLRF
Loop
DECFSZ
GOTO
DECFSZ
GOTO
Delay1
Delay2
Delay1,f
Loop
Delay2,f
Loop
The GOTO Loop (in Example 3-3) backs up and does it again. This loop takes 3
instruction times; one for the decrement and two for the GOTO (see note) and the
counter will force it to go around 256 times, which takes it a total of 768 instruction times
(768 μs) to execute.
Even that is still too fast for the eye to see. It can be slowed down even more by adding
a second loop around this one.
The inner loop still takes 768 μs plus 3 for the outer loop, but now it’s executed another
256 times, 771 * 256 = 197376 μs = 0.197s.
Note:
GOTO instructions take two instructions due to the pipelined design of the
processor. The processor fetches the next instruction while executing the
current instruction. When a program branch occurs, the fetched instruction
is not executed.
Open Blink.asm and build the lesson. Next, import the hex file into the PICkit 2 and
program the device. Note the LED now flashes at about a 2 Hz rate.
DS51556A-page 16
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.3
Lesson 3: Rotate (Move the LED)
Building on Lessons 1 and 2, which showed how to light up a LED and then make it
blink with a delay loop, this lesson adds rotation. It will light up DS4 and then shift it to
DS3, then DS2, then DS1 and back to DS4.
New Instructions
MOVLW
Loads Wreg with a literal value
MOVWF
Moves the contents of Wreg to a file register
MOVF
Moves the contents of a file register, either to Wreg or back
into the file register (see note)
RRF
Rotate file register right
RLF
Rotate file register left
Note:
Moving a file register to itself looks like a NOP at first. However, it has a
useful side effect in that the Z flag is set to reflect the value. In other words,
MOVF fileregister,f is a convenient way to test whether or not the
value is zero without affecting the contents of the Wreg.
Rotate Program Flow
•
•
•
•
First, initialize the I/O port and the Display,
Copy the Display variable to the I/O Port, then
Delay for a little while
Rotate the display
FIGURE 3-1:
ROTATE PROGRAM FLOW
Initialize I/O Port
Put Up Display
Delay
Rotate Display
Did it overflow?
Yes
No
Reset Display
© 2005 Microchip Technology Inc.
DS51556A-page 17
Low Pin Count Demo Board User’s Guide
Rotate
The rotate instructions (RRF or RLF) shift all the bits in the file register right or left by
one position, through the Carry bit. The Carry bit is shifted into the byte and receives
the bit shifted out of the byte. The Carry bit should be cleared before rotation so
unwanted bits are not introduced into the display byte. The Carry bit also indicates
when the display byte is empty. When it is, reinsert the ‘1’ at bit 3.
PICmicro MCUs have two rotate instructions: Rotate Left (RLF) and Rotate Right (RRF).
These instructions rotate the contents of a file register and Carry bit one place.
FIGURE 3-2:
ROTATE LEFT
Carry
EXAMPLE 3-4:
File Register
ROTATE EXAMPLE
Start
BSF
CLRF
BCF
MOVLW
MOVWF
STATUS,RP0
TRISC
STATUS,RP0
0x08
Display
;select Register Page 1
;make I/O PORTC all output
;back to Register Page 0
MainLoop
MOVF
MOVWF
Display,w
PORTC
;Copy the display to the LEDs
OndelayLoop
DECFSZ
GOTO
DECFSZ
GOTO
Delay1,f
OndelayLoop
Delay2,f
OndelayLoop
BCF
RRF
BTFSC
BSF
GOTO
DS51556A-page 18
;Delay .197S
STATUS,C
Display,f
STATUS,C
Display,3
MainLoop
;ensure the carry bit is clear
;Rotate Display right
;Did the bit rotate into the carry?
;yes, put it into bit 3.
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.4
Lesson 4: Analog-to-Digital
This lesson shows how to configure the ADC, run a conversion, read the analog voltage
controlled by the potentiometer (RP1) on the board, and display the high order 4 bits
on the display.
The PIC16F690 has an on board Analog-to-Digital Converter (ADC) with 10 bits of
resolution on any of 11 channels. The converter can be referenced to the device’s VDD
or an external voltage reference. The LPC Demo Board references it to VDD as
provided by the USB cable. The answer from the ADC is represented by a ratio of the
voltage to the reference.
ADC = V/VREF * 1023
Converting the answer from the ADC back to voltage requires solving for V.
V = ADC/1023 * VREF
Two of the three factors on the right side of the equation are constants and may be
calculated in advance. This eliminates the need to actually divide, but still requires fixed
or floating point multiply to solve the equation on the fly.
However, sometimes, such as when reading a sensor, calculating the voltage is only
the first step. There may be additional math to calculate the meaningful data from the
sensor. For example, when reading a thermistor, calculating the voltage is only the first
step on the way to getting the temperature.
There are other means to convert ADC values, including a straight table look-up or a
piece-wise linear interpolation. Each of these represents different speed/memory
trade-offs.
The schematic (Appendix A. “Hardware Schematics”) shows the wiper on the
potentiometer is connected to pin RA0 on the PIC16F690.
Here’s the checklist for this lesson:
• Configure PORTA as an analog input, TRISA & lt; 0 & gt; = 1, ANSEL & lt; 0 & gt; = 1
• Select clock scaling in ADCON1.
• Select channel, justification and VREF source in ADCON0.
© 2005 Microchip Technology Inc.
DS51556A-page 19
Low Pin Count Demo Board User’s Guide
3.2.4.1
ADCON1
ADCON1 selects the ratio between processor clock speed and conversion speed. This
is important because the ADC needs at least 1.6 μs per bit. Accuracy degrades if the
clock speed is too high. As the processor clock speed increases, an increasingly large
divider is necessary to keep the conversion speed. Four MHz is fastest at 8:1 ratio with
a conversion speed of 2 μs per bit. Refer to the “TAD vs. Device Operating
Frequencies” Table in the Analog-to-Digital Section of the PIC16F685/687/689/690
Data Sheet (DS41262) for recommended configurations.
REGISTER 3-1:
ADCON1 – A/D CONTROL REGISTER 1 (ADDRESS: 9Fh)
U-0
R/W-0
R/W-0
R/W-0
U-0
U-0
U-0
U-0
—
ADCS2
ADCS1
ADCS0
—
—
—
—
bit 7
bit 0
bit 7
Unimplemented: Read as ‘0’
bit 6-4
ADCS & lt; 2:0 & gt; : A/D Conversion Clock Select bits
000 = FOSC/2
001 = FOSC/8
010 = FOSC/32
x11 = FRC (clock derived from a dedicated internal oscillator = 500 kHz max)
100 = FOSC/4
101 = FOSC/16
110 = FOSC/64
bit 3-0
Unimplemented: Read as ‘0’
Legend:
R = Readable bit
U = Unimplemented bit, read as ‘0’
- n = Value at POR
DS51556A-page 20
W = Writable bit
‘1’ = Bit is set
‘0’ = Bit is cleared
x = Bit is unknown
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.4.2
ADCON0
ADCON0 controls the ADC operation. Bit 0 turns on the ADC module. Bit 1 starts a
conversion and bits & lt; 5:2 & gt; selects which channel the ADC will operate. VCFG bit & lt; 6 & gt;
selects the ADC reference, which may be either VDD or a separate reference voltage
on VREF. ADFM bit & lt; 7 & gt; selects whether the 10 bits are right or left justified in the 16 bits.
For purposes of this lesson, the ADC must be turned on and pointed to RA0. Choose
the internal voltage reference and 8TOSC conversion clock.
The ADC needs about 5 μs, after changing channels, to allow the ADC sampling
capacitor to settle. Finally, we can start the conversion by setting the GO bit in ADCON0.
The bit also serves as the DONE flag. That is, the ADC will clear the same bit when the
conversion is complete. The answer is then available in ADRESH:ADRESL.
This lesson takes the high order 4 bits of the result and copies them to the display LEDs
attached to PORTC.
See the Analog-to-Digital section in the PIC16F685/687/689/690 Data Sheet
(DS41262) for more details on the ADC module.
REGISTER 3-2:
ADCON0 – A/D CONTROL REGISTER (ADDRESS: 1Fh)
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ADFM
VCFG
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
bit 7
bit 0
bit 7
ADFM: A/D Result Formed Select bit
1 = Right justified
0 = Left justified
bit 6
VCFG: Voltage Reference bit
1 = VREF pin
0 = VDD
bit 5-2
CHS & lt; 3:0 & gt; : Analog Channel Select bits
0000 = Channel 00 (AN0)
0001 = Channel 01 (AN1)
0010 = Channel 02 (AN2)
0011 = Channel 03 (AN3)
0100 = Channel 04 (AN4)
0101 = Channel 05 (AN5)
0110 = Channel 06 (AN6)
0111 = Channel 07 (AN7)
1000 = Channel 08 (AN8)
1001 = Channel 09 (AN9)
1010 = Channel 10 (AN10)
1011 = Channel 11 (AN11)
1100 = CVREF
1101 = VP6
1110 = Reserved. Do not use.
1111 = Reserved. Do not use.
bit 1
GO/DONE: A/D Conversion Status bit
1 = A/D conversion cycle in progress. Setting this bit starts an A/D conversion cycle.
This bit is automatically cleared by hardware when the A/D conversion has completed.
0 = A/D conversion completed/not in progress
bit 0
ADON: A/D Enable bit
1 = A/D converter module is enabled
0 = A/D converter is shut off and consumes no operating current
Legend:
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as ‘0’
- n = Value at POR
‘1’ = Bit is set
‘0’ = Bit is cleared
© 2005 Microchip Technology Inc.
x = Bit is unknown
DS51556A-page 21
Low Pin Count Demo Board User’s Guide
3.2.5
Lesson 5: Variable Speed Rotate
Lesson 5 combines Lessons 3 and 4 by using the Analog-to-Digital Converter (ADC)
to control the speed of rotation.
New Instructions
BTFSS
Bit test, skip if set
BTFSC
Bit test, skip if clear
A conversion is run on every pass through the main loop. The result controls the length
of the outer loop (see Example 3-5).
EXAMPLE 3-5:
VARIABLE SPEED ROTATE EXAMPLE
...
BSF
BTFSS
ADCON0,GO
ADCON0,GO
GOTO
MOVF
ADDLW
MOVWF
$-1
ADRESH,w
1
Delay2
A2DDelayLoop
DECFSZ Delay1,f
;start conversion
;this bit will change to zero when the
;conversion is complete
;Copy the display to the LEDs
;Delay Loop shortened by the ADResult as
;controlled by the Pot.
GOTO
A2DDelayLoop
DECFSZ Delay2,f
GOTO
A2DDelayLoop
FIGURE 3-3:
VARIABLE SPEED ROTATE PROGRAM FLOW
Initialize I/O Port
Initialize ADC
Put Up Display
Get ADC Result
Delay Using ADC
Rotate Display
Did it overflow?
Yes
No
Reset Display
DS51556A-page 22
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.6
Lesson 6: Switch Debouncing
Mechanical switches play an important and extensive role in practically every
computer, microprocessor and microcontroller application. Mechanical switches are
inexpensive, simple and reliable. In addition, switches can be very noisy. The apparent
noise is caused by the closing and opening action that seldom results in a clean
electrical transition. The connection makes and breaks several, perhaps even
hundreds, of times before the final switch state settles.
The problem is known as switch bounce. Some of the intermittent activity is due to the
switch contacts actually bouncing off each other. Imagine slapping two billiard balls
together. The hard non-resilient material doesn’t absorb the kinetic energy of motion.
Instead, the energy dissipates over time and friction in the bouncing action against the
forces push the billiard balls together. Hard metal switch contacts react in much the
same way. Also, switch contacts are not perfectly smooth. As the contacts move
against each other, the imperfections and impurities on the surfaces cause the
electrical connection to be interrupted. The result is switch bounce.
The consequences of uncorrected switch bounce can range from being just annoying
to catastrophic. For example, imagine advancing the TV channel, but instead of getting
the next channel, the selection skips one or two. This is a situation a designer should
strive to avoid.
Switch bounce has been a problem even before the earliest computers. The classic
solution involved filtering, such as through a resistor-capacitor circuit, or through
re-settable shift registers (see Figures 3-4 and 3-5). These methods are still effective
but they involve additional cost in material, installation and board real estate. Why
suffer the additional expense when software is free and program memory is abundant.
FIGURE 3-4:
FILTERING DEBOUNCE SOLUTION
+V
R2
R1
Filtered
Switch
Output
C1
SW
FIGURE 3-5:
SHIFT REGISTER DEBOUNCE SOLUTION
+V
R1
D
SW
CLK
Qn
Filtered
Switch
Output
CLR
Debounce
Clock
© 2005 Microchip Technology Inc.
DS51556A-page 23
Low Pin Count Demo Board User’s Guide
One of the simplest ways to switch debounce is to sample the switch until the signal is
stable or continue to sample the signal until no more bounces are detected. How long
to continue sampling requires some investigation. However, 5 mS is usually plenty
long, while still reacting fast enough that the user won’t notice it.
Lesson 6 shows how to sample the line at a 1 mS rate waiting for a number of
sequential state changes, which is a simple matter of counting to 5, then resetting the
counter every time it’s still in the original unchanged state.
The Switch on the LPC Demo Board doesn’t bounce much, but it is good practice to
debounce all switches in the system.
FIGURE 3-6:
SIMPLE SWITCH DEBOUNCE PROGRAM FLOW
Yes
Switch has
changed states?
Increment Counter
No
Reset Counter
No
Is Counter = 5?
Yes
Change State
Reset Counter
Delay 1 mS
DS51556A-page 24
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.7
Lesson 7: Reversible Variable Speed Rotate
Lesson 7 combines Lessons 5 and 6 using the button to reverse the direction of rotation
when the button is pressed and adjusting the potentiometer to control the speed of
rotation.
The program needs to keep track of rotation direction and new code needs to be added
to rotate in the other direction.
Lesson 5 rotates right and checks for a ‘1’ in the Carry bit to determine when to restart
the sequence. In Lesson 7, we’ll also need to rotate left and check for a ‘1’ in bit 4 of
the display. When the ‘1’ shows up in bit 4 of the display, re-insert it into the bit 0
position.
EXAMPLE 3-6:
REVERSIBLE VARIABLE SPEED ROTATE EXAMPLE
Original Version:
Rotate
RRF
BTFSC
BSF
Display,f
STATUS,C
Display,3
;Did the bit rotate into the carry?
;yes, put it into bit 3.
Bidirectional Version:
Rotate
BCF
BTFSS
GOTO
STATUS,C
Direction,0
RotateLeft
RotateRight
RRF
Display,f
BTFSC STATUS,C
BSF
Display,3
GOTO
MainLoop
RotateLeft
RLF
Display,f
BTFSC Display,4
BSF
Display,0
GOTO
MainLoop
© 2005 Microchip Technology Inc.
;ensure the carry bit is clear
;Did the bit rotate into the carry?
;yes, put it into bit 3.
;did it rotate out of the display
;yes, put it into bit 0
DS51556A-page 25
Low Pin Count Demo Board User’s Guide
3.2.8
Lesson 8: Function Calls
Lesson 8 shows the reversible LEDs but with the Delay Loop rewritten as a function.
New Instructions
CALL
Invokes functions or subroutines
RETURN
Terminates functions or subroutines
RETLW
Terminates functions or subroutines
Functions or Subroutines are invoked with the CALL instruction and terminated with a
RETURN or RETLW instruction. RETURN jumps back to the original program at the
location following the CALL. RETLW also returns to the calling program, but loads Wreg
with a constant.
The mid-range PICmicro MCU device’s CALL stack can hold up to 8 return addresses.
If a ninth CALL is made, it will overwrite the first one and then the program will not be
able to RETURN all the way back.
Passing Arguments
Arguments to the subroutine may be passed in a number of ways. Wreg is a convenient
place to pass one byte and the FSR may be used to pass another byte, if not otherwise
used. If more data must be passed, a buffer must be allocated.
When the Delay function is pulled out to a subroutine, the ADC result is moved into
Wreg, then the CALL transfers control to the Delay subroutine. The RETURN transfers
control to the MOVLW following the CALL.
EXAMPLE 3-7:
FUNCTION CALL EXAMPLE
MOVF
CALL
ADRESH,w
Delay
...
GOTO
xxx
;call delay function
;returns here when done
; Delay function.
; Delay time is Wreg value * 771 uS
Delay
MOVWF Delay2
DelayLoop
DECFSZ Delay1,f
GOTO
DelayLoop
DECFSZ Delay2,f
GOTO
DelayLoop
RETURN
DS51556A-page 26
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.9
Lesson 9: Timer0
Timer0 is a counter implemented in the processor. It may be used to count processor
clock cycles or external events. Lesson 9 configures it to count instruction cycles and
set a flag when it rolls over. This frees up the processor to do meaningful work rather
than just wasting cycles.
Timer0 is an 8-bit counter with an optional prescaler, which is configured to divide by
256 before reaching the Timer0 counter.
FIGURE 3-7:
TIMER0 SIMPLIFIED
Clock/4 or
Prescaler
T0CKI pin
TMR0
T0IF
Prescaler may be configured
to divide by 2, 4, 8, 16, 32, 64,
128 or 256.
Note:
Flag set when
TMR0 overflows.
Must be cleared
in software.
See PIC16F690 Timer0 section for more details.
TMR0 is a Special Function Register (SFR) and may be read or modified by the
program. The Prescaler is not a SFR and thus cannot be read or modified by the
program. However, writing to TMR0 clears the Prescaler.
The timer may be fed either by the same clock that drives the processor or by an
external event. Driven by the processor clock, it increments once for every instruction
cycle. This is a convenient method of marking time, better than delay loops, as it allows
the processor to work on the problem rather than waste cycles in delay loops.
The prescaler is configured through the OPTION_REG, see Figure 3-8.
FIGURE 3-8:
X
PRESCALER CONFIGURATION THROUGH OPTION_REG
X
T0CS
T0SE
PSA
PS2
PS1
bit 7
PS0
bit 0
Legend:
X:
Don’t cares – not Timer0 related.
T0CS: Timer0 Clock Source 0 for Instruction Clock.
T0SE: Timer0 Source Edge – Don’t care when connected to instruction clock.
PSA:
Prescaler Assignment 0 assigns to Timer0.
PS:
Prescaler rate select ‘111’ – full prescaler, divide by 256.
Lesson 9 configures Timer0 with the Prescaler for a maximum delay on Timer0. The
prescaler will divide the processor clock by 256 and Timer0 will divide that by 256
again. Thus, Timer0 Flag will be set every 65536 μs (0.0000001 second * 256 * 256),
or about 15 times a second. The main program sits in a loop waiting for the rollover and
when it does, it increments the display and then loops back.
© 2005 Microchip Technology Inc.
DS51556A-page 27
Low Pin Count Demo Board User’s Guide
EXAMPLE 3-8:
TIMER0 EXAMPLE
ORG 0
BSF
MOVLW
STATUS,RP0
b'00000111'
MOVWF
CLRF
CLRF
BCF
OPTION_REG
TRISC
Display
STATUS,RP0
ForeverLoop
BTFSS INTCON,T0IF
GOTO
ForeverLoop
BCF
INTCON,T0IF
INCF
Display,f
MOVF
Display,w
MOVWF PORTC
GOTO
ForeverLoop
;configure Timer0. Sourced from the
;Processor clock
;Maximum Prescaler
;Make PORTC all output
;wait here until Timer0 rolls over
;flag must be cleared in software
;increment display variable
;send to the LEDs
END
DS51556A-page 28
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.10
Lesson 10: Interrupts
New Instructions
RETFIE
Return from Interrupt
SWAPF
Swap nibbles in file register
Interrupt Sources
Most of the peripherals can generate an interrupt; also some of the I/O pins may be
configured to generate an interrupt when they change state.
When a peripheral needs service, it sets its interrupt flag. Each interrupt flag is ANDed
with its enable bit and then these are ORed together to form a Master Interrupt. This
master interrupt is ANDed with the Global Interrupt Enable (GIE). See the Interrupt
Logic Figure in the PIC16F685/687/689/690 Data Sheet (DS41262) for a complete
drawing of the interrupt logic. The enable bits allow the PICmicro to limit the interrupt
sources to certain peripherals.
FIGURE 3-9:
INTERRUPT LOGIC SIMPLIFIED
Interrupt Flag
Interrupt Enable
Master Interrupt
Global Interrupt Enable
Other Interrupt Sources
When the master interrupt line is asserted, the PICmicro finishes the current
instruction, stores the next address on the CALL stack then jumps to the Interrupt
Service Routine (ISR). It also clears the GIE bit, preventing another interrupt from
occurring while servicing the current one.
Save Current Context
The first thing the ISR must do is to save the current context of the processor so it can
be restored before returning to the main program. Any SFR that may be changed in the
ISR must be saved, which means the Wreg and Status registers at the very least. The
last 16 bytes of each PIC16F690 file register page are unbanked and are good places
to save the context, as they may be accessed from any register page without regard to
the RP0 and RP1 bits in the Status register. The location of unbanked registers may
vary from part to part. Check the register map to find the unbanked region for a specific
part.
Identify Triggering Event
Next, the ISR has to figure out what triggered the interrupt. It has to check the interrupt
flags to determine what caused the interrupt. When it finds the source, then it can
service the peripheral.
© 2005 Microchip Technology Inc.
DS51556A-page 29
Low Pin Count Demo Board User’s Guide
Restore Context
Once the peripheral is serviced, it needs to restore the context and resume the main
program. Restoring the context is a little harder than it might seem at first. The obvious
method doesn’t work because the MOVF W_Temp,w may affect the Z flag, which was
restored in the previous instruction. Instead, a pair of SWAPF instructions can restore
Wreg without affecting the flags in the Status register. SWAPF exchanges the high and
low nibbles. The first SWAPF switches the nibbles in the file register and the second one
switches them back and puts the result in Wreg.
EXAMPLE 3-9:
CONTEXT RESTORE
;incorrect context restore
MOVF
STATUS_Temp,w
MOVWF STATUS
MOVF
W_Temp
;this may change the Z bit
;in the Status register
;good context restore
MOVF
STATUS_Temp,w
MOVWF STATUS
SWAPF W_Temp,f
SWAPF W_Temp,w
;swap in place
;swap with Wreg destination
Finally, RETFIE transfers control back to the original program and sets the GIE bit,
re-enabling interrupts.
FIGURE 3-10:
SWAPF INSTRUCTION
Before
0 0 1 1
After
DS51556A-page 30
1 0 1 0
0 0 1 1
1 0 1 0
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.11
Lesson 11: Indirect Data Addressing
The FSR (File Select Register) allows the specifying of a file register address. A
subsequent read or write to the INDF (Indirect File register) refers to the file register
addressed by the FSR.
This may be used to implement a moving average filter. The moving average keeps a
list of the last n values and averages them together. The Filter needs two parts: A
circular queue and a function to calculate the average.
FIGURE 3-11:
MOVING AVERAGES
Conceptual View
Average
Time
n
105
102
101
104
99
103
105
107
103
n+1
106
105
102
101
104
99
103
105
103
n+2
110
106
105
102
101
104
99
103
104
The rest move down one
Newest value inserted here
Implementation View
Average
Time
n
107
105
101
104
99
101
102
105
103
99
101
102
Pointer to oldest value
n+1
106
105
102
101
105
103
n+2
106
110
Older value overwritten, pointer advanced
103
99
99
101
102
105
104
Pointer advanced
Calculating averages in a mid-range PICmicro is best accomplished by using the FSR
to keep track of where the next value will be inserted. This ensures the oldest value is
always overwritten with the newest and doesn’t waste time moving values within the
memory.
EXAMPLE 3-10:
FILE SELECT REGISTER EXAMPLE
;insert new value into a queue, enter with new value in
;Wreg
MOVF
MOVF
MOVWF
MOVF
MOVWF
© 2005 Microchip Technology Inc.
temp
QueuePointer,w
FSR
temp,w
INDF
;save the latest value
;load FSR with the queue pointer
;Write the latest value to the queue
DS51556A-page 31
Low Pin Count Demo Board User’s Guide
Lesson 11 adds a Moving Average Filter to the Analog-to-Digital code in Lesson 4.
Twisting the potentiometer changes the value read by the Analog-to-Digital. The filtered
value is then sent to the LED display. The filter only runs every 0.2 seconds to slow
down the display changes and make it visible. The display appears to count from the
old potentiometer position to the new position.
The filter averages the last 8 readings. Choosing a power of two for the number of
samples allows division by simple rotates instead of longhand.
Rather than summing the array every time, it’s faster to keep a running sum, then
subtract out the oldest value in the queue and adding in the new value.
DS51556A-page 32
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
3.2.12
Lesson 12: Look-up Table (ROM Array)
Lesson 8 introduced function calls. Lesson 12 shows how function calls and calculated
modification of the Program Counter may be used to implement a Look-up Table (see
Example 3-11).
It is sometimes useful to implement a table to convert from one value to another.
Expressed in a high-level language it might look like this:
y = function(x);
That is for every value of x, it returns the corresponding y value.
Look-up tables are a fast way to convert an input to meaningful data because the
transfer function is pre-calculated and “looked up” rather than calculated on the fly.
PICmicro MCUs implement these by directly modifying the Program Counter. For
example, a function that converts hexadecimal numbers to the ASCII equivalent. We
can strip out the individual nibble and call the Look-up Table. The index advances the
program counter to the appropriate RETLW instruction to load Wreg with the constant
and returns to the calling program.
EXAMPLE 3-11:
LOOK-UP TABLE
;Enter with index in Wreg
Look-upTable
ADDWF
RETLW
RETLW
...
RETLW
PCL,f
'0'
'1'
;jump to
;index 0
;index 1
'F'
;index 15
Calling the Look-up Table works most of the time. However, if the table falls across a
256 byte page boundary, or if somehow the Look-up Table is called with an out of
bounds index value, it will jump to a location out of the table.
Good programming practices dictate a few additional instructions. First, since the table
is only sixteen entries, make sure a number no larger than 16 is passed in. The simplest
way to do this is to logically AND the contents of Wreg before modifying PCL: ANDLW
0x0F. More complex error recovery schemes may be appropriate, depending on the
application.
In addition, there are some nuances to be aware of should the table cross a 256 word
boundary. The Program Counter is 13 bits wide, but only the lower 8 bits are
represented in PCL (see Figure 3-12). The remaining 5 bits are stored in PCLATH.
However, an overflow of the lower 8 bits is not automatically carried over into PCLATH.
Instead, be sure to check for and handle that case in our code. See the PCL and
PCLATH Section in the PIC16F685/687/689/690 Data Sheet (DS41262) for more
details of how PCLATH is used.
FIGURE 3-12:
PC LOADING AS DESTINATION OF INSTRUCTION
PCH
12
PCL
8
7
0
PC
5
PCLATH & lt; 4:0 & gt;
Instruction with
PCL as
Destination
8
ALU Result
PCLATH
© 2005 Microchip Technology Inc.
DS51556A-page 33
Low Pin Count Demo Board User’s Guide
This lesson uses the Look-up Table to implement a binary to Gray code converter. Gray
code is a binary code in which only a single bit changes from one sequence to the next.
They are frequently used in encoder applications to avoid wild jumps between states.
Binary encoders are typically implemented an opaque disk sensed by light sensors.
Due to different threshold levels on different bits, bits may change at slightly differently
times yielding momentary invalid results. Gray code prevents this because only one bit
changes from one sequence to the next. The current code is correct until it transitions
to the next.
The algorithm to convert between binary and Gray code is fairly complex. For a small
number of bits, the table look-up is smaller and faster.
This lesson also takes the Analog-to-Digital value and converts it to Gray code
displayed on the LEDs. The code changes one bit at a time as the potentiometer
rotates across its range (see Example 3-12).
Gray Code Converter
Decimal
0
0000
1
0001
2
0011
3
0010
4
0110
5
0111
6
0101
7
0100
8
1100
9
1101
10
1111
11
1110
12
1010
13
1011
14
1001
15
DS51556A-page 34
Binary
1000
© 2005 Microchip Technology Inc.
LPC Demo Board Lessons
EXAMPLE 3-12:
CONVERT BINARY TO GRAY CODE
; Convert 4 bit binary to 4 bit Gray code
;
BinaryToGrayCode
ANDLW 0x0F
;mask off invalid entries
MOVWF temp
MOVLW high TableStart ;get high order part of the beginning of
;the table
MOVWF PCLATH
MOVLW low TableStart
;load starting address of table
ADDWF temp,w
;add offset
BTFSC STATUS,C
;did it overflow?
INCF
PCLATH,f
;yes: increment PCLATH
MOVWF PCL
;modify PCL
TableStart
RETLW b'0000'
;0
RETLW b'0001'
;1
RETLW b'0011'
;2
RETLW b'0010'
;3
RETLW b'0110'
;4
RETLW b'0111'
;5
RETLW b'0101'
;6
RETLW b'0100'
;7
RETLW b'1100'
;8
RETLW b'1101'
;9
RETLW b'1111'
;10
RETLW b'1110'
;11
RETLW b'1010'
;12
RETLW b'1011'
;13
RETLW b'1001'
;14
RETLW b'1000'
;15
© 2005 Microchip Technology Inc.
DS51556A-page 35
Low Pin Count Demo Board User’s Guide
NOTES:
DS51556A-page 36
© 2005 Microchip Technology Inc.
© 2005 Microchip Technology Inc.
1
2
+V
+V
+V
RA5
RA4
RA3
RC5
RC4
RC3
RA0
RA1
RA2
RC0
RC1
RC2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
J1
RA5
RA4
RA3
RC5
RC4
RC3
RA0
RA1
RA2
RC0
RC1
RC2
+5V
GND
VDD
VSS
RA5/T1CKI/OSC1/CLKIN
RA0/AN0/C1IN+/ICSPDAT/ULPWU
RA4/AN3/T1G/OSC2/CLKOUT RA1/AN1/C12IN-/VREF/ICSPCLK
RA3/MCLR/VPP
RA2/AN2/T0CLKI/INT/C1OUT
RC5/CCP1/P1A
RC0/AN4/C2IN+
RC4/C2OUT/P1B
RC1/AN5/C12INRC3/AN7/P1C
RC2/AN6/P1D
RC6/AN8/SS
RB4/AN10/SDI/SDA
RC7/AN9/SDO
RB5/AN11/RX/DT
RB6/SCK/SCK
RB7/RX/CK
U1
PIC16F690/P
20
19
18
17
16
15
14
13
12
11
RA0
RA1
RA2
RC0
RC1
RC2
RB4
RB5
RB6
RC3
RC2
RC1
RC0
RA0
+V
JP4
JP3
JP2
JP1
R7
1KΩ
JP5
R2
1 KΩ
DS4
DS3
DS2
R6
470Ω
R5
470Ω
R4
470Ω
R3
470Ω
C2
0.1 μF
DS1
R1
10 KΩ
SW1
10 KΩ
RP1
FIGURE A-1:
P2
PWR
P1 TM
ICSP
1
2
3
4
5
6
VPP
VDD
GND
ICSPDAT
ICSPCLK
T1G
1
2
3
4
5
6
7
8
9
10
RA3
A.1
RA5
RA4
RA3
RC5
RC4
RC3
RC6
RC7
RB7
C1
0.1 μF
+V
PICKITTM 2 USER’S GUIDE
Appendix A. Hardware Schematics
INTRODUCTION
This appendix contains the Low Pin Count Demo Board Diagrams.
LOW PIN COUNT DEMO BOARD SCHEMATIC DIAGRAM
DS51556A-page 37
WORLDWIDE SALES AND SERVICE
AMERICAS
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
India - Bangalore
Tel: 91-80-2229-0061
Fax: 91-80-2229-0062
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
India - New Delhi
Tel: 91-11-5160-8631
Fax: 91-11-5160-8632
Austria - Weis
Tel: 43-7242-2244-399
Fax: 43-7242-2244-393
Denmark - Ballerup
Tel: 45-4450-2828
Fax: 45-4485-2829
China - Chengdu
Tel: 86-28-8676-6200
Fax: 86-28-8676-6599
Japan - Kanagawa
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
France - Massy
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
China - Fuzhou
Tel: 86-591-8750-3506
Fax: 86-591-8750-3521
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
Germany - Ismaning
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Atlanta
Alpharetta, GA
Tel: 770-640-0034
Fax: 770-640-0307
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
China - Hong Kong SAR
Tel: 852-2401-1200
Fax: 852-2401-3431
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
China - Shunde
Tel: 86-757-2839-5507
Fax: 86-757-2839-5571
China - Qingdao
Tel: 86-532-502-7355
Fax: 86-532-502-7205
Malaysia - Penang
Tel:011-604-646-8870
Fax:011-604-646-5086
Philippines - Manila
Tel: 011-632-634-9065
Fax: 011-632-634-9069
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
England - Berkshire
Tel: 44-118-921-5869
Fax: 44-118-921-5820
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-536-4803
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
Taiwan - Hsinchu
Tel: 886-3-572-9526
Fax: 886-3-572-6459
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
San Jose
Mountain View, CA
Tel: 650-215-1444
Fax: 650-961-0286
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
04/20/05
DS51556A-page 38
© 2005 Microchip Technology Inc.
44-PIN DEMO BOARD
USER’S GUIDE
© 2007 Microchip Technology Inc.
DS41296B
Note the following details of the code protection feature on Microchip devices:
•
Microchip products meet the specification contained in their particular Microchip Data Sheet.
•
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•
Microchip is willing to work with the customer who is concerned about the integrity of their code.
•
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, KEELOQ, KEELOQ logo, microID, MPLAB, PIC,
PICmicro, PICSTART, PRO MATE, PowerSmart, rfPIC, and
SmartShunt are registered trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
AmpLab, FilterLab, Linear Active Thermistor, Migratable
Memory, MXDEV, MXLAB, PS logo, SEEVAL, SmartSensor
and The Embedded Control Solutions Company are
registered trademarks of Microchip Technology Incorporated
in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, ECAN,
ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi,
MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit,
PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal,
PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB,
rfPICDEM, Select Mode, Smart Serial, SmartTel, Total
Endurance, UNI/O, WiperLock and ZENA are trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2007, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona, Gresham, Oregon and Mountain View, California. The
Company’s quality system processes and procedures are for its PIC®
MCUs and dsPIC® DSCs, KEELOQ® code hopping devices, Serial
EEPROMs, microperipherals, nonvolatile memory and analog
products. In addition, Microchip’s quality system for the design and
manufacture of development systems is ISO 9001:2000 certified.
DS41296B-page ii
© 2007 Microchip Technology Inc.
44-PIN DEMO BOARD
USER’S GUIDE
Table of Contents
Preface ........................................................................................................................... 1
Introduction............................................................................................................ 1
Document Layout .................................................................................................. 1
Conventions Used in this Guide ............................................................................ 2
Warranty Registration............................................................................................ 3
Recommended Reading........................................................................................ 3
The Microchip Web Site ........................................................................................ 4
Development Systems Customer Change Notification Service ............................ 4
Customer Support ................................................................................................. 5
Document Revision History ................................................................................... 5
Chapter 1. 44-Pin Demo Board Overview
1.1 Introduction ..................................................................................................... 7
1.2 Highlights ........................................................................................................ 7
1.3 Devices Supported by the 44-Pin Demo Board .............................................. 7
1.4 44-Pin Demo Board Overview ........................................................................ 8
1.5 Running the Default Demonstration ............................................................... 8
Chapter 2. Mid-Range PIC® Microcontroller Architectural Overview
2.1 Introduction...................................................................................................... 9
2.2 Memory Organization ...................................................................................... 9
2.3 Instruction Formats........................................................................................ 10
2.4 Assembler Basics.......................................................................................... 11
Chapter 3. 44-Pin Demo Board Lessons
3.1 Introduction.................................................................................................... 13
3.2 44-Pin Demo Board Lessons ........................................................................ 13
3.2.1 Lesson 1: Hello World (Light a LED) ......................................................... 14
3.2.2 Blink (Delay Loop) ..................................................................................... 15
3.2.3 Lesson 3: Rotate (Move the LED) ............................................................. 17
3.2.4 Lesson 4: Analog-to-Digital ....................................................................... 19
3.2.5 Lesson 5: Variable Speed Rotate .............................................................. 22
3.2.6 Lesson 6: Switch Debouncing ................................................................... 23
3.2.7 Lesson 7: Reversible Variable Speed Rotate ............................................ 24
3.2.8 Lesson 8: Function Calls ........................................................................... 26
3.2.9 Lesson 9: Timer0 ....................................................................................... 26
3.2.10 Lesson 10: Interrupts ............................................................................... 28
3.2.11 Lesson 11: Indirect Data Addressing ...................................................... 30
3.2.12 Lesson 12: Look-up Table (ROM Array) .................................................. 32
© 2007 Microchip Technology Inc.
DS41296B-page iii
44-Pin Demo Board User’s Guide
Appendix A. Hardware Schematics
A.1 Introduction ................................................................................................... 35
Worldwide Sales and Service......................................................................................38
DS41296B-page iv
© 2007 Microchip Technology Inc.
44-PIN DEMO BOARD
USER’S GUIDE
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most up-to-date information on development tools, see the MPLAB® IDE on-line help.
Select the Help menu, and then Topics to open a list of available on-line help files.
INTRODUCTION
This chapter contains general information that will be useful to know before using the
44-Pin Demo Board. Items discussed in this chapter include:
•
•
•
•
•
•
•
•
Document Layout
Conventions Used in this Guide
Warranty Registration
Recommended Reading
The Microchip Web Site
Development Systems Customer Change Notification Service
Customer Support
Document Revision History
DOCUMENT LAYOUT
This document describes how to use the 44-Pin Demo Board as a development tool to
emulate and debug firmware on a target board. The manual layout is as follows:
• Chapter 1. “44-Pin Demo Board Overview” – This chapter provides an
overview of the 44-Pin Demo Board for Microchip’s 44-pin Thin Quad Flatpack
(TQFP) PIC® Microcontroller Units (MCU).
• Chapter 2. “Mid-Range PIC® Microcontroller Architectural Overview” – This
chapter provides an overview of the mid-range PIC® microcontroller architecture.
• Chapter 3. “44-Pin Demo Board Lessons” – This chapter provides lessons that
introduce mid-range PIC® MCU assembly instructions and cover basic 44-Pin
Demo board features.
• Appendix A. “Hardware Schematics” – Illustrates the 44-Pin Demo Board
hardware schematic diagram, PCB layout and Bill of Materials.
© 2007 Microchip Technology Inc.
DS41296B-page 1
44-Pin Demo Board User’s Guide
CONVENTIONS USED IN THIS GUIDE
This manual uses the following documentation conventions:
DOCUMENTATION CONVENTIONS
Description
Arial font:
Italic characters
Initial caps
Quotes
Underlined, italic text with
right angle bracket
Bold characters
N‘Rnnnn
Text in angle brackets & lt; & gt;
Courier New font:
Plain Courier New
Represents
Referenced books
Emphasized text
A window
A dialog
A menu selection
A field name in a window or
dialog
A menu path
“MPLAB® IDE User’s Guide”
...is the only compiler...
the Output window
the Settings dialog
select Enable Programmer
“Save project before build”
A dialog button
A tab
A number in verilog format,
where N is the total number of
digits, R is the radix and n is a
digit.
A key on the keyboard
Click OK
Click the Power tab
4‘b0010, 2‘hF1
Italic Courier New
Sample source code
Filenames
File paths
Keywords
Command-line options
Bit values
Constants
A variable argument
Square brackets [ ]
Optional arguments
Curly brackets and pipe
character: { | }
Ellipses...
Choice of mutually exclusive
arguments; an OR selection
Replaces repeated text
Represents code supplied by
user
DS41296B-page 2
Examples
File & gt; Save
Press & lt; Enter & gt; , & lt; F1 & gt;
#define START
autoexec.bat
c:\mcc18\h
_asm, _endasm, static
-Opa+, -Opa0, 1
0xFF, ‘A’
file.o, where file can be
any valid filename
mcc18 [options] file
[options]
errorlevel {0|1}
var_name [,
var_name...]
void main (void)
{ ...
}
© 2007 Microchip Technology Inc.
Preface
WARRANTY REGISTRATION
Please complete the enclosed Warranty Registration Card and mail it promptly.
Sending in the Warranty Registration Card entitles users to receive new product
updates. Interim software releases are available at the Microchip web site.
RECOMMENDED READING
This user’s guide describes how to use the 44-Pin Demo Board. Other useful documents are listed below. The following Microchip documents are available and
recommended as supplemental reference resources.
PIC16F88X Data Sheet (DS41291)
Consult this document for information regarding the PIC16F88X 28/40/44-Pin
Flash-Based, 8-Bit CMOS Microcontrollers with nanoWatt Technology device
specification.
PICkit™ 2 Microcontroller Programmer User’s Guide (DS51553)
Consult this document for instructions on how to use the PICkit 2 Microcontroller
Programmer software and hardware.
MPLAB® ICD User’s Guide (DS51184)
Consult this document for more information pertaining to the features and functions of
the MPLAB In-Circuit Debugger (ICD) software.
MPLAB® IDE User’s Guide (DS51519)
Consult this document for more information pertaining to the installation and features
of the MPLAB Integrated Development Environment (IDE) Software.
Readme Files
For the latest information on using other tools, read the tool-specific Readme files in
the Readmes subdirectory of the MPLAB IDE installation directory. The Readme files
contain update information and known issues that may not be included in this user’s
guide.
© 2007 Microchip Technology Inc.
DS41296B-page 3
44-Pin Demo Board User’s Guide
THE MICROCHIP WEB SITE
Microchip provides online support via our web site at www.microchip.com. This web
site is used as a means to make files and information easily available to customers.
Accessible by using your favorite Internet browser, the web site contains the following
information:
• Product Support – Data sheets and errata, application notes and sample
programs, design resources, user’s guides and hardware support documents,
latest software releases and archived software
• General Technical Support – Frequently Asked Questions (FAQs), technical
support requests, online discussion groups, Microchip consultant program
member listing
• Business of Microchip – Product selector and ordering guides, latest Microchip
press releases, listing of seminars and events, listings of Microchip sales offices,
distributors and factory representatives
DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICE
Microchip’s customer notification service helps keep customers current on Microchip
products. Subscribers will receive e-mail notification whenever there are changes,
updates, revisions or errata related to a specified product family or development tool of
interest.
To register, access the Microchip web site at www.microchip.com, click on Customer
Change Notification and follow the registration instructions.
The Development Systems product group categories are:
• Compilers – The latest information on Microchip C compilers and other language
tools. These include the MPLAB C18 and MPLAB C30 C compilers; MPASM™
and MPLAB ASM30 assemblers; MPLINK™ and MPLAB LINK30 object linkers;
and MPLIB™ and MPLAB LIB30 object librarians.
• Emulators – The latest information on Microchip in-circuit emulators.This
includes the MPLAB ICE 2000 and MPLAB ICE 4000.
• In-Circuit Debuggers – The latest information on the Microchip in-circuit
debugger, MPLAB ICD 2.
• MPLAB® IDE – The latest information on Microchip MPLAB IDE, the Windows®
Integrated Development Environment for development systems tools. This list is
focused on the MPLAB IDE, MPLAB SIM simulator, MPLAB IDE Project Manager
and general editing and debugging features.
• Programmers – The latest information on Microchip programmers. These include
the MPLAB PM3 and PRO MATE® II device programmers and the PICSTART®
Plus and PICkit™ 2 development programmers.
DS41296B-page 4
© 2007 Microchip Technology Inc.
Preface
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
•
•
•
•
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Technical Support
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
DOCUMENT REVISION HISTORY
Revision A (August 2006)
• Initial release of this document.
Revision B (December 2006)
•
•
•
•
•
•
Updated Chapter 1. “PICkit™ 2 Overview”.
Added Chapter 2. “Mid-Range PIC® Microcontroller Architectural Overview”.
Added Chapter 3. “44-Pin Demo Board Lessons”.
Changed PICmicro® to PIC®.
Changed PICkit® to PICkit™.
Removed Development Systems Information Line from Customer Support
bulleted list.
• Updated schematic in Appendix.
© 2007 Microchip Technology Inc.
DS41296B-page 5
44-Pin Demo Board User’s Guide
NOTES:
DS41296B-page 6
© 2007 Microchip Technology Inc.
44-PIN DEMO BOARD
USER’S GUIDE
Chapter 1. 44-Pin Demo Board Overview
1.1
INTRODUCTION
The 44-Pin Demo Board is a small and simple demonstration PCB for Microchip’s
44-pin Thin Quad Flatpack (TQFP) PIC® Microcontroller Units (MCU). It is populated
with a PIC16F887 MCU, eight LEDs, push button and potentiometer. The demo board
has several test points to access the I/O pins of the MCU and a surface mount
prototyping area. The MCU can be programmed with the PICkit™ 2 Microcontroller
Programmer or the MPLAB® ICD 2 using the RJ-11 to 6-pin inline adapter (AC164110).
1.2
HIGHLIGHTS
This chapter discusses:
• Devices supported by the 44-Pin Demo Board
• The 44-Pin Demo Board Overview
• Running the Default Demonstration
1.3
DEVICES SUPPORTED BY THE 44-PIN DEMO BOARD
The 44-Pin Demo Board can be used with virtually any 44-pin Thin Quad Flatpack
(TQFP) PIC MCU. The assembled 44-Pin Demo Board is populated with a
PIC16F887-I/PT microcontroller.
Additional 44-Pin Demo Boards can be ordered from Microchip Technology and distributors. Part number, DM164120-2, comes with one assembled and two blank 44-Pin
Demo Boards. The blank demo board can be used for evaluating or prototyping circuits
using any of the 44-pin devices listed below.
44-pin TQFP Flash Devices:
•
•
•
•
•
•
•
•
•
•
•
•
•
PIC16F74
PIC16F777
PIC16F877A
PIC16F917
PIC18F4320
PIC18F4410
PIC18F4431
PIC18F4480
PIC18F4515
PIC18F4525
PIC18F4585
PIC18F4620
PIC18F4685
© 2007 Microchip Technology Inc.
•
•
•
•
•
•
•
•
•
•
•
•
PIC16F747
PIC16F871
PIC16F887
PIC18F4220
PIC18F4321
PIC18F4420
PIC18F4450
PIC18F44J10
PIC18F4520
PIC18F4550
PIC18F45J10
PIC18F4680
•
•
•
•
•
•
•
•
•
•
•
•
PIC16F77
PIC16F874A
PIC16F914
PIC18F4221
PIC18F4331
PIC18F4423
PIC18F4455
PIC18F4510
PIC18F4523
PIC18F4580
PIC18F4610
PIC18F4682
DS41296B-page 7
44-Pin Demo Board User’s Guide
1.4
44-PIN DEMO BOARD OVERVIEW
The 44-Pin Demo Board is populated with a PIC16F887 MCU (U1), eight LEDs
(DS1-DS8), push button (SW1) and potentiometer (RP1). The board layout is shown in
Figure 1-1. The demo board has several test points to access the I/O pins of the MCU
and a surface mount prototyping area. The MCU can be programmed with the PICkit™
2 Microcontroller Programmer from header P1.
FIGURE 1-1:
44-PIN DEMO BOARD
PICkit™ 2 Programming Header
Potentiometer RP1
Push Button SW1
LEDs DS1-DS8
Surface Mount
Prototyping
Area
1.5
RUNNING THE DEFAULT DEMONSTRATION
The assembled 44-Pin Demo Board comes preprogrammed with a demonstration
program. To use this program, power the demo board (3.0-5.5 VDC) using a PICkit™ 2
Microcontroller Programmer, or a bench power supply connected to header P2. To use
the PICkit™ 2 Microcontroller Programmer, connect it to a PC USB port using the USB
cable. Start the PICkit™ 2 Microcontroller Programmer PC application and click on the
target power box to apply power to the demo board. The demo program will blink the
eight red lights in succession. Press the push button switch, labeled SW1, and the
sequence of the lights will reverse. Rotate the potentiometer, RP1, and the light
sequence will blink at a different rate.
DS41296B-page 8
© 2007 Microchip Technology Inc.
44-PIN DEMO BOARD
USER’S GUIDE
Chapter 2. Mid-Range PIC® Microcontroller Architectural Overview
2.1
INTRODUCTION
This chapter provides a simple overview of the mid-range PIC® microcontroller
architecture.
SIMPLIFIED MID-RANGE PIC® MICROCONTROLLER BLOCK
DIAGRAM
FIGURE 2-1:
INT
13
Flash
4k x 14
Program
Memory
8
Data Bus
Program Counter
RAM
256 bytes
File
Registers
8-Level Stack (13-bit)
Program 14
Bus
RAM Addr
9
Addr MUX
Instruction Reg
Direct Addr
Indirect
Addr
7
8
FSR Reg
STATUS Reg
8
3
Instruction
Decode and
Control
OSC1/CLKI
OSC2/CLKO
MUX
ALU
8
Timing
Generation
W Reg
Internal
Oscillator
Block
2.2
MEMORY ORGANIZATION
PIC® microcontrollers are designed with separate program and data memory areas.
This allows faster execution as the address and data busses are separate and do not
have to do double duty.
© 2007 Microchip Technology Inc.
DS41296B-page 9
44-Pin Demo Board User’s Guide
Data Memory is held in file registers. Instructions referring to file registers use 7 bits,
so only 128 file registers can be addressed. Multiple file registers are arranged into
“banks”. Two bits in the STATUS register, RP0 and RP1, allow accessing different
banks. These two bits effectively become the top two bits of the file register address.
The additional banks may or may not be implemented, depending on the device.
Mid-range devices reserve the first 32 addresses of each bank for Special Function
Registers (SFRs). SFRs are how the program interacts with the peripherals and some
core features. The controls and data registers are memory mapped into the SFR space.
Addresses above 0x20 to the end of each bank are General Purpose Registers
(GPRs), where program variables may be stored.
Some frequently used registers may be accessed from any bank. For example, the
STATUS register is always available no matter which bank is selected via the RP bits.
The last 16 bytes (0x70-0x7F) of the GPRs may also be accessed from any bank.
Program Memory is accessed via a 13-bit Program Counter (PC). The lower 8 bits are
accessible via SFR (PCL), and the upper 5 are at a PCLATH. See the PIC16F88X Data
Sheet’s (DS41291) section on PCL and PCLATH for more details on the PC. PCLATH
becomes important when program memory size exceeds 1k instructions, and also for
the table look-up in Lesson 12.
Mid-range PIC® MCUs may be clocked by a number of different devices. Unless otherwise noted, the lessons in this manual use the Internal Oscillator running at 4 MHz.
2.3
INSTRUCTION FORMATS
Most instructions follow one of three formats: Byte oriented instructions, Bit oriented
instructions and Literal instructions.
Byte instructions contain a 7-bit data address, a destination bit, and a 6-bit op code.
The data address plus the RP0 and RP1 bits create a 9-bit data memory address for
one operand. The other operand is the Working register (called W or WREG). After the
instruction executes, the destination bit (d) specifies whether the result will be stored in
the WREG (‘w’) or back in the original file register (‘f’). For example:
ADDWF
data,f
adds the contents of WREG and file register data, with the result going back into data.
Bit instructions operate on a specific bit within a file register. They contain 7 bits of data
address, a 3-bit number and the remaining 4 bits are op code. These instructions may
set or clear a specific bit within a file register. They may also be used to test a specific
bit within a file register. For example:
BSF
STATUS,RP0
set the RP0 bit in the STATUS register.
Literal instructions contain the data operand within the instruction. The WREG
becomes the other operand. Calls and GOTO’s use 11 bits as a literal address.
MOVLW
'A'
Moves the ASCII value of ‘A’ (0x41) into the WREG.
DS41296B-page 10
© 2007 Microchip Technology Inc.
Mid-Range PIC® Microcontroller Architectural Overview
2.4
ASSEMBLER BASICS
Numbers in the Assembler
Unless otherwise specified, the assembler assumes any numeric constants in the
program are hexadecimal (base 16). Binary (base 2), Octal (base 8), Decimal (base
10), and ASCII coding are also supported.
Hexadecimal
12 or 0x12 or H'12'
Decimal
.12 or D'12'
Octal
O'12'
Binary
B'00010010'
ASCII
A'c' or 'c'
Org (Origin)
Org tells the Assembler an address at which to start generating code. Normally
we start coding at the Reset vector address ‘0000’, but it could be anywhere.
Baseline devices have a Reset vector at the last location in program memory, so
it’s good practice to have a GOTO instruction pointing to the beginning of the
program.
End
End tells the assembler to stop assembling. There must be one at the end of the
program. It does not necessarily have to be at the end of the file, but nothing after
the end statement will be assembled.
Defining Data Memory Locations
There are three ways to name a location (see Example 2-1). All are equivalent in
that the location name label will be substituted with the value assigned to it during
assembly.
EXAMPLE 2-1:
DEFINING DATA MEMORY
#define Length
0x20
;c-like syntax
Length
0x20
;equate 0x20 with the symbol
0x20
;start a block of variables
;this will be at address 0x20
;this will be at address 0x21
;this is 2 bytes long, starting at
;address 0x22
;this will be at address 0x24
equ
cblock
Length
Width
Area:2
Girth
endc
Note that if used as a literal, the label names will take on the value assigned. If used as
an address operand in an instruction, the label names point to the contents of the file
register with the address of the label’s value.
Unless there is a reason to name a specific location address, the cblock/endc
method is preferred. The advantage is that as variables come and go through the
development process, the cblock keeps the block to a minimum. Using one of the
other methods, you may have to go back and find an unused location.
© 2007 Microchip Technology Inc.
DS41296B-page 11
44-Pin Demo Board User’s Guide
NOTES:
DS41296B-page 12
© 2007 Microchip Technology Inc.
44-PIN DEMO BOARD
USER’S GUIDE
Chapter 3. 44-Pin Demo Board Lessons
3.1
INTRODUCTION
The following lessons cover basic 44-Pin Demo Board features. Refer to applicable
documents as needed. Any updates to the applicable documents are available on
Microchip’s web site.
The code and hex files may be installed from the PICkit™ 2 CD-ROM under path
Install /Lessons.
3.2
44-PIN DEMO BOARD LESSONS
•
•
•
•
•
•
•
•
•
•
•
•
Lesson 1: Hello World (Light a LED)
Lesson 2: Blink (Delay Loop)
Lesson 3: Rotate (Move the LED)
Lesson 4: Analog-to-Digital
Lesson 5: Variable Speed Rotate
Lesson 6: Switch Debounce
Lesson 7: Reversible Variable Speed Rotate
Lesson 8: Function Calls
Lesson 9: Timer0
Lesson 10: Interrupts
Lesson 11: Indirect Data Addressing
Lesson 12: Look-up Table (ROM Array)
© 2007 Microchip Technology Inc.
DS41296B-page 13
44-Pin Demo Board User’s Guide
3.2.1
Lesson 1: Hello World (Light a LED)
The first lesson shows how to turn on a LED. This is the PIC® microcontroller version
of “Hello World” and discusses the I/O pin structures.
New Instructions
BSF
Bit set
BCF
Bit clear
The LEDs are connected to I/O pins RD0 through RD7. When one of these I/O pins
drives high, the LED turns on. The I/O pins can be configured for input or output. On
start-up, the default is input. The TRIS Special Function Register bits use the convention of ‘0’ for output and ‘1’ for input. We want digital output so these must be
configured.
EXAMPLE 3-1:
PICKIT 2, LESSON 1: “HELLO WORLD”
; PICkit 2 Lesson 1 - " Hello World "
;
#include & lt; p16F887.inc & gt;
__CONFIG
_CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF &
_BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF &
_PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG
_CONFIG2, _WRT_OFF & _BOR21V
org 0
Start:
BSF
BCF
BCF
BSF
GOTO
END
STATUS,RP0
TRISD,0
STATUS,RP0
PORTD,0
$
;
;
;
;
;
select Register Bank 1
make IO Pin RD0 an output
back to Register Bank 0
turn on LED RD0 (DS0)
wait here
Now lets look at the program that makes this happen.
;
#include
__Config
Org 0
BCF TRISC,0
BSF PORTD,0
GOTO $
DS41296B-page 14
Starts a comment. Any text on the line following the semicolon
is ignored.
Brings in an include file defining all the Special Function Registers available on the PIC16F887. Also, it defines valid memory
areas. These definitions match the names used in the device
data sheet.
Defines the Configuration Word. The labels are defined in the
p16F887.inc file. The labels may be logically ANDed
together to form the word.
Tells the assembler where to start generating code. Code may
be generated for any area of the part. Mid-range PIC® microcontroller devices start at address ‘0’, also called the Reset
vector.
Tells the processor to clear a bit in a file register. TRISD is the
tri-state register for pin 0 of PORTD. A ‘1’ in the register makes
the pin an input; a ‘0’ makes it an output. We want to make it an
output, so the bit must be cleared.
Tells the processor to set pin 0 of PORTD. This will force the I/O
pin to a high condition turning on the LED.
Tells the processor to go to the current instruction.
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
For more information, refer to the I/O Ports section of the PIC16F882/883/884/886/887
Data Sheet (DS41291).
3.2.2
Blink (Delay Loop)
The first lesson showed how to turn on a LED, this lesson shows how to make it blink.
While this might seem a trivial change from Lesson 1, it gives a context to explore
several more instructions.
New Instructions
CLRF
INCF
DECF
INCFSZ
DECFSZ
GOTO
EXAMPLE 3-2:
Loop
BSF
BCF
GOTO
Clear file register
Increment file register
Decrement file register
Increment file register, Skip next instruction if zero
Decrement file register, Skip next instruction if zero
Jump to a new location in the program
PICKIT 2, LESSON 2: BLINK
PORTD,0
PORTD,0
Loop
;turn on LED D0
;turn off LED D0
;do it again
While adding a BCF instruction and making it loop will make it blink. It will blink so fast
you won’t see it, it will only look dim. That loop requires 4 instruction times to execute.
The first instruction turns it on. The second one turns it off. The GOTO takes two instruction times, which means it will be on for 25% of the time.
As configured, the PIC® microcontroller executes 1 million instructions per second. At
this rate, the blinking needs to be slowed down so that the blinking can be seen, which
can be done by using a delay loop.
Note:
© 2007 Microchip Technology Inc.
Counting cycles – Relating clock speed to instruction speed. The processor
requires 4 clocks to execute an instruction. Since the internal oscillator as
used in these lessons runs at 4 MHz, the instruction rate is 1 MHz.
DS41296B-page 15
44-Pin Demo Board User’s Guide
Increment or Decrement a File Register
The INCFSZ and DECFSZ instructions add or subtract one from the contents of
the file register and skips the next instruction when the result is zero. One use is
in the delay loop as shown in Example 3-3.
CLRF Clears the counter location.
DECFSZ Decrements the location, and if the result is zero, the next instruction is
skipped.
EXAMPLE 3-3:
DELAY LOOP
Short Loop
CLRF
Loop
DECFSZ
GOTO
Delay
Delay,f
Loop
Long Loop
CLRF
CLRF
Loop
DECFSZ
GOTO
DECFSZ
GOTO
Delay1
Delay2
Delay1,f
Loop
Delay2,f
Loop
The GOTO Loop (in Example 3-3) backs up and does it again. This loop takes 3
instruction times; one for the decrement and two for the GOTO (see note) and the
counter will force it to go around 256 times, which takes it a total of 768 instruction times
(768 μs) to execute.
Even that is still too fast for the eye to see. It can be slowed down even more by adding
a second loop around this one.
The inner loop still takes 768 μs plus 3 for the outer loop, but now it’s executed another
256 times, (768 + 3) * 256 = 197376 μs = 0.197s.
Note:
GOTO instructions take two instructions due to the pipelined design of the
processor. The processor fetches the next instruction while executing the
current instruction. When a program branch occurs, the fetched instruction
is not executed.
Open Blink.asm and build the lesson. Next, import the hex file into the PICkit 2 and
program the device. Note the LED now flashes at about a 2.5 Hz rate.
DS41296B-page 16
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
3.2.3
Lesson 3: Rotate (Move the LED)
Building on Lessons 1 and 2, which showed how to light up a LED and then make it
blink with a delay loop, this lesson adds rotation. It will light up DS8 and then shift it to
DS7, then DS6 and on down to DS1, and then back to DS8.
New Instructions
MOVLW
Loads WREG with a literal value
MOVWF
Moves the contents of WREG to a file register
MOVF
Moves the contents of a file register, either to WREG or back into
the file register (see note)
RRF
Rotate file register right
RLF
Rotate file register left
Note:
Moving a file register to itself looks like a NOP at first. However, it has a
useful side effect in that the Z flag is set to reflect the value. In other words,
MOVF fileregister,f is a convenient way to test whether or not the
value is zero without affecting the contents of the WREG.
Rotate Program Flow
•
•
•
•
First, initialize the I/O port and the Display,
Copy the Display variable to the I/O Port, then
Delay for a little while
Rotate the display
FIGURE 3-1:
ROTATE PROGRAM FLOW
Initialize I/O Port
Put Up Display
Delay
Rotate Display
Did it overflow?
Yes
No
Reset Display
© 2007 Microchip Technology Inc.
DS41296B-page 17
44-Pin Demo Board User’s Guide
Rotate
The rotate instructions (RRF or RLF) shift all the bits in the file register right or left by
one position, through the Carry bit. The Carry bit is shifted into the byte and receives
the bit shifted out of the byte. The Carry bit should be cleared before rotation so
unwanted bits are not introduced into the display byte. The Carry bit also indicates
when the display byte is empty. When it is, reinsert the ‘1’ at bit 3.
PIC microcontrollers have two rotate instructions: Rotate Left (RLF) and Rotate Right
(RRF). These instructions rotate the contents of a file register and Carry bit one place.
The Carry bit is found in the STATUS Special Function Register.
FIGURE 3-2:
ROTATE LEFT
File Register
Carry
EXAMPLE 3-4:
Start:
BSF
CLRF
BCF
MOVLW
MOVWF
MainLoop:
MOVF
MOVWF
OndelayLoop:
DECFSZ
GOTO
DECFSZ
GOTO
BCF
RRF
BTFSC
BSF
GOTO
DS41296B-page 18
ROTATE EXAMPLE
STATUS,RP0 ; select Register Bank 1
TRISD
; make IO PortD all output
STATUS,RP0 ; back to Register Bank 0
0x80
Display
Display,w
PORTD
; Copy the display to the LEDs
Delay1,f
; Delay .197 s
OndelayLoop
Delay2,f
OndelayLoop
STATUS,C
Display,f
STATUS,C
Display,7
MainLoop
;
;
;
;
ensure the carry bit is clear
rotate display right
Did the bit rotate into the carry?
yes, put it into bit 7.
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
3.2.4
Lesson 4: Analog-to-Digital
This lesson shows how to configure the ADC, run a conversion, read the analog voltage
controlled by the potentiometer (RP1) on the board, and display the high order 8 bits
on the display.
The PIC16F887 has an on-board Analog-to-Digital Converter (ADC) with 10 bits of resolution on any of 14 channels. The converter can be referenced to the device’s VDD or
an external voltage reference. The 44-pin Demo Board references it to VDD as provided
by the PICkit 2 Microcontroller Programmer. The answer from the ADC is represented
by a ratio of the voltage to the reference.
ADC = V/VREF * 1023
Converting the answer from the ADC back to voltage requires solving for V.
V = ADC/1023 * VREF
Two of the three factors on the right side of the equation are constants and may be calculated in advance. This eliminates the need to actually divide, but still requires fixed
or floating point multiply to solve the equation on the fly.
However, sometimes, such as when reading a sensor, calculating the voltage is only
the first step. There may be additional math to calculate the meaningful data from the
sensor. For example, when reading a thermistor, calculating the voltage is only the first
step on the way to getting the temperature.
There are other means to convert ADC values, including a straight table look-up or a
piece-wise linear interpolation. Each of these represents different speed/memory
trade-offs.
The schematic (Appendix A. “Hardware Schematics”) shows the wiper on the potentiometer is connected to pin RA0 on the PIC16F887.
Here’s the checklist for this lesson:
• Configure PORTA as an analog input, TRISA & lt; 0 & gt; = 1, ANSEL & lt; 0 & gt; = 1
• Select justification and VREF source in ADCON1.
• Select clock scaling and channel in ADCON0.
© 2007 Microchip Technology Inc.
DS41296B-page 19
44-Pin Demo Board User’s Guide
3.2.4.1
ADCON1
The ADCON1 register sets the justification of the 10-bit result in the 16-bit result read
through registers ADRESL and ADRESH. Setting the result to Left Justified means the
8 Most Significant bits and read from ADRESH and the 2 Least Significant bits are read
from bits 7 and 6 of ADRESL. ADCON1 also sets the voltage reference sources VREF+
and VREF-. VREF- is the voltage at which the result will be zero. VREF+ is the voltage at
which the result will be maximum (1023). We select the PIC16F887 VSS and VDD
voltages respectively.
REGISTER 3-1:
ADCON1: A/D CONTROL REGISTER 1
R/W-0
U-0
R/W-0
R/W-0
U-0
U-0
U-0
ADFM
—
VCFG1
VCFG0
—
—
—
bit 7
U-0
—
bit 0
Legend:
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as ‘0’
- n = Value at POR
‘1’ = Bit is set
‘0’ = Bit is cleared
bit 7
ADFM: A/D Conversion Result Format Selection bit
1 = Right justified
0 = Left justified
bit 6
Unimplemented: Read as ‘0’
bit 5
VCFG1: Voltage Reference bit
1 = VREF- pin
0 = Vss
bit 4
VCFG0: Voltage Reference bit
1 = VREF+ pin
0 = VDD
bit 3-0
x = Bit is unknown
Unimplemented: Read as ‘0’
3.2.4.2
ADCON0
ADCON0 controls the ADC operation. Bit 0 turns on the ADC module and bit 1 starts a
conversion. Bits & lt; 7:6 & gt; select the ratio between the processor clock and conversion
speed and bits & lt; 5:2 & gt; select which channel the ADC will operate on. The ratio between
the processor clock and conversion speed is important because the ADC needs at
least 1.6 μs per bit. Accuracy degrades if the clock speed is too high. As the processor
clock speed increases, an increasingly large divider is necessary to keep the conversion bit speed above 1.6 μs. Four MHz gives the fastest conversion rate above the minimum at 8:1 ratio. This results in a conversion speed of 2 μs per bit. Refer to the “TAD
vs. Device Operating Frequencies” Table in the Analog-to-Digital section of the
PIC16F882/883/884/886/887 Data Sheet (DS41291) for recommended configurations.
For purposes of this lesson, the ADC must be turned on and pointed to channel AN0
on pin RA0.
The ADC needs about 5 μs, after changing channels, to allow the ADC sampling capacitor to settle. Finally, we can start the conversion by setting the GO bit in ADCON0. The
bit also serves as the DONE flag. That is, the ADC will clear the same bit when the conversion is complete. The answer is then available in ADRESH:ADRESL. This lesson
takes the high order 8 bits of the result and copies them to the display LEDs attached
to PORTD.
DS41296B-page 20
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
See the Analog-to-Digital section in the PIC16F882/883/884/886/887 Data Sheet
(DS41291) for more details on the ADC module.
REGISTER 3-2:
ADCON0: A/D CONTROL REGISTER 0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
ADCS1
ADCS0
CHS3
CHS2
CHS1
CHS0
GO/DONE
ADON
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
U = Unimplemented bit, read as ‘0’
- n = Value at POR
‘1’ = Bit is set
‘0’ = Bit is cleared
x = Bit is unknown
bit 7-6
ADCS & lt; 1:0 & gt; : A/D Conversion Clock Select bits
00 = FOSC/2
01 = FOSC/8
10 = FOSC/32
11 = FRC (clock derived from a dedicated internal oscillator = 500 kHz max)
bit 5-2
CHS & lt; 3:0 & gt; : Analog Channel Select bits
0000 = AN0
0001 = AN1
0010 = AN2
0011 = AN3
0100 = AN4
0101 = AN5
0110 = AN6
0111 = AN7
1000 = AN8
1001 = AN9
1010 = AN10
1011 = AN11
1100 = AN12
1101 = AN13
1110 = CVREF
1111 = Fixed Ref (0.6 volt fixed reference)
bit 1
GO/DONE: A/D Conversion Status bit
1 = A/D conversion cycle in progress. Setting this bit starts an A/D conversion cycle.
This bit is automatically cleared by hardware when the A/D conversion has
completed.
0 = A/D conversion completed/not in progress
bit 0
ADON: ADC Enable bit
1 = ADC is enabled
0 = ADC is disabled and consumes no operating current
© 2007 Microchip Technology Inc.
DS41296B-page 21
44-Pin Demo Board User’s Guide
3.2.5
Lesson 5: Variable Speed Rotate
Lesson 5 combines Lessons 3 and 4 by using the Analog-to-Digital Converter (ADC)
to control the speed of rotation.
New Instructions
BTFSS
BTFSC
Bit test, skip if set
Bit test, skip if clear
A conversion is run on every pass through the main loop. The result controls the length
of the outer loop (see Example 3-5).
EXAMPLE 3-5:
VARIABLE SPEED ROTATE EXAMPLE
...
BSF
ADCON0,GO_DONE
; start conversion
BTFSS
ADCON0,GO_DONE
; this bit will change to zero when
; the conversion is complete
GOTO
$-1
MOVF
ADRESH,w
ADDLW
1
MOVWF
Delay2
; Copy the display to the LEDs
A2DDelayLoop:
DECFSZ
Delay1,f
; Delay Loop shortened by the ADResult
; as controlled by the potentiometer.
GOTO
A2DDelayLoop
DECFSZ
Delay2,f
GOTO
A2DDelayLoop
FIGURE 3-3:
VARIABLE SPEED ROTATE PROGRAM FLOW
Initialize I/O Port
Initialize ADC
Put Up Display
Get ADC Result
Delay Using ADC
Rotate Display
Did it overflow?
Yes
No
Reset Display
DS41296B-page 22
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
3.2.6
Lesson 6: Switch Debouncing
Mechanical switches play an important and extensive role in practically every computer, microprocessor and microcontroller application. Mechanical switches are inexpensive, simple and reliable. However, switches can be very noisy electrically. The
apparent noise is caused by the closing and opening action that seldom results in a
clean electrical transition. The connection makes and breaks several, perhaps even
hundreds, of times before the final switch state settles.
The problem is known as switch bounce. Some of the intermittent activity is due to the
switch contacts actually bouncing off each other. Imagine slapping two billiard balls
together. The hard non-resilient material doesn’t absorb the kinetic energy of motion.
Instead, the energy dissipates over time and friction in the bouncing action against the
forces push the billiard balls together. Hard metal switch contacts react in much the
same way. Also, switch contacts are not perfectly smooth. As the contacts move
against each other, the imperfections and impurities on the surfaces cause the electrical connection to be interrupted. The result is switch bounce.
The consequences of uncorrected switch bounce can range from being just annoying
to catastrophic. For example, imagine advancing the TV channel, but instead of getting
the next channel, the selection skips one or two. This is a situation a designer should
strive to avoid.
Switch bounce has been a problem even before the earliest computers. The classic
solution involved filtering, such as through a resistor-capacitor circuit, or through re-settable shift registers (see Figure 3-4 and Figure 3-5). These methods are still effective
but they involve additional cost in material, installation and board real estate. Debouncing in software eliminates these additional costs.
FIGURE 3-4:
FILTERING DEBOUNCE SOLUTION
+V
R2
R1
C1
Filtered
Switch
Output
SW
FIGURE 3-5:
SHIFT REGISTER DEBOUNCE SOLUTION
+V
R1
Qn
D
SW
CLK
Filtered
Switch
Output
CLR
Debounce
Clock
© 2007 Microchip Technology Inc.
DS41296B-page 23
44-Pin Demo Board User’s Guide
One of the simplest ways to switch debounce is to sample the switch until the signal is
stable or continue to sample the signal until no more bounces are detected. How long
to continue sampling requires some investigation. However, 5 mS is usually plenty
long, while still reacting fast enough that the user won’t notice it.
Lesson 6 shows how to sample the line at a 1 mS rate waiting for a number of sequential state changes, which is a simple matter of counting to 5, then resetting the counter
every time it’s still in the original unchanged state.
The Switch on the 44-Pin Demo Board doesn’t bounce much, but it is good practice to
debounce all switches in the system.
FIGURE 3-6:
SIMPLE SWITCH DEBOUNCE PROGRAM FLOW
Yes
Switch has
changed states?
Increment Counter
No
Reset Counter
No
Is Counter = 5?
Yes
Change State
Reset Counter
Delay 1 mS
3.2.7
Lesson 7: Reversible Variable Speed Rotate
Lesson 7 combines Lessons 5 and 6 using the button to reverse the direction of rotation
when the button is pressed and adjusting the potentiometer to control the speed of
rotation.
The program needs to keep track of rotation direction and new code needs to be added
to rotate in the other direction.
Lesson 5 rotates right and checks for a ‘1’ in the Carry bit to determine when to restart
the sequence. In Lesson 7, we’ll also need to rotate left and check for a ‘1’ in bit 7 of
the display. When the ‘1’ shows up in bit 7 of the display, insert it into the bit 0 position.
DS41296B-page 24
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
EXAMPLE 3-6:
REVERSIBLE VARIABLE SPEED ROTATE EXAMPLE
Original Version:
Rotate:
RRF
BTFSC
BSF
Display,f
STATUS,C
Display,7
; Did the bit rotate into the carry?
; yes, put it into bit 7.
Bidirectional Version:
Rotate:
BCF
BTFSS
GOTO
STATUS,C
Direction,0
RotateLeft
RotateRight:
RRF
BTFSC
BSF
Display,f
STATUS,C
Display,7
GOTO
RotateLeft:
RLF
BTFSC
BSF
GOTO
© 2007 Microchip Technology Inc.
; ensure the carry bit is clear
; Did the bit rotate into the carry?
; yes, put it into bit 7.
MainLoop
Display,f
STATUS,C
Display,0
MainLoop
; did it rotate out of the display
; yes, put it into bit 0
DS41296B-page 25
44-Pin Demo Board User’s Guide
3.2.8
Lesson 8: Function Calls
Lesson 8 shows the reversible LEDs but with the Delay Loop rewritten as a function.
New Instructions
CALL
Invokes functions or subroutines
RETURN
Terminates functions or subroutines
RETLW
Terminates functions or subroutines
Functions or Subroutines are invoked with the CALL instruction and terminated with
a RETURN or RETLW instruction. RETURN jumps back to the original program at the
location following the CALL. RETLW also returns to the calling program, but loads the
WREG with a constant.
The mid-range PIC® microcontroller device’s CALL stack can hold up to 8 return
addresses.
If a ninth CALL is made, it will overwrite the first one and then the program will not be
able to RETURN all the way back.
Passing Arguments
Arguments to the subroutine may be passed in a number of ways. WREG is a convenient place to pass one byte and the FSR may be used to pass another byte, if not otherwise used. If more data must be passed, a buffer must be allocated.
When the Delay function is pulled out to a subroutine, the ADC result is moved into
WREG, then the CALL transfers control to the Delay subroutine. The RETURN transfers control to the MOVLW following the CALL.
EXAMPLE 3-7:
FUNCTION CALL EXAMPLE
MOVF
ADDLW
ADRESH,w
1
CALL
Delay
GOTO
;
;
;
;
;
Move conversion value (delay) to w
add 1 otherwise entering with 0 takes
longer than entering with 1.
Call delay function
returns here when done
XXX
...
; Delay Function. Enter with number of 771uS delays in Wreg
Delay:
MOVWF
Delay2
DelayLoop:
DECFSZ
Delay1,f
GOTO
DelayLoop
DECFSZ
Delay2,f
GOTO
DelayLoop
RETURN
; goes back to instruction after call
3.2.9
Lesson 9: Timer0
Timer0 is a counter implemented in the processor. It may be used to count processor
clock cycles or external events. Lesson 9 configures it to count instruction cycles and
set a flag when it rolls over. This frees up the processor to do meaningful work rather
than just counting cycles for a delay.
Timer0 is an 8-bit counter with an optional prescaler, which is configured to divide by
256 before reaching the Timer0 counter.
DS41296B-page 26
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
FIGURE 3-7:
TIMER0 SIMPLIFIED
Clock/4 or
Prescaler
T0CKI pin
TMR0
Prescaler may be configured
to divide by 2, 4, 8, 16, 32, 64,
128 or 256.
T0IF
Flag set when
TMR0 overflows.
Must be cleared
in software.
TMR0 is a Special Function Register (SFR) and may be read or modified by the program. The prescaler is not a SFR and thus cannot be read or modified by the program.
However, writing to TMR0 clears the prescaler.
The timer may be fed either by the same clock that drives the processor or by an external event. Driven by the processor clock, it increments once for every instruction cycle.
This is a convenient method of marking time and is better than delay loops, as it allows
the processor to work on the problem rather than waste cycles in delay loops.
The prescaler is configured through the OPTION_REG, see Figure 3-8.
FIGURE 3-8:
X
PRESCALER CONFIGURATION THROUGH OPTION_REG
X
T0CS
T0SE
PSA
PS2
PS1
bit 7
PS0
bit 0
Legend:
X:
Don’t cares – not Timer0 related.
T0CS: Timer0 Clock Source 0 for Instruction Clock.
T0SE: Timer0 Source Edge – Don’t care when connected to instruction clock.
PSA:
Prescaler Assignment 0 assigns to Timer0.
PS:
Prescaler rate select ‘111’ – full prescaler, divide by 256.
Lesson 9 configures Timer0 with the prescaler for a maximum delay on Timer0. The
prescaler will divide the processor clock by 256 and Timer0 will divide that by 256
again. Thus, the Timer0 Flag will be set every 65536 μs (0.0000001 second * 256 *
256), or about 15 times a second. The main program sits in a loop waiting for the
rollover and when it does, it increments the display and then loops back.
© 2007 Microchip Technology Inc.
DS41296B-page 27
44-Pin Demo Board User’s Guide
EXAMPLE 3-8:
org 0
TIMER0 EXAMPLE
BSF
STATUS,RP0
; Bank 1
MOVLW
b'00000111' ; configure Timer0.
Sourced from the
; Processor clock
MOVWF
OPTION_REG
; Maximum Prescaler
CLRF
TRISD
; Make PortD all output
CLRF
Display
BCF
STATUS,RP0
; Bank 0
ForeverLoop:
BTFSS
INTCON,T0IF ; wait here until Timer0 rolls over
GOTO
ForeverLoop
BCF
INTCON,T0IF ; flag must be cleared in software
INCF
Display,f
; increment display variable
MOVF
Display,w
; send to the LEDs
MOVWF
PORTD
GOTO
ForeverLoop
3.2.10
Lesson 10: Interrupts
New Instructions
RETFIE
Return from Interrupt
SWAPF
Swap nibbles in file register
Interrupt Sources
Most of the peripherals can generate an interrupt, and some of the I/O pins may be
configured to generate an interrupt when they change state.
When a peripheral needs service or an event occurs, it sets its interrupt flag. Each
interrupt flag is ANDed with its enable bit and then these are ORed together to form a
Master Interrupt. This master interrupt is ANDed with the Global Interrupt Enable (GIE).
See the Interrupt Logic Figure in the PIC16F882/883/884/886/887 Data Sheet
(DS41291) for a complete drawing of the interrupt logic. The enable bits allow the PIC
microcontroller to limit the interrupt sources to certain peripherals.
FIGURE 3-9:
INTERRUPT LOGIC SIMPLIFIED
Interrupt Flag
Interrupt Enable
Master Interrupt
Global Interrupt Enable
Other Interrupt Sources
DS41296B-page 28
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
When the master interrupt line is asserted, the PIC microcontroller finishes the current
instruction, stores the next address on the CALL stack then jumps to the Interrupt Service Routine (ISR). It also clears the GIE bit, preventing another interrupt from occurring while servicing the current one.
Save Current Context
The first thing the ISR must do is to save the current context of the processor so it can
be restored before returning to the main program. Certain SFRs that may be changed
in the ISR should be saved, such as the WREG and STATUS registers at the very least.
Make sure to save the WREG first, as moving other SFRs into it will destroy the value
needing to be saved. The last 16 bytes of each PIC16F887 file register page are
unbanked and are good places to save the context, as they may be accessed from any
register page without regard to the RP0 and RP1 bits in the STATUS register. The
location of unbanked registers may vary from part to part. Check the register map to
find the unbanked region for a specific part.
Identify Triggering Event
Next, the ISR has to figure out what triggered the interrupt. It has to check the interrupt
flags to determine what caused the interrupt. When it finds the source, it can then
service the peripheral.
Restore Context
Once the peripheral is serviced, it needs to restore the context and resume the main
program. The “context” is the state of the SFRs when the interrupt occurred. Restoring
the context is a little harder than it might seem at first. The obvious method doesn’t work
because the MOVF W_Temp,w may affect the Z flag, which was restored in the previous instruction. Instead, a pair of SWAPF instructions can restore WREG without affecting the flags in the STATUS register. SWAPF exchanges the high and low nibbles. The
first SWAPF switches the nibbles in the file register and the second one switches them
back and puts the result in WREG.
EXAMPLE 3-9:
CONTEXT RESTORE
;incorrect context restore
MOVF STATUS_Temp,w
MOVWF STATUS
MOVF W_Temp
;this may change the Z bit
;in the Status register
;good
MOVF
MOVWF
SWAPF
SWAPF
context restore
STATUS_Temp,w
STATUS
W_Temp,f
W_Temp,w
;swap in place
;swap with Wreg destination
Finally, RETFIE transfers control back to the original program and sets the GIE bit,
re-enabling interrupts.
© 2007 Microchip Technology Inc.
DS41296B-page 29
44-Pin Demo Board User’s Guide
FIGURE 3-10:
SWAPF INSTRUCTION
Before
0 0 1 1
After
3.2.11
1 0 1 0
0 0 1 1
1 0 1 0
Lesson 11: Indirect Data Addressing
The FSR (File Select Register) allows a file register address to be specified. A subsequent read or write to the INDF (Indirect File register) refers to the file register
addressed by the FSR.
This may be used to implement a moving average filter. The moving average keeps a
list of the last n values and averages them together. The Filter needs two parts: A
circular queue and a function to calculate the average.
FIGURE 3-11:
MOVING AVERAGES
Conceptual View
Average
Time
n
105
102
101
104
n+1
106
105
102
101
n+2
110
106
105
102
99
103
105
107
103
104
99
103
105
103
101
104
99
103
104
The rest move down one
Newest value inserted here
Implementation View
Average
Time
n
107
105
101
104
99
101
102
105
103
99
101
102
Pointer to oldest value
n+1
106
105
102
101
105
103
n+2
106
110
Older value overwritten, pointer advanced
103
99
99
101
102
105
104
Pointer advanced
Calculating averages in a mid-range PIC microcontroller is best accomplished by using
the FSR to keep track of where the next value will be inserted. This ensures the oldest
value is always overwritten with the newest and doesn’t waste time moving values
within the memory.
DS41296B-page 30
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
EXAMPLE 3-10:
FILE SELECT REGISTER EXAMPLE
;insert new value into a queue, enter with new value in
;Wreg
MOVF
MOVF
MOVWF
MOVF
MOVWF
INCF
temp
QueuePointer,w
FSR
temp,w
INDF
QueuePointer, f
;save the latest value
;load FSR with the queue pointer
;Write the new value to the queue
;Advance the pointer
Lesson 11 adds a Moving Average Filter to the Analog-to-Digital code in Lesson 4.
Turning the potentiometer changes the value read by the Analog-to-Digital converter.
The averaged value is then sent to the LED display. The averaging filter only runs every
0.2 seconds to slow down the display changes and make it visible. The display appears
to count from the old potentiometer position to the new position.
The filter averages the last 8 readings. Choosing a power of two for the number of samples allows division by simple rotates instead of having to use a true division routine.
Additionally, rather than summing the array every time, it’s faster to keep a running
sum, then subtract out the oldest value in the queue and adding in the new value.
© 2007 Microchip Technology Inc.
DS41296B-page 31
44-Pin Demo Board User’s Guide
3.2.12
Lesson 12: Look-up Table (ROM Array)
Lesson 8 introduced function calls. Lesson 12 shows how function calls and calculated
modification of the Program Counter may be used to implement a look-up table (see
Example 3-11).
It is sometimes useful to implement a table to convert from one value to another.
Expressed in a high-level language it might look like this:
y = function(x);
That is for every value of x, it returns the corresponding y value.
Look-up tables are a fast way to convert an input to meaningful data because the transfer function is pre-calculated and “looked up” rather than calculated on the fly.
PIC microcontrollers implement these by directly modifying the Program Counter (PC).
An example might be a function that converts hexadecimal numbers to the ASCII
equivalent. Each digit’s individual nibble can be pulled out of the number and used as
the index to the look-up table. The index advances the PC to the appropriate RETLW
instruction to load WREG with the corresponding constant and returns to the calling
program.
EXAMPLE 3-11:
LOOK-UP TABLE
;Enter with index in Wreg
LookupTable
ADDWF
RETLW
RETLW
...
RETLW
PCL,f
'0'
'1'
;jump to
;index 0
;index 1
'F'
;index 15
If the table falls across a 256 byte program memory boundary, or if somehow the
look-up table is called with an out of bounds index value, it will jump to a location out of
the table.
Good programming practices dictate a few additional instructions. First, since the table
has only sixteen entries, make sure a number no larger than 16 is passed in. The simplest way to do this is to logically AND the contents of WREG before modifying PCL:
ANDLW 0x0F. More complex error recovery schemes may be appropriate, depending
on the application.
In addition, there are some nuances to be aware of should the table cross a 256 word
boundary. The Program Counter is 13 bits wide, but only the lower 8 bits are represented in PCL (see Figure 3-12). The remaining 5 bits are stored in PCLATH. However,
an overflow of the lower 8 bits is not automatically carried over into PCLATH. Instead,
be sure to check for and handle that case in the code. See the PCL and PCLATH
section in the PIC16F882/883/884/886/887 Data Sheet (DS41291) for more details of
how PCLATH is used.
DS41296B-page 32
© 2007 Microchip Technology Inc.
44-Pin Demo Board Lessons
FIGURE 3-12:
PC LOADING AS DESTINATION OF INSTRUCTION
PCH
12
PCL
8
7
0
PC
5
PCLATH & lt; 4:0 & gt;
Instruction with
PCL as
Destination
8
ALU Result
PCLATH
This lesson uses the look-up table to implement a binary to Gray code converter. Gray
code is a binary code in which only a single bit changes from one sequence to the next.
They are frequently used in encoder applications to avoid wild jumps between states.
Binary encoders are typically implemented as an opaque disk with slots sensed by light
sensors. Due to different threshold levels on different bits, bits may change at slightly
differently times yielding momentary invalid results. Gray code prevents this because
only one bit changes from one sequence to the next. The current code is correct until
it transitions to the next.
The algorithm to convert between binary and Gray code is fairly complex. For a small
number of bits, the table look-up is smaller and faster.
This lesson takes the Analog-to-Digital value upper nibble and converts it to Gray code
displayed on the first four LEDs. The code changes one bit at a time as the potentiometer rotates across its range (seeExample 3-12).
Gray Code Converter
Decimal
Binary
0
0000
1
0001
2
0011
3
0010
4
0110
5
0111
6
0101
7
0100
8
1100
9
1101
10
1111
11
1110
12
1010
13
1011
14
1001
15
1000
© 2007 Microchip Technology Inc.
DS41296B-page 33
44-Pin Demo Board User’s Guide
EXAMPLE 3-12:
CONVERT BINARY TO GRAY CODE
BinaryToGrayCode
ANDLW
0x0F
MOVWF
temp
MOVLW
high TableStart
MOVWF
MOVLW
ADDWF
BTFSC
INCF
MOVWF
TableStart
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
RETLW
DS41296B-page 34
;mask off invalid entries
;get high order part of the
;beginning of the table
PCLATH
low TableStart
temp,w
STATUS,C
PCLATH,f
PCL
;load starting address of table
;add offset
;did it overflow?
;yes: increment PCLATH
;modify PCL
b'0000'
b'0001'
b'0011'
b'0010'
b'0110'
b'0111'
b'0101'
b'0100'
b'1100'
b'1101'
b'1111'
b'1110'
b'1010'
b'1011'
b'1001'
b'1000'
;0
;1
;2
;3
;4
;5
;6
;7
;8
;9
;10
;11
;12
;13
;14
;15
© 2007 Microchip Technology Inc.
44-PIN DEMO BOARD USER’S
GUIDE
Appendix A. Hardware Schematics
A.1
INTRODUCTION
This appendix contains the 44-Pin Demo Board schematic, PCB layout and Bill of
Materials.
44-PIN DEMO BOARD SCHEMATIC DIAGRAM
PIC®
FIGURE A-1:
© 2007 Microchip Technology Inc.
DS41296B-page 35
44-Pin Demo Board User’s Guide
FIGURE A-2:
FIGURE A-3:
DS41296B-page 36
44-PIN DEMO BOARD SILKSCREEN
44-PIN DEMO BOARD TOP COPPER
© 2007 Microchip Technology Inc.
Hardware Schematics
FIGURE A-4:
TABLE A-1:
44-PIN DEMO BOARD BOTTOM COPPER
44-PIN DEMO BOARD BILL OF MATERIALS
Bill of Materials
Designation
C1, C2, C3
Qty
3
Description
Capacitor, Ceramic, 0805 SMT, 0.1 μF, 16V, 5%, X7R
R5-R12
8
Resistor, 0805 SMT, 750Ω, 5%, 1/8W
R1, R3
2
Resistor, 0805 SMT, 1 kΩ, 5%, 1/8W
R2
1
Resistor, 0805 SMT, 10 kΩ, 5%, 1/8W
RP1
1
Potentiometer 10 kΩ, thumbwheel
DS1-DS8
8
LED, 0805 SMT, Red Clear
SW1
1
Switch, push button, momentary
U1 – Microcontroller
1
44-pin PIC® MCU
P1
1
Connector, header, right-angle, 6-pin, 0.100” spacing, 0.025”
square
JP1
1
Connector, header, 2-pin, 0.100” spacing, 0.025” square
Rubber feet
4
Bumpon square, 0.40 x 0.10, black
© 2007 Microchip Technology Inc.
DS41296B-page 37
WORLDWIDE SALES AND SERVICE
AMERICAS
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
Asia Pacific Office
Suites 3707-14, 37th Floor
Tower 6, The Gateway
Habour City, Kowloon
Hong Kong
Tel: 852-2401-1200
Fax: 852-2401-3431
India - Bangalore
Tel: 91-80-4182-8400
Fax: 91-80-4182-8422
India - New Delhi
Tel: 91-11-4160-8631
Fax: 91-11-4160-8632
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Santa Clara
Santa Clara, CA
Tel: 408-961-6444
Fax: 408-961-6445
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
Korea - Gumi
Tel: 82-54-473-4301
Fax: 82-54-473-4302
China - Fuzhou
Tel: 86-591-8750-3506
Fax: 86-591-8750-3521
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
China - Hong Kong SAR
Tel: 852-2401-1200
Fax: 852-2401-3431
Malaysia - Penang
Tel: 60-4-646-8870
Fax: 60-4-646-5086
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
Taiwan - Hsin Chu
Tel: 886-3-572-9526
Fax: 886-3-572-6459
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-536-4803
China - Shunde
Tel: 86-757-2839-5507
Fax: 86-757-2839-5571
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
China - Xian
Tel: 86-29-8833-7250
Fax: 86-29-8833-7256
12/08/06
DS41296B-page 38
© 2007 Microchip Technology Inc.
PICkit™ 2
Programmer/Debugger
User’s Guide
© 2008 Microchip Technology Inc.
DS51553E
Note the following details of the code protection feature on Microchip devices:
•
Microchip products meet the specification contained in their particular Microchip Data Sheet.
•
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•
Microchip is willing to work with the customer who is concerned about the integrity of their code.
•
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro,
PICSTART, PRO MATE, rfPIC and SmartShunt are registered
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
FilterLab, Linear Active Thermistor, MXDEV, MXLAB,
SEEVAL, SmartSensor and The Embedded Control Solutions
Company are registered trademarks of Microchip Technology
Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, In-Circuit Serial
Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB
Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM,
PICDEM.net, PICtail, PIC32 logo, PowerCal, PowerInfo,
PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total
Endurance, UNI/O, WiperLock and ZENA are trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
© 2008, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC® MCUs and dsPIC® DSCs, KEELOQ® code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
DS51553E-page ii
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Table of Contents
Preface ........................................................................................................................... 1
Chapter 1. PICkit 2 Programmer/Debugger Overview
1.1 Introduction ..................................................................................................... 7
1.2 PICkit 2 Development Programmer/Debugger Contents ............................... 7
1.3 PICkit 2 Development Programmer/Debugger ............................................... 7
1.4 PICkit 2 Programmer Application ................................................................. 10
Chapter 2. PICkit 2 Programmer Getting Started
2.1 Introduction ................................................................................................... 15
2.2 Installing the PICkit 2 Hardware ................................................................... 15
2.3 Installing and Launching the PICkit 2 Programmer Application ................... 16
2.4 Connecting to the Device ............................................................................. 16
2.5 Selecting Target Power ................................................................................ 18
2.6 Importing a Hex File ..................................................................................... 19
2.7 Writing the Program to the Device ............................................................... 20
2.8 Verifying the Device ..................................................................................... 23
2.9 Reading Device Memory .............................................................................. 23
2.10 Code Protecting the Device ........................................................................ 23
2.11 Erasing and Blank Checking the Device .................................................... 24
2.12 Automating Write/Read Procedures ........................................................... 24
2.13 PICkit 2 Calibration and Unit ID .................................................................. 25
Chapter 3. Using In-Circuit Serial Programming™ (ICSP™)
3.1 Introduction ................................................................................................... 27
3.2 Isolate VPP/MCLR/Port Pin ........................................................................... 28
3.3 Isolate ICSPCLK or PGC and ICSPDAT or PGD pins ................................. 28
3.4 VDD ............................................................................................................... 29
3.5 VSS ............................................................................................................... 30
3.6 Cable Lengths .............................................................................................. 30
3.7 Serial EEPROM and KeeLoq HCS Devices ................................................. 30
Chapter 4. PICkit 2 Debug Express
4.1 Introduction ................................................................................................... 31
4.2 PICkit 2 Debug Express Kit Contents ........................................................... 31
4.3 Installing the Hardware and Software .......................................................... 32
4.4 Using PICkit 2 Debug Express ..................................................................... 32
4.5 Debug Express Tutorial ................................................................................ 36
© 2008 Microchip Technology Inc.
DS51553E-page iii
PICkit™ 2 User’s Guide
Chapter 5. Troubleshooting
5.1 Introduction ................................................................................................... 49
5.2 Frequently Asked Questions ........................................................................ 49
5.3 PICkit 2 Debug Express MPLAB IDE Errors ................................................ 54
Chapter 6. Updating the PICkit 2 Operating System
6.1 Introduction ................................................................................................... 61
6.2 Updating the PICkit 2 OS - PICkit 2 Programmer Application ...................... 61
6.3 Updating the PICkit 2 OS – MPLAB IDE ...................................................... 62
Chapter 7. PICkit 2 UART Tool
7.1 Introduction ................................................................................................... 65
7.2 Connecting the PICkit 2 UART Tool ............................................................. 65
7.3 The PICkit 2 UART Tool Window ................................................................. 66
Appendix A. MPLAB IDE Reference
A.1 Introduction .................................................................................................. 71
A.2 Debugging Functions ................................................................................... 71
A.3 Programming Functions ............................................................................... 73
A.4 Settings Dialog ............................................................................................. 75
Appendix B. PICkit 2 Schematics
Index .............................................................................................................................79
Worldwide Sales and Service .....................................................................................82
DS51553E-page iv
© 2008 Microchip Technology Inc.
PICkit™ 2
USER’S GUIDE
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most up-to-date information on development tools, see the MPLAB® IDE on-line help.
Select the Help menu, and then Topics to open a list of available on-line help files.
INTRODUCTION
This chapter contains general information that will be useful to know before using
PICkit™ 2 . Items discussed include:
•
•
•
•
•
•
•
Document Layout
Conventions Used in this Guide
Warranty Registration
Recommended Reading
The Microchip Web Site
Development Systems Customer Change Notification Service
Customer Support
© 2008 Microchip Technology Inc.
DS51553E-page 1
PICkit™ 2 User’s Guide
DOCUMENT LAYOUT
This document describes how to use the PICkit 2 as a development tool to emulate
and debug firmware on a target board. The manual layout is as follows:
• Chapter 1. PICkit 2 Programmer/Debugger Overview – Provides an overview
of the PICkit 2 Programmer/Debugger.
• Chapter 2. PICkit 2 Programmer Getting Started – Provides Instructions on
how to get started using the PICkit 2 Programmer/Debugger to program
Flash-based PIC® Microcontroller Units (MCUs).
• Chapter 3. Using In-Circuit Serial Programming™ (ICSP™) – Describes programming with the PICkit 2 Programmer/Debugger using In-Circuit Serial
Programming™ (ICSP™).
• Chapter 4. PICkit 2 Debug Express – Provides a tutorial on using the PICkit™ 2
Debug Express debugger program.
• Chapter 5. Troubleshooting – Provides information on solving common
problems and Debug Express errors.
• Chapter 6. Updating the PICkit 2 Operating System – Provides instruction on
how to update your PICkit 2 Programmer/Debugger’s Operating System.
• Chapter 7. PICkit 2 UART Tool – Provides information on using the PICkit 2 as a
serial UART terminal interface for communicating with a PIC microcontroller
• Appendix A. MPLAB IDE Reference – Describes how the PICkit 2
Programmer/Debugger works with MPLAB IDE.
• Appendix B. PICkit 2 Schematics – Illustrates the PICkit 2
Programmer/Debugger hardware schematic diagrams.
DS51553E-page 2
© 2008 Microchip Technology Inc.
Preface
CONVENTIONS USED IN THIS GUIDE
The following conventions may appear in this documentation:
DOCUMENTATION CONVENTIONS
Description
Represents
Examples
Arial font:
Initial caps
Referenced books
MPLAB® IDE User’s Guide
Emphasized text
Italic
...is the only compiler...
A window
the Output window
A dialog
the Settings dialog
A menu selection
select Enable Programmer
Quotes
A field name in a window or
dialog
“Save project before build”
Underlined, italic with right
angle bracket
A menu path
File & gt; Save
Bold characters
A dialog button
Click OK
A tab
Click the Power tab
A key on the keyboard
Press & lt; Enter & gt; , & lt; F1 & gt;
Sample source code
#define START
Filenames
autoexec.bat
File paths
c:\mcc18\h
Keywords
_asm, _endasm, static
Command-line options
-Opa+, -Opa-
Bit values
0, 1
Constants
0xFF,’A’
Italic
A variable argument
file.o, where file can be
any valid filename
Square brackets [ ]
Optional arguments
mpasmwin [options]
file [options]
Curly brackets and pipe
character: { | }
Choice of mutually exclusive
arguments; an OR selection
errorlevel {0|1}
Ellipses...
Replaces repeated text
var_name [,
var_name...]
Represents code supplied by
user
void main (void)
{ ...
}
Text in angle brackets & lt; & gt;
Courier New font:
Plain
© 2008 Microchip Technology Inc.
DS51553E-page 3
PICkit™ 2 User’s Guide
WARRANTY REGISTRATION
Please complete the enclosed Warranty Registration Card and mail it promptly.
Sending in the Warranty Registration Card entitles users to receive new product
updates. Interim software releases are available at the Microchip web site.
RECOMMENDED READING
This user's guide describes how to use PICkit 2 . Other useful documents are listed
below. The following Microchip documents are available and recommended as
supplemental reference resources.
44-Pin Demo Board User’s Guide (DS41296)
Consult this document for instructions on how to use the 44-Pin demo board as a
development tool to emulate and debug firmware on a target board.
Low Pin Count Demo Board User’s Guide (DS51556)
Consult this document for instructions on how to use Microchip Technology’s low pin
count device (8-pin, 14-pin and 20-pin). This document includes a series of tutorials.
MPLAB® IDE Quick Start Guide (DS51281)
Describes how to set up the MPLAB IDE software and use it to create projects and
program devices.
MPLAB® IDE User’s Guide/Help (DS51519)
Consult this document for more information pertaining to the installation and features
of the MPLAB Integrated Development Environment (IDE) software. An on-line Help
version is also available.
In-Circuit Serial Programmer™ (ICSP™) Guide (DS30277)
This document contains helpful design guidelines for successful ICSP programming. It
includes application notes on hardware designs and the ICSP programming
specifications.
MPASM™ Assembler, MPLINK™ Object Linker, MPLIB™ Object Librarian User’s
Guide (DS33014)
Describes how to use the Microchip PIC® MCU assembler (MPASM assembler), linker
(MPLINK linker), and librarian (MPLIB librarian).
README for PICkit™ 2 Debug Express
For the latest information on using the PICkit 2 Debug Express, read the “Readme for
PICkit 2.htm” file (an HTML file) in the Readmes subdirectory of the MPLAB IDE
installation directory. The Readme file contains updated information and known issues
that may not be included in this user’s guide.
Readme Files
For the latest information on using other tools, read the tool-specific Readme files in
the Readmes subdirectory of the MPLAB IDE installation directory. The Readme files
contain updated information and known issues that may not be included in this user’s
guide.
DS51553E-page 4
© 2008 Microchip Technology Inc.
Preface
THE MICROCHIP WEB SITE
Microchip provides online support via our web site at www.microchip.com. This web
site is used as a means to make files and information easily available to customers.
Accessible by using your favorite internet browser, the web site contains the following
information:
• Product Support – Data sheets and errata, application notes and sample
programs, design resources, user’s guides and hardware support documents,
latest software releases and archived software
• General Technical Support – Frequently Asked Questions (FAQs), technical
support requests, online discussion groups, Microchip consultant program
member listing
• Business of Microchip – Product selector and ordering guides, latest Microchip
press releases, listing of seminars and events, listings of Microchip sales offices,
distributors and factory representatives
DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICE
Microchip’s customer notification service helps keep customers current on Microchip
products. Subscribers will receive e-mail notification whenever there are changes,
updates, revisions or errata related to a specified product family or development tool of
interest.
To register, access the Microchip web site at www.microchip.com, click on Customer
Change Notification and follow the registration instructions.
The Development Systems product group categories are:
• Compilers – The latest information on Microchip C compilers and other language
tools. These include the MPLAB C18 and MPLAB C30 C compilers; MPASM™
and MPLAB ASM30 assemblers; MPLINK™ and MPLAB LINK30 object linkers;
and MPLIB™ and MPLAB LIB30 object librarians.
• Emulators – The latest information on Microchip in-circuit emulators.This
includes the MPLAB REAL ICE™ and MPLAB ICE 2000 in-circuit emulators.
• In-Circuit Debuggers – The latest information on the Microchip in-circuit
debuggers. This includes the MPLAB ICD 2 and PICkit™ 2.
• MPLAB® IDE – The latest information on Microchip MPLAB IDE, the Windows®
Integrated Development Environment for development systems tools. This list is
focused on the MPLAB IDE, MPLAB IDE Project Manager, MPLAB Editor and
MPLAB SIM simulator, as well as general editing and debugging features.
• Programmers – The latest information on Microchip programmers. These include
the MPLAB PM3 device programmer and the PICSTART® Plus, PICkit 1 and
PICkit 2 development programmers.
© 2008 Microchip Technology Inc.
DS51553E-page 5
PICkit™ 2 User’s Guide
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
•
•
•
•
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Technical Support
Customers should contact their distributor, representative or field application engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document. See our web site
for a complete, up-to-date listing of sales offices.
Technical support is available through the web site at: http://support.microchip.com.
DS51553E-page 6
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Chapter 1. PICkit 2 Programmer/Debugger Overview
1.1
INTRODUCTION
This chapter introduces the PICkit 2 Development Programmer/Debugger features and
PICkit 2 Programmer application menu functions.
This chapter discusses:
• PICkit 2 Development Programmer/Debugger Contents
• PICkit 2 Development Programmer/Debugger
• PICkit 2 Programmer Application
1.2
PICkit 2 DEVELOPMENT PROGRAMMER/DEBUGGER CONTENTS
The PICkit 2 Development Programmer/Debugger kit contains the following items:
1. The PICkit 2 Development Programmer/Debugger
2. USB cable
3. PICkit Starter Kit and MPLAB IDE CD-ROMs
Additionally, the PICkit 2 Starter Kit and PICkit 2 Debug Express kit both contain a
demo board with a PIC microcontroller device.
1.3
PICkit 2 DEVELOPMENT PROGRAMMER/DEBUGGER
The PICkit 2 Development Programmer/Debugger is a low-cost development programmer. It is capable of programming most of Microchip’s Flash microcontrollers and serial
EEPROM devices. For specific device support, see the README file included on the
PICkit 2 Starter Kit CD-ROM.
Note:
The PICkit 2 is intended for development programming. For production
programming, please consider the MPLAB PM3 device programmer or
other third party programmers designed for a production environment.
New device support can be added by updating the programming software. The latest
software is available on Microchip’s web site page for the PICkit 2:
www.microchip.com/pickit2.
The PICkit 2 also may be used to debug selected devices. See Chapter 4. “PICkit 2
Debug Express” for more details.
© 2008 Microchip Technology Inc.
DS51553E-page 7
PICkit™ 2 User’s Guide
The PICkit 2 unit is shown in Figure 1-1.
FIGURE 1-1:
PICkit™ 2 MCU PROGRAMMER/DEBUGGER
3
2
1
4
6
5
Legend:
1 – Status LEDs
3 – Lanyard Connection
5 – Pin 1 Marker
2 – Push Button
4 – USB Port Connection
6 – Programming Connector
1.3.1
USB Port Connection
The USB port connection is a USB mini-B connector. Connect the PICkit 2 to the PC using
the supplied USB cable.
1.3.2
Status LEDs
The Status LEDs indicate the status of the PICkit 2.
1. Power (green) – Power is applied to the PICkit 2 via the USB port.
2. Target (yellow) – The PICkit 2 is powering the target device.
3. Busy (red) – The PICkit 2 is busy with a function in progress, such as
programming.
1.3.3
Push Button
The push button may be used to initiate the Write Device programming function when
Programmer & gt; Write on PICkit Button is checked on the PICkit 2 Programmer
application menu (see item labeled 2 in Figure 1-1.)
The push button may also be used to put the PICkit 2 unit operating system firmware
into Bootloader mode. For more information on this feature, see Chapter 6. “Updating
the PICkit 2 Operating System”.
1.3.4
Programming Connector
The programming connector is a 6-pin header (0.100 " spacing) that connects to the
target device. See the pinout specification in Figure 1-2.
For more information on how to use the PICkit 2 with In-Circuit Serial Programming
(ICSP), refer to Chapter 3. “Using In-Circuit Serial Programming™ (ICSP™)”.
DS51553E-page 8
© 2008 Microchip Technology Inc.
PICkit 2 Programmer/Debugger Overview
FIGURE 1-2:
PICkit™ 2 PROGRAMMER CONNECTOR PINOUT
Pin 1 Indicator
Pin Description*
1
2
3
4
5
6
1 = VPP/MCLR
2 = VDD Target
3 = VSS (ground)
4 = ICSPDAT/PGD
5 = ICSPCLK/PGC
6 = Auxiliary
*
Note:
1.3.5
The 6-pin header (0.100 " spacing) accepts 0.025 " square pins.
The programming connector pin functions are different for programming
Serial EEPROMS and HCS devices. See the ReadMe file (Help & gt; Readme)
included with the PICkit 2 programming software for these pinouts.
Lanyard Connection
To help prevent possible loss of the PICkit 2, a convenient lanyard connection is
available on the programmer.
© 2008 Microchip Technology Inc.
DS51553E-page 9
PICkit™ 2 User’s Guide
1.4
PICkit 2 PROGRAMMER APPLICATION
The PICkit 2 Programmer application allows you to program all supported devices
listed in the PICkit 2 Readme file. The programming interface appears as shown in
Figure 1-3. Its controls are listed in the following sections.
For more information on how to install and use the PICkit 2 Programmer application,
see Chapter 2. “PICkit 2 Programmer Getting Started”.
Figure 1-3:
PICkit™ 2 Programmer Application
Menu Bar
Device Configuration
Status Window
Progress Bar
Device VDD
Memory Source
Program Memory
EEPROM Data Memory
DS51553E-page 10
© 2008 Microchip Technology Inc.
PICkit 2 Programmer/Debugger Overview
1.4.1
Menu Bar
The menu bar selects various functions of the PICkit 2 Programmer application. A
summary of the functions are:
File
• Import Hex – Import a hex file for programming. The hex file format INHX32 is
supported.
• Export Hex – Export a hex file read from a device.The hex file is created in the
INHX32 format.
• File History – Up to the last four hex files opened are displayed with their filepath.
These recent hex files may be selected to quickly import them. Note that the file
history will initially be blank on a new installation until a hex file is imported.
• Exit – Exit the program.
Device Family
Select a device family to search for a connected device in that family. Selecting the
device family of the current part will clear all device data.
Some families which cannot be auto-detected (such as Baseline) will bring up a drop
down box from which supported devices may be selected.
Programmer
• Read Device – Reads program memory, data EEPROM memory, ID locations and
Configuration bits.
• Write Device – Writes program memory, data EEPROM memory, ID locations and
Configuration bits.
• Verify – Verifies program memory, data EEPROM memory, ID locations and
Configuration bits read from the target MCU against the code stored in the
programming application.
• Erase – Performs a Bulk Erase of the target MCU. OSCCAL and band gap values
are preserved on parts with these features.
• Blank Check – Performs a Blank Check of program memory, data EEPROM
memory, ID locations and Configuration bits.
• Verify on Write – When checked, the device will be immediately verified after
programming on a Write (recommended). When unchecked, the device will be
programmed but not verified on a Write.
• Hold Device in Reset – When checked, the MCLR (VPP) pin is held low
(asserted). When unchecked, the pin is released (tri-stated), allowing an external
pull-up to bring the device out of Reset.
• Write on PICkit Button – When checked, a Write operation will be initiated by
pressing the PICkit 2 push button.
Tools
• Enable Code Protect – Enables code protection features of the microcontroller on
future Write operations.
Note:
To disable code protect, all device memory must be erased and rewritten.
• Enable Data Protect – Enables data protection feature of microcontrollers with
data EEPROM memory on future Write operations.
Note:
© 2008 Microchip Technology Inc.
To disable data protect, all device memory must be erased and rewritten.
DS51553E-page 11
PICkit™ 2 User’s Guide
• Set OSCCAL – Allows the OSCCAL value to be changed for devices where it is
stored in the last location of Program Memory.
• Target VDD Source
- Auto-Detect – The PICkit 2 will automatically detect whether the target device
has its own power supply or needs to be powered by the programmer on each
operation.
- Force PICkit 2 – The PICkit 2 will always attempt to supply VDD to the target
device.
- Force Target – The PICkit 2 will always assume the target has its own power
supply.
• Calibrate VDD & Set Unit ID – Opens a wizard that steps the user through calibrating the PICkit 2 VDD supplied voltage so it is more accurate, and optionally
assigning a Unit ID to identify between multiple PICkit 2 devices.
• Use VPP First Program Entry – When checked, it allows the PICkit 2 to connect to
and program devices with configurations and code that interferes with the ICSP
signal pins, preventing PICkit 2 from detecting them. Using this feature requires
that the PICkit 2 supplies VDD to the target.
• Fast Programming – When checked, the PICkit 2 will attempt to program the
device as fast as possible. When unchecked, the PICkit 2 will slow down ICSP
communication. This may be helpful for targets with loaded ICSP lines.
• Check Communication – Verifies USB communication with the PICkit 2 and ICSP
communication with a target device by attempting to identify the connected device
by its device ID.
• UART Tool… - Puts the PICkit 2 in UART Mode and opens a terminal-like
interface for communicating with a PIC MCU device program through the USART
pins. See Chapter 7. “PICkit 2 UART Tool” for more information.
• Troubleshoot... – Opens a wizard to help with troubleshooting connectivity from
the PICkit 2 to the target device. This is most useful where the programmer is
unable to detect the target device at all.
• Download PICkit 2 Programmer Operating System – Performs a download of the
PICkit 2 operating system (firmware).
Help
• PICkit 2 User’s Guide – Attempts to launch the user’s guide PDF (Adobe® Reader
must be installed).
• 44-Pin Demo Board Guide – Attempts to launch the 44-Pin Demo Board User’s
Guide PDF (Adobe Reader must be installed).
• LPC Demo Board Guide – Attempts to launch the Low Pin Count Demo Board
User’s Guide PDF (Adobe Reader must be installed).
• PICkit 2 Programmer on the web – Opens www.microchip.com/pickit2 in the
default web browser.
• Readme – Opens the PICkit 2 Readme.txt file.
• About – Opens a dialog with the PICkit 2 Programmer application version, device
file version and firmware version.
1.4.2
Device Configuration
The Device Configuration window displays the device, User ID, Configuration Word
and Checksum. It also displays OSCCAL and Band Gap for parts with those features.
For baseline (12-bit core) devices, serial EEPROM devices, and KeeLoq® HCS
devices, you must select the device from the Device drop-down menu.
DS51553E-page 12
© 2008 Microchip Technology Inc.
PICkit 2 Programmer/Debugger Overview
All other part family devices will be detected by their device ID and the part name will
be displayed on the Device line.
1.4.3
Status Window
The status window displays text status of the operations in progress. If an operation is
successful, the status window will display a green background. If an operation fails, the
status window will display red. If an operation alerts a caution, the status window will
display yellow.
1.4.4
Progress Bar
The progress bar displays the progress of an operation.
1.4.5
Device VDD
The PICkit 2 VDD may be turned on and off by clicking the checkbox “On”. The voltage
may be set in the box on the right either by typing it directly or using the up/down arrows
to adjust it a tenth of a volt at a time. The maximum and minimum allowed voltages will
vary depending on the target device.
If the “On” checkbox is unchecked, PICkit 2 will automatically turn on the VDD at the set
voltage during any requested programming operation.
FIGURE 1-4:
PICKIT™ 2 SUPPLIED VDD
If the target device has its own power supply, then the PICkit 2 will display the detected
VDD voltage in the box on the right, which will be grayed out to prevent being changed.
The checkbox text changes to “check”, and clicking on the checkbox will update the
detected VDD voltage value. If Target VDD & gt; Auto-Detect is selected, clicking on the
checkbox will revert the VDD mode back to PICkit 2 supplied VDD if a target power
supply is no longer detected.
FIGURE 1-5:
1.4.6
TARGET SUPPLIED VDD
Device MCLR State
The “/MCLR” checkbox shown in Figure 1-4 and Figure 1-5 has the same functionality
as the menu selection Programmer & gt; Hold Device in Reset. When the box is checked
the target device will be held in Reset. When unchecked, the target circuit is allowed to
pull MCLR up to VDD to release the device from Reset. This function can be used to
prevent a device from executing code before and after programming.
Note:
© 2008 Microchip Technology Inc.
If the target device allows the MCLR pin to be configured as an input port,
and it is configured as such, PICkit 2 will not be able to hold the device in
Reset.
DS51553E-page 13
PICkit™ 2 User’s Guide
1.4.7
Memory Source
The Source bar displays the source of the currently loaded device data. If read from a
hex file, it will display the hex file name. If read from a device, it will display the part
name. None (Empty/Erased) indicates the buffers are empty, and it will display
Edited once Program Memory or Data EEPROM Memory has been edited in the
window.
1.4.8
Program Memory
Program code can be loaded into the PICkit 2 Programmer application by selecting
File & gt; Import HEX to import a hex file or by clicking Read to read the device memory.
The origin of the code is displayed in the Source block. The Program Memory window
displays the program code in hexadecimal. The code may be edited in the window.
The checkbox next to the Program Memory window is only available on devices with
EEPROM data memory. If the box is checked, then Program Memory, User IDs, and
Configuration Words are written to, read from, and verified on the device. If the box is
unchecked, then Program Memory, User IDs, and Configuration Words will not be
erased or altered during a Write Device operation, and will not be read or verified. The
checkbox does not affect Erase Device or Blank Check operations. Both memory
window checkboxes may not be cleared at the same time.
For supported serial EEPROM devices, the device contents are displayed in the Program Memory window instead of the Data EEPROM Memory window for easier viewing
in the larger display area.
1.4.9
Data EEPROM Memory
Similar to Program Memory above, data EEPROM code can be loaded into the PICkit 2
Programmer application by selecting File & gt; Import HEX to import a hex file or by clicking
Read to read the device memory. The origin of the code is displayed in the Source
block. The Data EEPROM Memory window displays the program code in hexadecimal.
The code may be edited in the window.
The check box next to the EEPROM Data window controls whether the EEPROM Data
memory is written, read and verified. If the box is checked, then the device EEPROM
will be overwritten with the window data. If the box is not checked, then the device
EEPROM will not be erased or altered during a Write Device operation. The checkbox
does not affect Erase Device or Blank Check operations. Both memory window
checkboxes may not be cleared at the same time.
DS51553E-page 14
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Chapter 2. PICkit 2 Programmer Getting Started
2.1
INTRODUCTION
This chapter gives instruction on how to get started using the PICkit 2 Development
Programmer/Debugger to program Flash-based PIC microcontroller units.
For information on how to use the PICkit 2 with In-Circuit Serial Programming™
(ICSP™), refer to Chapter 3. “Using In-Circuit Serial Programming™ (ICSP™)”.
For information on how to update the PICkit 2 operating system (firmware), refer to
Chapter 6. “Updating the PICkit 2 Operating System”.
For information on using the PICkit 2 as a debugger in MPLAB IDE, see Chapter
4. “PICkit 2 Debug Express”.
•
•
•
•
•
•
•
•
•
•
•
2.2
Installing the PICkit 2 Hardware
Installing and Launching the PICkit 2 Programmer Application
Connecting to the Device
Selecting Target Power
Importing a Hex File
Writing the Program to the Device
Verifying the Device
Reading Device Memory
Code Protecting the Device
Erasing and Blank Checking the Device
Automating Write/Read Procedures
INSTALLING THE PICkit 2 HARDWARE
To install the PICkit 2 hardware:
• Plug one end of the USB cable into PICkit 2 USB connector. Plug the other end
into a USB port on your PC.
• Connect the PICkit 2 to a target board via a 6-pin connector. The target board can
be the included demo board or any target equipped with the appropriate 6-pin
connector.
• Do not connect the PICkit 2 to a target board that has its own power supply if it is
not connected to a powered USB port.
• To connect the PICkit 2 to a target with an MPLAB ICD 2 style RJ-11 connector,
the AC164110 RJ-11 to ICSP Adapter kit is required.
When plugging the PICkit 2 into the USB, it is recommended to disconnect it from any
target board first. Similarly, when starting up or rebooting the host PC, ensure it is
disconnected from a target.
For more information about the PICkit 2 hardware, see Section 1.3 “PICkit 2
Development Programmer/Debugger”.
© 2008 Microchip Technology Inc.
DS51553E-page 15
PICkit™ 2 User’s Guide
2.3
INSTALLING AND LAUNCHING THE PICkit 2 PROGRAMMER APPLICATION
Insert the PICkit 2 Starter Kit CD-ROM into the CD-ROM drive. In a few moments, the
introductory screen should be displayed. Follow the directions on the screen for
installing the PICkit 2 Programmer application.
If the introductory screen does not appear, browse to the CD-ROM directory and open
the PICkit_Starter_Kit_Welcome.htm file.
Once installed, start the PICkit 2 Programmer application by selecting
Start & gt; Programs & gt; Microchip & gt; PICkit 2. The programming interface appears as shown in
Figure 2-1. A listing of its features and functions may be found in Section 1.4 “PICkit 2
Programmer Application”.
FIGURE 2-1:
2.4
PICkit™ 2 PROGRAMMING APPLICATION
CONNECTING TO THE DEVICE
The PICkit 2 is capable of programming a variety of Flash-based Microchip PIC microcontrollers and serial EEPROM devices. Supported devices are listed in the PICkit 2
Readme file on the CD-ROM, which can also be viewed by selecting Help & gt; Readme.
When the PICkit 2 Programmer application is first opened, it will attempt to identify the
connected device by the device ID and display it in the Configuration window as shown
in Figure 2-2.
DS51553E-page 16
© 2008 Microchip Technology Inc.
PICkit 2 Programmer Getting Started
FIGURE 2-2:
IDENTIFY DEVICE
If the device on the target is not correctly identified, check the target power
(Section 2.5 “Selecting Target Power”) and device ICSP connections before
attempting to reselect or change the device.
At any time, the device family may be selected to search for connectivity to a device in
that family. To connect to a device once the application is already running, select the
device family by clicking on the Device Family menu as shown in Figure 2-3.
FIGURE 2-3:
SELECT DEVICE FAMILY
If the Baseline (12-bit core), KEELOQ® HCS or EEPROMs device family is selected, you
must select the specific device from the device drop-down box as shown in Figure 2-4.
These devices do not have a device ID and do not support automatic detection.
CAUTION
Ensure that the correct Baseline has been selected. These devices do not contain a
device ID to confirm device selection. Choosing the wrong Baseline may cause an
erasing of the OSCCAL value stored in the last memory location.
© 2008 Microchip Technology Inc.
DS51553E-page 17
PICkit™ 2 User’s Guide
FIGURE 2-4:
2.5
SELECT BASELINE FLASH DEVICE
SELECTING TARGET POWER
The PICkit 2 can supply power to the target or the target may be powered externally.
2.5.1
Target Powered from PICkit 2
If you are going to power the target board from the PICkit 2, do not attach a power supply to the target or the PICkit 2 will sense it and not give you the option to use PICkit 2
power. For a target board not connected to an external power supply, you will see the
options displayed in Figure 2-5.
FIGURE 2-5:
ENABLE POWER FROM PICkit™ 2
voltage
box
To enable power to the target device, check the VDD PICkit 2 “On” checkbox as shown.
The default setting is “Off”, i.e., the checkbox is unchecked.
Note:
If a target power supply is not detected, the PICkit 2 will always supply
power to the target during programming, regardless of the VDD PICkit 2
“On” checkbox state.
The voltage supplied to the target may be adjusted before or after enabling power by
adjusting the VDD PICkit 2 voltage box (Figure 2-5).
If a short or heavy current load is detected on the programmer-supplied VDD, then you
will receive an error and VDD will be automatically disabled. Refer to Figure 2-6.
CAUTION
The USB port current limit is set to 100 mA. If the target plus the PICkit 2 exceed this
current limit, the USB port may turn off. The target may be powered externally if
more power is required.
DS51553E-page 18
© 2008 Microchip Technology Inc.
PICkit 2 Programmer Getting Started
FIGURE 2-6:
VDD ERROR
To avoid heavy current load errors, it is recommended to keep the target current
consumption below 25 mA. Large VDD capacitances should also be avoided as they
slow down the VDD risetime. The allowed VDD rise time is 500 μs or less.
2.5.2
Target Powered from External Supply
The target device may also be powered externally. By default, the PICkit 2 will automatically detect an externally powered board. The heading “VDD PICkit 2” will be changed
to “VDD Target”, the “On” checkbox will be replaced by a checkbox named “Check”, and
the detected VDD voltage is displayed in the grayed out voltage box as in Figure 2-7.
Clicking the “Check” checkbox will update the detected VDD voltage displayed in the
voltage box. If no VDD voltage is detected when the checkbox is clicked, then PICkit 2
will return to supplying VDD power to the target device.
Note:
The maximum external VDD that may be used with the PICkit 2 is 5.0 Volts.
The minimum external VDD that may be used with the PICkit 2 is 2.5 Volts.
FIGURE 2-7:
2.6
EXTERNALLY POWERED TARGET
IMPORTING A HEX FILE
To import a compiled program (hex file) to be programmed into the target device, select
File & gt; Import HEX as shown in Figure 2-8.
FIGURE 2-8:
IMPORT HEX FILE
Example source code and hex files may be found under the Install\Lessons\
directory for the appropriate kit demo board on the PICkit 2 Starter Kit CD-ROM. The
hex file Reversible.hex from the folder 07 Reversible will be used.
© 2008 Microchip Technology Inc.
DS51553E-page 19
PICkit™ 2 User’s Guide
Browse for the hex file and click Open. The code is displayed in the Program Memory
and EEPROM Data windows. The name of the hex file is displayed in the Source block
under Program Memory.
Note:
The example lesson code is meant to be installed to the local hard drive
from the CD-ROM using the Setup files in the CD-ROM directory
Install/Lessons/. The lessons are covered in the user’s guide for the
included kit Demo Board, and this guide should be read before using the
lesson projects and source code.
FIGURE 2-9:
EXAMPLE HEX FILE IMPORTED
The PICkit 2 Programmer application will warn you if the hex file does not contain any
Configuration Words. You can be sure these are included in the hex file by selecting
File & gt; Export in MPLAB IDE to save a hex file including configuration memory. (For
MPLAB IDE usage, see Chapter 4. “PICkit 2 Debug Express”.)
You will also be warned that the hex file is larger than the selected device if the hex file
contains memory locations that do not exist in the current device. Any data for
non-existent locations will not be imported.
2.7
WRITING THE PROGRAM TO THE DEVICE
After a device family has been selected and a hex file has been imported, the target
device can be programmed by clicking Write (Figure 2-10). The device will be erased
and programmed with the hex code previously imported.
DS51553E-page 20
© 2008 Microchip Technology Inc.
PICkit 2 Programmer Getting Started
When erasing the device during programming, a Bulk Erase method is used. All Baseline, Mid-Range, and many dsPIC30F and PIC18F devices require a minimum VDD for
the Bulk Erase. Some of these devices support a low voltage row erase method that
can be used at lower voltages, but this method takes longer to erase the device. See
the Readme file under Help & gt; Readme for devices that support this feature. If a device
does not support row erasing, a dialog will pop up to warn you if the device VDD is below
the minimum required for a Bulk Erase.
Note:
If any Code Protect, Data Protect, Write Protect, or Read Protect configuration bits are currently set in the device, the Bulk Erase method must be
used prior to programming. The lower voltage row erase procedure will not
succeed.
FIGURE 2-10:
BUTTONS – WRITE
The status of the Write operation is displayed in the status bar located under the Device
Configuration window. If the write is successful, the status bar turns green and displays
“Programming Successful”, as shown in Figure 2-11.
FIGURE 2-11:
WRITE SUCCESSFUL STATUS
If the write fails, the status bar turns red and displays “Programming Failed”, as shown
in Figure 2-12. This error indicates that the data was corrupted during the programming
sequence. If this error is displayed, try writing the program to the device again. If the
error continues, see Chapter 5. “Troubleshooting” for assistance.
FIGURE 2-12:
WRITE ERROR STATUS
Other write issues may be displayed as warnings and will turn the status bar yellow as
in Figure 2-13. In this case, the PICkit 2 and demo board had become disconnected.
© 2008 Microchip Technology Inc.
DS51553E-page 21
PICkit™ 2 User’s Guide
FIGURE 2-13:
2.7.1
WRITE WARNING STATUS
Writing to Specific Memory Regions
If a device has EEPROM data memory, the “Enabled” checkbox next to Program
Memory and EEPROM Data will become available.
The checkboxes select which memory regions’ programming operations will be
affected. Refer to Table 2-1 for a description of how programming operations are
affected by the checkboxes. Erase and Blank Check always operate on all memory
regions.
TABLE 2-1:
MEMORY REGION SELECTION
Program
Memory Enabled
EEPROM Data
Enabled
Write/Read/Verify
Erase/Blank Check
Checked
Checked
All Memory Regions
All Memory Regions
Checked
—
Program Memory
User IDS
Configuration
All Memory Regions
—
Checked
EEPROM only
All Memory Regions
—
—
Not Allowed
During a Write, regions that are unchecked will remain unchanged in the device.
For example, if Program Memory is unchecked while EEPROM Data is checked, then
a Write operation will only write EEPROM Data, while Program Memory, User IDs and
Configuration Words in the device will remain unchanged.
If Program Memory is checked while EEPROM Data is unchecked, then a Write
operation will program Program Memory, User IDs and Configuration Words, while
EEPROM Data in the device will remain unchanged.
Due to programming constraints in some devices, the PICkit 2 Programmer application
may read and re-write EEPROM data memory during a Write to preserve it.
It is not allowed to have both memory regions unchecked.
2.7.2
Automatic File Reload
Prior to each Write, the imported hex file time stamp is compared to the version on the
disk. If the version on the disk is newer, it is reloaded. This occurs only when a hex file
has been read from the disk.
This feature ensures that the latest version built will be written to the device. It may be
used with the Tools & gt; Program on PICkit Button feature to program the latest MPLAB
IDE build without switching to the PICkit 2 Programmer software simply by pressing the
PICkit 2 unit push button.
DS51553E-page 22
© 2008 Microchip Technology Inc.
PICkit 2 Programmer Getting Started
2.8
VERIFYING THE DEVICE
The Verify function verifies that the program in device memory matches the hex file
imported into the PICkit 2 Programmer application. It compares all areas of memory
including program memory, data EEPROM memory, ID and Configuration bits.
To verify the code, import the hex file and click Verify (Figure 2-14).
Note that a Write operation is automatically verified if Programmer & gt; Verify on Write is
checked.
FIGURE 2-14:
BUTTONS - VERIFY
If the code is the same, the status bar turns green and displays “Device Verified”. If a
discrepancy is found, the status bar turns red and displays where the error is located:
“Error in Program Memory, Data EEPROM Memory, or Configuration Bits”.
Table 2-1 illustrates how Verify is affected by the memory region checkboxes.
2.9
READING DEVICE MEMORY
To view the code written to the device, click Read (Figure 2-15).
FIGURE 2-15:
BUTTONS - READ
The code is displayed in the Program Memory and EEPROM Data windows for your
review. If all zeros are displayed, it is possible that the device is code-protected (See
Section 2.10 “Code Protecting the Device”.)
Table 2-1 illustrates how Read is affected by the memory region checkboxes.
2.10
CODE PROTECTING THE DEVICE
The Code and Data Protect functions enable the read protection features of the device.
To protect the program memory code, complete the following steps:
1. Import hex file.
2. Select Tools & gt; Enable Code Protect as shown in Figure 2-16.
3. Click Write.
Devices that have EEPROM data memory may protect it by selecting Tools & gt; Enable
Data Protect.
© 2008 Microchip Technology Inc.
DS51553E-page 23
PICkit™ 2 User’s Guide
FIGURE 2-16:
Note:
2.11
ENABLE CODE PROTECT
If the device is read after it has been protected, the protected memory
regions will display all zeros.
Simply unchecking “Enable Code Protect” will not allow you to read the
region. You must erase and reprogram all device memory before you can
read that memory region again.
ERASING AND BLANK CHECKING THE DEVICE
The Erase function erases the program memory, data EEPROM memory, ID and
Configuration bits, regardless of the state of the Program Memory and EEPROM Data
“Enabled” checkboxes. However, this function is not normally needed since the Write
function performs an erase operation prior to programming the device.
To erase the device, click Erase (Figure 2-17).
Note:
The PICkit 2 Erase function always uses the Bulk Erase method that
requires a minimum VDD, even on devices that support row erasing for the
Write function. You will be warned if VDD is below the minimum for the
connected device.
FIGURE 2-17:
BUTTONS – ERASE
The Blank Check function will read the entire device to determine if Program Memory,
EEPROM Data memory, User IDs and Configuration bits are erased. All memory
regions will be examined, regardless of the state of the Program Memory and EEPROM
Data “Enabled” checkboxes.
To Blank Check the device, click Blank Check (Figure 2-17).
2.12
AUTOMATING WRITE/READ PROCEDURES
The PICkit 2 Programmer application has two buttons for automating multiple
functions.
DS51553E-page 24
© 2008 Microchip Technology Inc.
PICkit 2 Programmer Getting Started
FIGURE 2-18:
2.12.1
AUTOMATING BUTTONS
Auto Import Hex + Write Device Button
This features allows the PICkit 2 Programmer application to automatically import a hex
file and write it to a connected device when the hex file is updated; for example, on a
new firmware build.
To use this feature, click Auto Import Hex + Write Device. This will bring up an Import
Hex file dialog defaulting to the first hex file in the file history under the File menu. After
selecting a file, it will be written to the device. The PICkit 2 Programmer application will
now monitor the selected hex file for updates. When the file has been updated (has a
newer time stamp), the application will automatically re-import the hex file and write to
the target device.
While this feature is enabled, other programming operations are disabled. The Auto
Import Hex + Write Device button will remain depressed while this feature is active.
To stop using this feature, click Auto Import Hex + Write Device again.
If an error is encountered during hex file importing or device programming, the
application will automatically exit this feature mode.
2.12.2
Read Device + Export Hex File Button
When clicked, this button will read the target device and open an Export Hex File
dialog.
2.13
PICKIT 2 CALIBRATION AND UNIT ID
The PICkit 2 VDD may be calibrated to account for variations in the unit hardware and
the USB voltage of the port it is connected to. A Unit ID string may also be assigned to
a PICkit 2 unit to provide unique identification.
2.13.1
Calibrating the PICkit 2 VDD
Calibration allows greater accuracy both in the VDD voltage supplied to the target from
PICkit 2, and the voltage detected on a powered target and reported in the software.
The calibration is stored in the PICkit 2 unit nonvolatile memory, so the unit will remain
calibrated even when used from within MPLAB IDE.
It is important to note, however, that as the calibration is dependent on the USB voltage,
moving the PICkit 2 unit to a different USB port, to or from a USB hub or to another
computer port may invalidate the calibration.
To calibrate the PICkit 2 unit, a multi-meter or other means of accurately measuring
voltages is required. Disconnect the PICkit 2 unit from the target and select
Tools & gt; Calibrate Vdd & Set Unit ID… to bring up the calibration wizard. Follow the steps
in the wizard to complete the calibration process.
Note:
© 2008 Microchip Technology Inc.
Even when calibrated, the PICkit 2 VDD voltage is limited by the available
USB port voltage. PICkit 2 is unable to provide a VDD voltage greater than
a Schottky diode drop below the USB port voltage. This voltage can be as
low as 4.2 Volts, especially in laptop computer ports.
DS51553E-page 25
PICkit™ 2 User’s Guide
2.13.2
The PICkit 2 Unit ID
During the calibration procedure, the PICkit 2 may optionally be assigned a Unit ID
string to identify it uniquely.
Once assigned, the PICkit 2 Unit ID will display in the PICkit 2 Programmer software
title bar, and in the Status Window when first connecting to the PICkit 2. An example is
shown in Figure 2-19 where the Unit ID is “Lab B-1”.
The Unit ID is also displayed in the MPLAB IDE Output window when first selecting
PICkit 2 as a Programmer or Debugger.
FIGURE 2-19:
DS51553E-page 26
UNIT ID
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Chapter 3. Using In-Circuit Serial Programming™ (ICSP™)
3.1
INTRODUCTION
The PICkit 2 Development Programmer/Debugger can program microcontroller
devices that are installed in an application circuit using In-Circuit Serial Programming
(ICSP). ICSP requires five signals:
• VPP – Programming Voltage; when applied, the device goes into Programming
mode.
• ICSPCLK or PGC – Programming Clock; a unidirectional synchronous serial clock
line from the programmer to the target.
• ICSPDAT or PGD – Programming Data; a bidirectional synchronous serial data line.
• VDD – Power Supply positive voltage.
• VSS – Power Supply ground reference.
However, the application circuit must be designed to allow all the programming signals
to be connected to the device without distorting the programming signals. Figure 3-1
shows a typical circuit as a starting point when designing an application circuit for ICSP.
For successful ICSP programming, the precautions in the following sections need to be
followed.
Note:
For details on how a specific device is programmed, refer to the device
programming specification available from the Microchip web site at
www.microchip.com.
FIGURE 3-1:
TYPICAL ICSP™ APPLICATION CIRCUIT
Isolation Circuitry:
Resistor or Schottky-type diode
PICkit™ 2
Programming
Header
+5V
1
2
3
4
5
6
+5V
10k*
470 Ohm*
OR
0.1 μF*
1
2
3
4
VSS 8
VDD
RA0/ICSPDAT 7
RA5
RA1/ICSPCLK 6
RA4
RA2 5
RA3/MCLR/VPP
VPP/MCLR
VDD
VSS
ICSPDAT/PGD
ICSPCLK/PGC
AUX
To Application
Circuit
Target Microcontroller
Device
* Typical Values
© 2008 Microchip Technology Inc.
DS51553E-page 27
PICkit™ 2 User’s Guide
3.2
ISOLATE VPP/MCLR/PORT PIN
When VPP voltage is applied, the application circuit needs to take into consideration
that the typical VPP voltage is +12V. This may be an issue in the following situations:
If the VPP pin is used as a MCLR pin
The application circuit is typically connected to a pull up resistor/capacitor circuit, as
recommended in the device data sheet. Care must be taken so that the VPP voltage
slew rate is not slowed down and exceeds the rise time in the programming
specification (typically 1 μs).
If a supervisory circuit or a push button is interfaced to the MCLR pin, it is
recommended that they be isolated from the VPP voltage by using a Schottky-type
diode or limiting resistor as shown in Figure 3-1. For more information about using
supervisory circuits with ICSP, see Application Note AN820 “System Supervisors in
ICSP™ Architectures” (DS00820).
If the VPP pin is used as an I/O port pin
The application circuit that connects to the I/O pin may not be able to handle the +12V
voltage. It is recommended to use a Schottky-type diode or limiting resistor as shown
in Figure 3-1 to isolate the circuitry.
3.3
ISOLATE ICSPCLK OR PGC AND ICSPDAT OR PGD PINS
The ICSPCLK or PGC and ICSPDAT or PGD pins need to be isolated from the
application circuit to prevent the programming signals from being affected by the
application circuitry. ICSPCLK or PGC is a unidirection synchronous serial
programming clock line from the programmer to the target. ICSPDAT or PGD is a
bidirectional synchronous serial programming data line.
If the design permits, dedicate these pins for ICSP. However, if the application circuit
requires that these pins be used in the application circuit, design the circuitry in a
manner that does not alter the signal level and slew rates. Isolation circuitry will vary
according to the application. Figure 3-1 shows one possibility by using series resistors
to isolate the ICSP signals from the application circuit.
DS51553E-page 28
© 2008 Microchip Technology Inc.
Using In-Circuit Serial Programming™ (ICSP™)
3.4
VDD
During ICSP programming, the device needs to be powered in accordance with the
device specification. Typically, the device supply voltage is connected to the application
circuit supply voltage. The application circuit can be powered by the PICkit 2 or externally. There are a few precautions that need to be observed in the situations covered
in the following three sections.
3.4.1
The application circuit is powered by the PICkit 2
The PICkit 2 supply voltage may set between the maximum and minimum voltages
allowed by the device programming specification, unless the minimum is below +2.5V.
Be sure to set the voltage box to the appropriate voltage before programming the
device or turning on VDD.
CAUTION
The USB port current limit is set to 100 mA. If the target plus the programmer
exceeds this current limit, the USB port may turn off. The target may be powered
externally if more power is required.
Note:
3.4.2
Current draw should be limited to 25 mA when using the programmer to
power the application circuit. Ensure that the application circuit does not
slow the VDD rise time to longer than 500 μs.
The application circuit is powered externally
The PICkit 2 may be used with application circuits powered externally between +5.0V
and +2.5V.
3.4.3
Bulk Erase is used
Some devices use a Bulk Erase function to erase program memory, data EEPROM
memory, ID locations, and Configuration bits. Typically, the Bulk Erase function
requires a supply voltage (VDD) of 4.5 to 5.5 Volts (refer to the device programming
specification for device specific requirements).
This voltage range can be a problem if the application circuit is designed to operate at
a different supply voltage range. In order to Bulk Erase the device, the application
circuit needs to take into consideration the Bulk Erase voltage requirement while
protecting any voltage sensitive circuitry.
If the application circuit VDD is below the minimum required for the Bulk Erase, a dialog
will warn the user before attempting to erase the device.
© 2008 Microchip Technology Inc.
DS51553E-page 29
PICkit™ 2 User’s Guide
3.5
VSS
The power supply ground reference, VSS, must be at the same potential as the
application circuit.
3.6
CABLE LENGTHS
Minimize the distance the ICSP signals must travel by placing the ICSP connector as
close to the application circuit device as possible. Minimize any cable length between
the PICkit 2 and application circuit device. The goal is to keep the ICSP signals within
the level and slew rate specifications for successful programming.
3.7
SERIAL EEPROM AND KEELOQ HCS DEVICES
The programming signals and connections for these devices are different than those
for microcontrollers as described in Section 3.1 “Introduction” and Figure 3-1. See
the PICkit 2 Programmer Readme file, Help & gt; Readme, for programming signal
connectivity for these devices.
Additionally, these devices are not intended to be programmed in-circuit. Attempting to
program serial EEPROM devices while in-circuit may fail due to conflicts with other
devices on the serial bus.
DS51553E-page 30
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Chapter 4. PICkit 2 Debug Express
4.1
INTRODUCTION
In addition to the PICkit 2 Programmer application, the PICkit 2 Development
Programmer/Debugger may be used with MPLAB® IDE, the free integrated development environment available on Microchip’s website. MPLAB IDE allows the PICkit 2 to
be used as an in-circuit debugger as well as a programmer (for selected devices only).
In-circuit debugging allows you to run, examine and modify your program while the
device is embedded in your target hardware. This greatly assists you in debugging your
firmware and hardware together.
Special PICkit 2 Debug Express software interacts with the MPLAB IDE application to
run, stop and single-step through programs. One or more breakpoints can be set and
the processor can be reset. Once the processor is stopped, the register’s contents can
be examined and modified.
For more information on how to use MPLAB IDE, reference the following
documentation:
• MPLAB® IDE User’s Guide (DS51519)
• MPLAB® IDE Quick Start Guide (DS51281)
• MPLAB® IDE On-line Help
4.2
PICkit 2 DEBUG EXPRESS KIT CONTENTS
The PICkit 2 Debug Express kit (DV164121) contains the following items:
1.
2.
3.
4.
The PICkit 2 Development Programmer/Debugger
USB cable
44-Pin Demo Board with device*
PICkit 2 Starter Kit and MPLAB IDE CD-ROMs
* The following boards may also be used to debug:
- To use the Low Pin Count Demo Board from the Starter Kit, the AC162061 ICD
Header and AC164110 adapter will be required.
- To use the Explorer 16 board, be aware that the connector labeled “PICKIT2”
incorrectly shows the location of PICkit 2 pin 1 on the silkscreen. That is, pin 1 is
actually pin 6.
© 2008 Microchip Technology Inc.
DS51553E-page 31
PICkit™ 2 User’s Guide
4.3
INSTALLING THE HARDWARE AND SOFTWARE
Install the PICkit 2 hardware as specified in Section 2.2 “Installing the PICkit 2
Hardware”.
Note:
Debug Express requires 4.7k Ohm pull down resistors on ICSPCLK and
ICSPDAT. Newer PICkit 2 units have a Red button and have the pull downs
internally. Older PICkit 2 units have a Black button and require that the pull
downs be added on the target board.
Obtain a copy of the MPLAB IDE software application from the Microchip website or
CD-ROM enclosed with the kit and install it as directed.
Note:
4.4
Debug Express requires MPLAB IDE version 7.50 or later.
USING PICKIT 2 DEBUG EXPRESS
4.4.1
Determining Device Support
For a list of current devices supported by PICkit 2 Debug Express, see the “Readme
for PICkit 2.htm” file in the “Readmes” subdirectory of the MPLAB IDE installation
directory.
When selecting a device as discussed in Section 4.5 “Debug Express Tutorial”, the
“Select Device” dialog shown in Figure 4-11 shows the level of support for the selected
device by Debug Express. In the “Debuggers” section of the dialog, the color of the
circle next to “PICkit 2” indicates the support level:
Red – The device is not currently supported by PICkit 2 Debug Express
Yellow – The device has beta support in PICkit 2 Debug Express
Green – The device has full support in PICkit 2 Debug Express
Beta support indicates that the device is supported, but has not yet undergone internal
certification testing by Microchip.
4.4.2
Reserved Resources
Due to the built-in in-circuit debugging capability of ICD devices and the ICSP function
offered by the debugger, the PICkit 2 Debug Express uses some on-chip resources
when debugging. It also uses program memory and file register locations in the target
device during debugging. These locations are not available for use by user code. In
MPLAB IDE, registers marked with an “R” in register displays represent reserved
registers.
For information on device resources that are needed for in-circuit debugging, please
refer to the MPLAB ICD 2 Help, found in the MPLAB IDE under Help & gt; Topics. The
device reserved resource information found under “Resources Used By MPLAB ICD 2”
is the same for the PICkit 2 Debug Express.
4.4.3
Using an ICD Header
All Baseline and some Mid-Range PIC microcontrollers require a special –ICD device
mounted on a debug header circuit board to enable the debugging feature. For a list of
these devices and the required ICD header board part number, please see the “Header
Board Specification” (DS51292). The Header Board Specification is included on the
PICkit 2 CD-ROM, and is available online at www.microchip.com.
DS51553E-page 32
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
Each ICD header board comes with the necessary –ICD device, and is used on the target board instead of the production microcontroller. However, most header boards have
an RJ-11 debug connector which requires the AC164110 RJ-11 to ICSP adapter kit to
connect it to PICkit 2. Figure 4-1 illustrates using the AC162061 ICD Header for the
PIC16F690 with the AC164110 adapter kit and Low Pin Count Demo Board.
FIGURE 4-1:
USING THE PIC16F690 ICD HEADER BOARD
AC164110 ICSP™ to RJ-11 Adapter
This diagram shows how to connect the PICkit™ 2 to an ICD
header with the ICSP to RJ-11 Adapter. The AC162061 ICD
header for the PIC16F690 is shown, plugging into the
DM164120-1 Low Pin Count Demo Board.
ICD Header
Debug Target
Board
Many Mid-Range PIC microcontrollers and all PIC18 and 16-bit PIC microcontroller
devices do not require an ICD header and can be debugged directly through the ICSP
programming connections. This is true of the PIC16F887 included on the 44-Pin Demo
Board, which can be debugged by simply connecting the demo board to the PICkit 2
as shown in Figure 4-2.
FIGURE 4-2:
CONNECTING THE DEMO BOARD TO THE PICKIT™ 2
PIC® microcontrollers that don’t require an ICD
Header may be debugged directly over the In-Circuit
Serial-Programming™ (ICSP™) connections.
Debug Target Board
The DM164120-2 44-Pin Demo Board with
PIC16F887 is shown.
© 2008 Microchip Technology Inc.
DS51553E-page 33
PICkit™ 2 User’s Guide
4.4.4
Configuration Bits and Debug Express
PIC microcontroller devices that do not require an ICD Header and may be debugged
directly contain a DEBUG bit in the Configuration Word(s) that enables and disables
the debug mode on the PIC microcontroller.
This bit is automatically set appropriately by the MPLAB IDE when using PICkit 2
Debug Express and should not be specified in source code configuration settings.
CAUTION
The DEBUG configuration bit value should not be specified in source code Configuration settings under normal conditions. Doing so may cause the bit to be asserted when
programming a device outside the debugger. This will cause the device to function
improperly or not all at in the application circuit.
Many 16-bit PIC microcontroller devices such as PIC24 and dsPIC33 families have
multiple ICSP programming and debugging port pins labeled PGC1/EMUC1 and
PGD1/EMUD1, PGC2/EMUC2 and PGD2/EMUD2, etc. While any ICSP port may be
used for programming, only one port is active at a time for debugging. The active EMU
port is set in the device Configuration bits. If the active port setting does not match the
EMU port to which the PICkit 2 is connected, the device will be unable to enter debug
mode. In the MPLAB IDE Configuration Bits dialog, these bits are usually referred to as
the “Comm Channel Select” bits.
4.4.5
Debug Express Breakpoints
The number of active breakpoints supported by PICkit 2 Debug Express depends on
the target device. Most Baseline and Mid-Range devices support 1 breakpoint, with
more breakpoints supported in some PIC18 and 16-bit devices.
The number of active breakpoints available for the current device in MPLAB IDE can
be seen by selecting Debugger & gt; Breakpoints…. This will open a dialog (Figure 4-3)
showing any currently set breakpoints in Program Memory. The “Active Breakpoint
Limit:” text box shows how many total breakpoints are available for the current device.
The “Available Breakpoints:” text box shows how many breakpoints are currently
unused.
FIGURE 4-3:
BREAKPOINTS DIALOG FOR PIC16F887
Some PIC18 and 16-bit devices also support advanced breakpoints. Advanced breakpoints allow breakpoints to be set in File Register memory, and will halt execution when
a specific File Register is read from or written to. This breakpoint may also be set so it
will only halt when a specific value is read from or written to a register. Additionally, a
DS51553E-page 34
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
“Pass Count” may be set on any breakpoint type. The pass count is the number of times
the breakpoint condition is met before it halts execution. For example, setting a pass
count of “2” on a Program Memory breakpoint means that instruction will execute twice
without halting execution, and the third time the instruction is executed the breakpoint
will halt execution. The default pass count for all breakpoints is “0”, which means
execution will halt the first time the breakpoint is encountered.
If advanced breakpoints are supported by the current device, the MPLAB IDE menu
option Debugger & gt; Advanced Breakpoints… will be available to open the advanced
breakpoint dialog. If the current device does not support advanced breakpoints, this
menu option will be grayed out or absent. Select the breakpoint to edit with the “Break
Point #” combo box.
FIGURE 4-4:
Note:
4.4.6
ADVANCED BREAKPOINTS DIALOG
The Advanced Breakpoint dialog will display any breakpoints already set in
Program Memory. However, the dialog may not be used to set or clear
breakpoints in Program Memory or to edit the address of an existing Program Memory breakpoint. Only the Pass Count value for Program Memory
breakpoints may be edited in the Advanced Breakpoint dialog. To edit, set,
or clear Program Memory breakpoints, use the MPLAB IDE editor or the
Debugger & gt; Breakpoints… menu dialog.
Breakpoint Skidding
The in-circuit debug implementation on PIC microcontrollers will halt execution on the
instruction after the breakpoint instruction. This means the breakpoint instruction will
have executed when the debugger halts. This is referred to as “breakpoint skidding”.
As a result, there are some breakpoint behaviors to be aware of. When a breakpoint is
set on a GOTO, CALL, or RETURN instruction, the debugger will halt at the destination
instruction, as the program branch instruction with the breakpoint will have executed.
Also, when using the debugger Step Over function, a breakpoint will be set on the
instruction after the CALL instruction that the debugger is “stepping over” if there is an
available breakpoint. If the CALL instruction is followed immediately by another CALL
instruction, this will result in the debugger halting at the destination of the second CALL
instruction. To prevent this, a NOP may be placed between the CALL instructions.
Note that 16-bit devices will halt two instructions after the breakpoint instruction.
© 2008 Microchip Technology Inc.
DS51553E-page 35
PICkit™ 2 User’s Guide
4.4.7
Linker Scripts
If your project uses a linker script, special ICD linker script files must be used when
debugging that reserve the resources used by the PICkit 2 Debug Express. Each
device has a separate debug linker file, which contains an “i” at the end of the device
name.
For example:
16F877i.lkr – In-Circuit Debug linker file for the PIC16F877 device
18F4520i.lkr – In-Circuit Debug linker file for the PIC18F4520 device
When debugging with PICkit 2 Debug Express, the ICD linker file should be used
instead of the standard linker file.
4.5
DEBUG EXPRESS TUTORIAL
This tutorial is intended to be used with the PICkit 2 44-Pin Demo Board and
PIC16F887 microcontroller. This demo board comes with the PICkit 2 Debug Express
kit and is available separately as part number DM164120-2.
If this demo board is not available, it is still recommended to read through this tutorial
to get an overview of using the PICkit 2 as a debugger in the MPLAB IDE.
The source file used for the tutorial is installed with the PICkit 2 Programmer software.
4.5.1
Selecting the Device
To select a device in MPLAB IDE:
1. Launch the MPLAB IDE application.
2. From the MPLAB IDE menu bar, select Configure & gt; Select Device (Figure 4-5).
FIGURE 4-5:
DS51553E-page 36
MPLAB® IDE MENU BAR
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
3. In the Select Device dialog (Figure 4-6), click on the “Device” drop-down list and
select your device. In this tutorial, choose the PIC16F887 device.
FIGURE 4-6:
SELECT DEVICE DIALOG
4. No other changes need to be made in this dialog box. Click OK.
4.5.2
Selecting PICkit 2 as the Debug Tool
1. Select Debugger & gt; Select Tool & gt; PICkit 2. MPLAB IDE will add PICkit 2 debug features (Figure 4-7): (A) the status bar will show PICkit 2 as the debug tool, (B) a
PICkit 2 debug toolbar will be added, (C) the Debugger menu will change to add
PICkit 2 debug functions and (D) the Output window will display communication
status between the PICkit 2 and the target board on the PICkit 2 tab.
FIGURE 4-7:
PICkit™ 2 DEBUG TOOL
C
B
D
A
© 2008 Microchip Technology Inc.
DS51553E-page 37
PICkit™ 2 User’s Guide
2. Select Debugger & gt; Settings to set up PICkit 2 operation. Make sure the “Connect
on Startup” checkbox is checked to enable the auto-connection feature
(Figure 4-8). Then click OK.
FIGURE 4-8:
PICkit™ 2 SETTINGS DIALOG
3. If the PICkit 2 did not connect automatically when it was selected as the debug
tool, select Debugger & gt; Connect to connect now. The connection status will be
visible in the Output window. Depending on the version of the MPLAB IDE software or the selected device, a message may appear indicating that the firmware
(PICkit 2 operating system) needs to be updated. MPLAB IDE will automatically
install new firmware.
4.5.3
Creating an MPLAB IDE Project
An MPLAB IDE project and workspace keep all files and settings for a development
project together. The Project Wizard helps you set up a new project.
1. Select Project & gt; Project Wizard to set up the project. The Project Wizard Welcome
screen will display (Figure 4-9). Click Next to continue to Step One.
FIGURE 4-9:
DS51553E-page 38
PROJECT WIZARD WELCOME
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
2. Select the PIC16F887 device from the “Device” drop-down box, if it is not already
selected (Figure 4-10). Click Next to continue to Step Two.
FIGURE 4-10:
STEP ONE – SELECT DEVICE
3. For this project, the MPASM™ assembler tool will be used. Select “Microchip
MPASM Toolsuite” from the Active Toolsuite drop-down menu (Figure 4-11).
Make sure the tools are set to the proper executables by default in the
C:\Program Files\Microchip\MPASM Suite folder as follows:
- MPASM assembler should be pointing to mpasmwin.exe.
- MPLINK™ object linker should be pointing to mplink.exe.
- MPLIB™ object librarian should be pointing to mplib.exe.
Click Next to continue to Step Three.
FIGURE 4-11:
© 2008 Microchip Technology Inc.
STEP TWO – SELECT LANGUAGE SUITE
DS51553E-page 39
PICkit™ 2 User’s Guide
4. Click Browse (Figure 4-12) to locate or create a new project directory and
project name. For this tutorial, select the location
C:\Program Files\Microchip\PICkit 2 v2\DBE Demo and give the
project file a name, such as “PIC16F887 Debug Demo”.
FIGURE 4-12:
STEP THREE – CREATE NEW PROJECT
5. Add the project source file (Figure 4-13). From the left pane window, go to
C:\Program Files\Microchip\PICkit 2 v2\DBE Demo. Select and
highlight the 16F887Demo.asm file and click Add. The file will be placed into the
right pane window
Note:
Other files can be added later.
The “A” allows MPLAB IDE to decide whether the path to the file should be relative or absolute for the project. For a description of and how to change to other
possible file-addition modes, see the MPLAB IDE documentation. Do not change
the setting for this project. Click Next to continue to the Summary window.
Note:
DS51553E-page 40
For projects containing more than one assembly file (e.g., multifile
projects, C code project) you will also need to add a linker script file.
See the language tool documentation for more details.
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
FIGURE 4-13:
STEP FOUR – ADD FILES
6. If any errors have been made, click Back to return to any of the previous steps
in the Project Wizard (Figure 4-14). Otherwise, click Finish.
FIGURE 4-14:
4.5.4
PROJECT WIZARD SUMMARY
Viewing the Demo Project
After completing the project setup and exiting the Project Wizard, the Project window
will display in the MPLAB IDE desktop window (Figure 4-15). If it is not open, select
View & gt; Project to open it.
If needed, files can be added to or removed from the project using the Project Window.
Right click on the file in the Project Window tree to display a pop-up menu with options
that include adding or removing files.
© 2008 Microchip Technology Inc.
DS51553E-page 41
PICkit™ 2 User’s Guide
FIGURE 4-15:
4.5.5
PROJECT WINDOW FILE MENU
Creating a Hex File
To create a hex file for programming the device, you need to build the project. Select
Project & gt; Build All, or right click on the project name in the Project Window and select
“Build All” from the pop-up menu. The MPASM assembler will create a hex file with the
same name as the source .asm file. The assembler’s progress will be visible in the
Build tab of the Output window (Figure 4-16).
FIGURE 4-16:
4.5.6
OUTPUT WINDOW – BUILD THE PROJECT
Checking Configuration Bit Values
The Configuration bits that will be programmed into the device are set from within the
program using __CONFIG directives. Once the project is built, the values of these bits
can be verified using the Configuration Bits window. Select Configure & gt; Configuration
Bits to open the window (Figure 4-17.)
The following Configuration bits should now be set for this tutorial:
Config1:
•
•
•
•
•
•
•
•
•
•
DS51553E-page 42
Oscillator – Internal RC No Clock
Watchdog Timer – Off
Power-Up Timer – On
Master Clear Enable – MCLR is external
Code-Protect – Off
Data EE Protect – Off
Brown-Out Detect – BOD and SBOREN Disabled
Internal-External Switch Over Mode – Disabled
Monitor Clock Fail-safe – Disabled
Low-Voltage Program – Disabled
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
Config 2:
• Self Write Enable – No Protection
• Master Brown-out Reset Sel Bit – Brown-out at 2.1V
FIGURE 4-17:
4.5.7
CONFIGURATION BIT SETTINGS
Loading Program Code for Debugging
To program the device, select Debugger & gt; Program to program the 16F887Demo.hex
file into the PIC16F887 on the 44-Pin Demo Board.
Programming will only take a few seconds. During programming, the PICkit 2 tab of the
Output dialog window will display the current phase of operation. When programming
is complete, the dialog should look similar to Figure 4-18.
Note:
Debug executive code is automatically programmed in the upper program
memory of the PIC16F887 (target device) when the PICkit 2 is selected as
a debugger. Debug code must be programmed into the target device to use
the in-circuit debugging capabilities of the PICkit 2.
FIGURE 4-18:
© 2008 Microchip Technology Inc.
OUTPUT WINDOW – PROGRAM DEVICE FOR DEBUG
DS51553E-page 43
PICkit™ 2 User’s Guide
4.5.8
Running the PIC16F887 Debug Demo
The PICkit 2 Debug Express executes the program code in either real-time (Run) or in
steps (Step Into, Step Over, Step Out, Animate.) Real-time execution occurs when you
select Run in MPLAB IDE. When the program is halted, either by Halt or at a
breakpoint, you can step through the code.
The following toolbar buttons can be used for quick access to commonly used debug
operations:
Debugger Menu
Toolbar Buttons
Run
Halt
Animate
Step Into
Step Over
Step Out
Reset
To run the demo code:
1. Double click on the 16F887Demo.asm file from the Project window or select
File & gt; Open from the toolbar menu. The code will appear in a File window.
2. Select Debugger & gt; Run or click Run.
3. Turn the potentiometer (RP1), located on the demo board, and observe the
LEDs.
If the program were working properly, the LEDs would rotate faster or slower depending
on in which direction the potentiometer is turned. However, a bug has been intentionally
placed in the code for debugging demonstration purposes. See
Section 4.5.9 “Debugging the PIC16F887 Debug Demo Code” for debugging
instructions.
4. Select Debugger & gt; Halt or click Halt to stop the program execution. A green solid
arrow will mark the line of code in the File window where the program halted.
5. Select Debugger & gt; Reset & gt; Processor Reset to reset the program. The arrow will
disappear, meaning the device is Reset.
4.5.9
Debugging the PIC16F887 Debug Demo Code
Any of the following issues can prevent the PIC16F887 Debug Demo program from
working properly:
1. The A/D converter value is not being written properly to the Delay routine.
2. The A/D converter is not enabled or has not been set to convert.
3. A typing error in the source code has caused the program to function improperly.
To explore the issue listed first, set a breakpoint at the line of code that writes the value
of the A/D result to the high-order Delay byte:
1. Place the cursor on the following line of code in the 16F887Demo.asm file:
movwf Delay+1, as shown in Figure 4-19.
At this breakpoint, the program will stop once the A/D conversion has completed.
2. Either right click on the line to display a drop-down menu and select
“Set Breakpoint” or double click on the line. A breakpoint symbol will appear next
to the line as the letter B in a solid red octagon, as shown in Figure 4-19.
DS51553E-page 44
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
FIGURE 4-19:
SET BREAKPOINT
3. Select Debugger & gt; Run, or click Run to run the program. The breakpoint will stop
the program’s execution when the program executes the line marked as a
breakpoint.
Note:
Depending on the device, breakpoint halts may “skid” past the
breakpoint location. In this case, the program will halt on the line:
incfsz
Delay,f
4. Mouse over ADRESH in the line above the breakpoint and it will show the value
of the file register (Figure 4-20).
FIGURE 4-20:
ADRESH REGISTER VALUE
5. Adjust the potentiometer (RP1) and continue the program execution by selecting
Debug & gt; Run. The program will run through the loop and halt again.
6. Mouse over ADRESH again to see that the A/D result has not changed. Thus it
seems the A/D conversion is not working. The A/D conversion initialization and
setup occurs at the beginning of the program.
7. Select Debugger & gt; Reset to reset the program.
8. Select View & gt; Watch to open a new Watch window. This window will allow you to
watch the A/D register value change as the program executes. The Watch dialog
opens with the Watch 1 tab selected, as shown in Figure 4-21.
© 2008 Microchip Technology Inc.
DS51553E-page 45
PICkit™ 2 User’s Guide
FIGURE 4-21:
Note:
NEW WATCH WINDOW
It is not recommended to use the View & gt; File Registers and View & gt; Special
Function Registers windows when debugging with PICkit 2 Debug Express.
When these windows are open, the entire contents must be written then
read back from the target device on every operation. This may slow down
debugging operations significantly. Instead, only add the SFR and File
Register variables of interest to a Watch window as described in this
tutorial.
9. Select ADCON0 from the first drop-down list and then click Add SFR to add
ADCON0 to the Watch window. Repeat this to add ADCON1 and ADRESH to the
Watch window. The selected SFRs should be visible in the Watch window as
shown in Figure 4-22.
FIGURE 4-22:
ADD SFRs TO WATCH
10. Select Debugger & gt; Run to the run the program. Again, the program will stop after
it reaches the breakpoint.
11. Examine the values of the ADCON0 and ADCON1 registers in the Watch
window. The ADCON0 value is ‘0x40’ (b’01000000’). This corresponds to the
hex value designated in the program. However, this is not correct. A review of the
“PIC16F882/883/884/886/887 Data Sheet” (DS41291), Analog-to-Digital (A/D)
Converter Module section, indicates that the last bit should be a ‘1’
(b’01000001’) to turn on the A/D module. To fix this bug, change:
movlw 0x40
to
movlw 0x41, as shown in Figure 4-23.
DS51553E-page 46
© 2008 Microchip Technology Inc.
PICkit 2 Debug Express
FIGURE 4-23:
A/D MODULE CODE
12. Select File & gt; Save to save your changes.
13. You must rebuild the project and reprogram the device for the changes to take
effect. Select Project & gt; Build All to rebuild the project and then select
Debugger & gt; Program to reprogram the device using the PICkit 2.
14. Select Debugger & gt; Run to the run the program. Again, the program will stop after
it reaches the breakpoint.
15. Examine the values in the Watch window. This time, ADCON0 should be 0x41
(Figure 4-24).
FIGURE 4-24:
ADCON CORRECT VALUE
16. Right click on the line of code that marked by the breakpoint and select
Remove & gt; Breakpoint or double click on the line to remove the breakpoint.
17. Select Debugger & gt; Run to run the program real-time. Turn the potentiometer
(RP1) to change the value displayed on the LEDs. Now it works!
The source code in this tutorial contained only one bug. However, real code may have
more. Using MPLAB IDE with PICkit 2 debugging functions, you can successfully find
and fix problems in your code.
© 2008 Microchip Technology Inc.
DS51553E-page 47
PICkit™ 2 User’s Guide
4.5.10
Programming the Debugged Application
When the program is successfully debugged and running, the next step is to program
the device for stand-alone operation in the finished design. When doing this, the
resources reserved by the ICD are released for use by the application. To program the
application, use the following steps:
1. Disable PICkit 2 as a debug tool by selecting Debugger & gt; Select Tool & gt; None.
2. Select PICkit 2 as a programmer in the Programmer & gt; Select Programmer menu.
3. Optional: Set up the ID in Configure & gt; ID Memory (Figure 4-25).
FIGURE 4-25:
USER ID MEMORY
4. Set up the parameters for programming on the Programmer & gt; Settings, Program
tab.
5. Select Programmer & gt; Program.
Now the target will run independently.
DS51553E-page 48
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Chapter 5. Troubleshooting
5.1
INTRODUCTION
This chapter describes questions and answers to common problems associated with
using the PICkit 2 Development Programmer/Debugger. It also gives information on
the PICkit 2 Debug Express MPLAB IDE errors.
• Frequently Asked Questions
• PICkit 2 Debug Express MPLAB IDE Errors
5.2
FREQUENTLY ASKED QUESTIONS
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Device is Not Recognized
Current Limit Exceeded
Microsoft Windows Driver
Verify and Read Return All Zeros
Microsoft Windows 95/98/NT
VDD/VPP Errors
Programming Errors
Windows Error: Unrecognized USB Device
PICkit 2 Not Found
PICkit 2 Programmer Application Locks Up
Low Pin Count Demo Board Push Button Not Working
Using the Demo Board Lessons
Programming Fails on Configuration
Unable to Program PIC10F Devices
The PICkit 2 AUX Pin
PICkit 2 HEX File Format
Window Display Problems
Memory Locations are marked ‘RR’
Debug Express is Slow
Debug Express Overshoots Breakpoint
Device is Not Recognized
Question
Why am I receiving a “No Device Found” message?
Answer
Verify that the device is supported and that the target MCU is connected to the PICkit 2
in accordance with Chapter 3. “Using In-Circuit Serial Programming™ (ICSP™)”.
Verify that PIC18FXXJXX, PIC24X, and dsPIC33F devices have an appropriate
capacitance on the VDDCORE/VCAP pin in accordance with the device data sheet.
Verify that the device is a member of the currently active family displayed at the top of
the Status window. Select the correct family from the Device Family menu if needed.
See also the Programming Fails on Configuration topic.
© 2008 Microchip Technology Inc.
DS51553E-page 49
PICkit™ 2 User’s Guide
Current Limit Exceeded
Question
Why am I receiving the error message “USB Hub Current Limit Exceeded” from the
Microsoft® Windows® program?
Answer
Verify that the application circuit is not drawing more than 25 mA from the PICkit 2.
Microsoft Windows Driver
Question
After plugging the PICkit 2 unit into the USB port, Windows 98 SE asks for a driver.
Where is the driver?
Answer
The PICkit 2 uses the drivers included with Windows 98 SE. When Windows 98 SE
prompts for a driver, select “Search for the best driver for your device.” Then select the
checkbox next to “Microsoft Windows Update” and click Next. Windows OS will
automatically install the appropriate driver. Do not use Microchip’s MPLAB ICD 2 USB
device driver.
Verify and Read Return All Zeros
Question
When Verify or Read are clicked, the Program Memory window comes up with all
zeros. What is wrong?
Answer
The device may be code-protected. Ensure code protection has not been selected in
the Configuration Word.
Microsoft Windows 95/98/NT
Question
Can I run on Windows 95/98/NT?
Answer
No. These operating systems either do not support USB or have drivers that are not
compatible.
VDD/VPP Errors
Question
Why do I keep getting a “VDD Error” or “VPP Error”?
Answer
This error indicates that the PICkit 2 is not able to drive VDD or VPP to the intended voltage. Check the circuit board for shorts, for large current draw and verify that the target
device is connected to the PICkit 2 in accordance with Chapter 3. “Using In-Circuit
Serial Programming™ (ICSP™)”. Make sure that VDD capacitance is not reducing
the VDD rise time longer than 500 μs.
DS51553E-page 50
© 2008 Microchip Technology Inc.
Troubleshooting
Programming Errors
Question
Why am I able to program some parts but not others?
Answer
If some parts are configured for Low-Voltage Programming, a floating PGM pin can
interfere with programming. Use a resistor to pull this pin low when programming.
Some Mid-Range parts, such as the PIC16F72/73/74/76/77 family and
PIC16F737/747/767/777 family require a minimum programming VDD of +4.75V.
Depending on the USB voltage, the PICkit 2 may not be able to supply +4.75V on VDD.
Program these parts using an external +5.0V power supply.
Some PIC18F parts require significant bypass capacitance on VDD. Try increasing the
total bypass capacitance up to 10 uF.
PIC18FXXJXX, PIC24X, and dsPIC30F/33F devices require a 4.7 uF capacitor on the
VDDCORE/VCAP pin in order to function properly. If not using a separate regulator to supply VDDCORE, ensure that the ENVREG pin is tied to VDD.
Windows Error: Unrecognized USB Device
Question
Why do I get an “unrecognized device” error when plugging my PICkit 2 into USB?
Answer
This error may occur if PICkit 2 is plugged into USB while connected to a target circuit
board. When plugging PICkit 2 in a PC, restarting or booting up a PC, ensure the
PICkit 2 is not connected to a target device.
This error may also occur when PICkit 2 is used with some USB hubs. If the PICkit 2 is
plugged into a USB hub port, try plugging the PICkit 2 directly into a PC USB port.
PICkit 2 Not Found
Question
I have my PICkit 2 plugged into USB, but the PICkit 2 Programmer application keeps
saying “PICkit 2 Not Found?
Answer
Please see the answer for Windows Error: Unrecognized USB Device.
PICkit 2 Programmer Application Locks Up
Question
Why is the PICkit 2 Programmer window locking up?
Answer
Often times, the software hasn’t truly locked up. During a programming operation the
PICkit 2 application user interface is inactive. Until the programming operation is complete, the Windows OS may stop updating the PICkit 2 if another application is brought
into focus or the PICkit 2 has just been brought back into focus. Once the programming
operation is complete, the application window will update. For large memory parts, programming may take several minutes. For 8-bit devices, try waiting at least 2 minutes
before concluding the software has truly locked up. For 16-bit devices, try waiting 5
minutes for the operation to complete.
© 2008 Microchip Technology Inc.
DS51553E-page 51
PICkit™ 2 User’s Guide
There are a few USB controller chipsets that appear to cause lockup problems with the
PICkit 2, which seem to be more common in laptops. This can usually be worked
around by connecting a USB hub between the PC and the PICkit 2 unit, or using a USB
Cardbus adapter. Using a USB hub with an external power supply is recommended.
Low Pin Count Demo Board Push Button Not Working
Question
When I run the Low Pin Count Demo Board Lessons, why doesn’t the push button
work?
Answer
When programming the lessons from within MPLAB IDE, the IDE always maintains an
output voltage on the PICkit 2 MCLR-VPP pin. On the Low Pin Count and 28-pin Demo
Boards, the push button signal is connected to the MCLR signal. The PICkit 2 output
interferes with the push button signal.
Use the PICkit 2 Programmer software application to program and run the Low Pin
Count Demo Board Lessons.
Additionally, future versions of the MPLAB IDE will optionally allow the MCLR-VPP pin
to be tri-stated when the device is “Released from Reset”. Check
Programmer & gt; Settings for this option. Note that this option would not apply during
debugging.
Using the Demo Board Lessons
Question
Where are the included lessons? Is there any documentation on them?
Answer
The Starter Kit and Debug Express kit lessons may be installed from the included PICkit
2 CD-ROM. The lessons will be installed to the local hard drive under
C:\Pk2 Lessons\.
The documentation for the lesson projects is in the user’s guide for the included demo
Board. For the Starter Kit, see the “Low Pin Count Demo Board User’s Guide”
(DS51556). For the Debug Express Kit, see the “44-Pin Demo Board User’s Guide”
(DS41296). Both of these documents may be opened from the PICkit 2 Programmer
Help menu.
Programming Fails on Configuration
Question
Why does programming a device always fail on the Configuration Word(s), after which
PICkit 2 won’t recognize the device?
Answer
This may be caused by a Configuration setting or program code that affects the ICSP
PGD and PGC pins. This interference can prevent the target PIC MCU from entering
programming mode.
Check the menu option Tools & gt; Use VPP First Program Entry when attempting a programming operation on these devices. This program mode entry will usually get around
the problem, but it requires that the target device be powered from the PICkit 2 unit VDD
pin.
DS51553E-page 52
© 2008 Microchip Technology Inc.
Troubleshooting
Unable to Program PIC10F Devices
Question
Why won’t my PIC10F parts program in the Low Pin Count Demo Board?
Answer
The Low Pin Count Demo Board supports 8-pin devices. The PIC10F parts are 6-pin
devices, even though they can be ordered in an 8-pin DIP. The PIC10F pinout is not
compatible with the Low Pin Count Demo Board. Instead, the AC163020 PIC10F2XX
Programming Adapter should be used.
The PICkit 2 AUX Pin
Question
What is the AUX pin for? How do I connect it?
Answer
The PICkit 2 AUX pin is not used for programming PIC microcontrollers, and should be
left unconnected. The AUX pin is only used when programming some Serial
EEPROMS. See the PICkit 2 Readme file (Help & gt; Readme) for EEPROM connection
information.
PICkit 2 HEX File Format
Question
What HEX file format does the PICkit 2 Programmer application use?
Answer
The PICkit 2 Programmer application uses the Intel Hex 32 Format, often referred to
as INHX32. However, PICkit 2 does not support record types 03 and 05. Least
Significant Bytes are at lower hex file addresses (little Endian format).
Window Display Problems
Question
Why is the PICkit 2 Programmer application displaying Program Memory and/or
EEPROM Data locations as all periods “…”? Why can’t I close the Help & gt; About dialog?
Answer
These issues are frequently caused by non-standard monitor DPI settings. This can be
corrected by setting the DPI to the Normal setting, 96 DPI. To do this
1. Right click on the Windows desktop background and select Properties from the
pop-up menu. This will open the Display Properties dialog.
2. In the Display Properties dialog, select the Settings tab.
3. On this tab, click Advanced to open the Monitor dialog.
4. In the Monitor dialog, select the General tab.
5. On this tab, change the “DPI setting:” to “Normal size (96 DPI)
6. Click Apply, then the OK button to close the dialog.
7. Click OK to close the Display Properties dialog.
It may be necessary to restart the PC for the changes to take effect.
© 2008 Microchip Technology Inc.
DS51553E-page 53
PICkit™ 2 User’s Guide
Memory Locations are marked ‘RR’
Question
Why does the File Register window or Program Memory show some locations marked
with ‘RR’?
Answer
These are locations that are reserved by ICD debuggers including PICkit 2 Debug
Express during debugging for the debug executive. See Section 4.4.2 “Reserved
Resources”.
Debug Express is Slow
Question
Why is debugging with PICkit 2 so slow?
Answer
Opening the View & gt; File Registers or View & gt; Special Function Registers windows in the
MPLAB IDE can significantly slow down debugging, due to the volume of information
being exchanged though the debugger. Use a Watch window instead as discussed in
Section 4.5.9 “Debugging the PIC16F887 Debug Demo Code”.
The debug interface is also directly affected by the target device oscillator speed. When
debugging with an oscillator less than 1 MHz, a slowdown in debugging performance
may be noticed.
Debug Express Overshoots Breakpoint
Question
Why isn’t PICkit 2 Debug Express stopping on the breakpoint instruction?
Answer
This behavior is referred to as “breakpoint skidding” and is covered in
Section 4.4.6 “Breakpoint Skidding”.
5.3
PICKIT 2 DEBUG EXPRESS MPLAB IDE ERRORS
PK2Error0002: Allocation failure (Component)
PK2Error0003: Missing component (Component)
PK2Error0005: Failed to acquire component (Component, HRESULT)
PK2Error0006: Failed external call (Component, Method, HRESULT)
Description: An error occurred initializing a PICkit 2 component, during an internal
operation, or when communicating with the MPLAB IDE environment. The most
probable cause is an incomplete or corrupted installation.
Suggested Actions:
1. Uninstall all versions of MPLAB IDE from the PC.
2. Reinstall the desired MPLAB IDE version.
3. If the problem persists contact Microchip.
PK2Error0008: Read failure (GetLastError)
PK2Error0009: Write failure (GetLastError)
Description: MPLAB IDE was unable to communicate with the PICkit 2. Possible
causes include the PICkit 2 not enumerating properly on USB, a target board causing
a USB overcurrent condition or problems with a USB hub.
DS51553E-page 54
© 2008 Microchip Technology Inc.
Troubleshooting
Suggested Actions: Ensure the target board does not pull more than 25 mA of current
from the PICkit 2. If it does, use an external power supply with the target board.
A target board may interfere with PICkit 2 enumerating on USB. When connecting
PICkit 2 to a USB port, booting or restarting a connected PC, ensure the PICkit 2 is disconnected from the target board.
If the PICkit 2 is connected to a USB hub, try connecting the PICkit 2 directly to a PC
USB port.
When using PICkit 2 as a programmer or debugger in the MPLAB IDE, do not run the
PICkit 2 Programmer application or PK2CMD at the same time.
If the problem persists, try connecting to PICkit 2 using the PICkit 2 Programmer
application.
PK2Error0010: Failed to unload PICkit 2
Description: MPLAB IDE was unable to disconnect from PICkit 2 as a debugger or
programmer when switching to the other tool mode.
Suggested Actions: Disconnect the PICkit 2 from USB, reboot the computer, then
reconnect PICkit 2 to USB (ensure the PICkit 2 is not connected to a target board.) If
the problem persists contact Microchip.
PK2Error0011: PICkit 2 is already busy. Unable to perform requested
task.
Description: PICkit 2 Debug Express has been asked to perform an operation while it
is busy servicing a prior request. For example, a programming operation may still be
process when a debug Step operation is attempted.
Suggested Actions: This situation will not normally happen as the user interface is
disabled while PICkit 2 is servicing requests. Wait for the original operation to
complete.
PK2Error0012: Unable to open file (Filename)
Description: PICkit 2 Debug Express was unable to open the specified file.
Suggested Actions: Ensure the file exists, and file or directory permissions do not prevent access to the file. This may also be caused by an incomplete or corrupted
installation. See PK2Error0002 Suggested Actions.
PK2Error0013: Bad hex line (File - Line)
PK2Error0014: Invalid address in hex file (File - Line - Address)
Description: PICkit 2 Debug Express detected an error in a debug executive hex file.
Suggested Actions: Since all debug executive hex files are provided by Microchip, the
issue is most likely a corrupted installation. See PK2Error0002 Suggested Actions.
PK2Error0015: Failed Windows call (WinFunc - GetLastError)
Description: A call to a Windows function within PICkit 2 Debug Express has failed.
This internal error is primarily meant for debugging purposes.
Suggested Actions: This may be caused by existed system resources or a corrupted
installation.
1. Try rebooting your system to free up memory.
2. Make sure you have a reasonable amount of free space on your hard drive, and
that it is not overly fragmented.
3. See PK2Error0002 Suggested Actions for a corrupted installation.
© 2008 Microchip Technology Inc.
DS51553E-page 55
PICkit™ 2 User’s Guide
PK2Error0016: Failed to find firmware files (MPLABDir)
Description: PICkit 2 Debug Express was unable to find the PICkit 2 Operating System
firmware files.
Suggested Actions: This is likely caused by an incomplete or corrupted installation. See
PK2Error0002 Suggested Actions.
PK2Error0017: Invalid hex file (Filename - Start - End)
Description: PICkit 2 Debug Express detected an error in a PICkit 2 Operating System
hex file.
Suggested Actions: Since all Operating System hex files are provided by Microchip, the
issue is most likely a corrupted installation. See PK2Error0002 Suggested Actions.
PK2Error0018: Unable to enter bootloader
Description: PICkit 2 Debug Express was unable to access the PICkit 2 unit bootloader
while updating the PICkit 2 Operating System.
Suggested Actions: Disconnect the PICkit 2 unit from USB and the target board. While
holding the PICkit 2 unit push button down, plug the PICkit 2 unit back into the USB
port. The BUSY LED should flash slowly. If it does not, the bootloader may be
corrupted. Contact Microchip about the problem.
PK2Error0019: Failed PICkit OS read ([1] - [2] - [3] - [4])
Description: An error occurred while communicating with the PICkit 2 bootloader.
Suggested Actions: Remove the PICkit 2 unit from USB and the target board, reboot
the PC, reconnect the PICkit 2 unit to USB and retry the operation. If this does not work,
try updating the firmware using the PICkit 2 Programmer application.
PK2Error0020: Failed PICkit OS verify (Address - Read - Expected)
Description: The download of a PICkit 2 Operating System to the PICkit 2 unit failed.
Suggested Actions: Remove the PICkit 2 unit from USB and the target board, reboot
the PC, reconnect the PICkit 2 unit to USB and retry the operation. If this does not work,
try updating the firmware using the PICkit 2 Programmer application.
PK2Error0021: Unable to exit bootloader
Description: PICkit 2 Debug Express failed to exit the PICkit 2 bootloader mode after
downloading a PICkit 2 Operating System to the unit.
Suggested Actions: Remove the PICkit 2 unit from USB and the target board, reboot
the PC, reconnect the PICkit 2 unit to USB and retry the operation. If this does not work,
try updating the firmware using the PICkit 2 Programmer application.
PK2Error0022: PICkit 2 not found
Description: MPLAB IDE is not able to detect the PICkit 2 device on any USB port.
Suggested Actions: See PK2Error0008 Suggested Actions.
PK2Error0023: Target VDD measured at X.XV which is outside the
operational range of this device (minV - maxV)
Description: The target power supply is outside the voltage range supported by PICkit 2
for the current device. This may be due to device Bulk Erase limitations or PICkit 2
hardware limitations.
DS51553E-page 56
© 2008 Microchip Technology Inc.
Troubleshooting
Suggested Actions: Use a target VDD voltage within the given range. If the target VDD
is close to one limit but within the given limits and this error appears, try calibration the
PICkit 2 unit with the PICkit 2 Programmer software so the target voltage is read more
accurately.
PK2Error0024: PICkit 2 was unable to establish a valid VDD on the target
(Attempted V - Read V)
Description: PICkit 2 was unable to provide the intended VDD voltage to the target. This
is usually caused by a heavy VDD load.
Suggested Actions: Power the target board externally, and/or try calibrating the
PICkit 2 unit with the PICkit 2 Programmer software.
PK2Error0025: Failed to load PICkit 2
Description: PICkit 2 Debug Express encountered a fatal error while attempting to load
in the MPLAB IDE.
Suggested Actions: This is likely caused by an incomplete or corrupted installation. See
PK2Error0003 Suggested Actions.
PK2Error0027: Failed verify (Address - Expected Value - Value Read)
Description: A verify operation failed. The error message specifies the memory type
and address involved, and gives the expected value and the value actually read. A verify operation on a previously programmed and code protected part will fail, as the code
protection feature returns all zeroes when the memory is read.
Note:
PICkit 2 Debug Express will terminate the verify operation upon the first
incorrect value read from the target. Only this first incorrect value will be
reported. There may be others.
Suggested Actions: Ensure the device is not code protected. Check the ICSP connections as described in Chapter 3. “Using In-Circuit Serial Programming™ (ICSP™)”.
If the target device has AVDD and AVSS pins, check that these are properly connected.
Verify that PIC18FXXJXX, PIC24X, and dsPIC33F devices have an appropriate capacitance on the VDDCORE/VCAP pin in accordance with the device data sheet. Some
PIC18F devices may require up to 10 uF of capacitance on the VDD pin to program
properly.
PK2Error0028: Unable to enter debug mode
Description: PICkit 2 Debug Express is unable to connect to the debug executive in the
target device.
Suggested Actions: Common reasons for this error:
1. If the target is a Baseline or Mid-Range device (PIC10F, PIC12F, PIC16F) it may
require an ICD header to debug with. See Section 4.4.3 “Using an ICD
Header”.
2. The device oscillator is not working. Check the Configuration bits and ensure the
device has a working oscillator.
3. Make sure to select Debugger & gt; Program in MPLAB IDE before trying to run or
step your code.
4. If you have a PICkit 2 with a black colored push button, you may need pull-down
resistors to debug reliably. See Section 4.3 “Installing the Hardware and
Software”.
5. The target board is not powered or is not powered properly. Check the power
supply.
6. The PICkit 2 VDD output pin has not been connected to the target board. Even if
© 2008 Microchip Technology Inc.
DS51553E-page 57
PICkit™ 2 User’s Guide
7.
8.
9.
10.
11.
12.
13.
the target board has its own power supply, this pin must always be connected to
the target VDD supply.
The PICkit 2 unit has become disconnected from the target board or has an intermittent connection on one or more pins. Check the PICkit 2 connections to the
target board.
The incorrect Linker Script was used. The “-i” ICD linker script must be used
when debugging. (For example, 16F887i.lkr must be used instead of 16F887.lkr).
The target application is attempting to use resources reserved for the debug
executive, causing the debug executive to become corrupted. For example, the
target application is writing to a reserved File Register. See
Section 4.4.2 “Reserved Resources”.
For PIC24 and dsPIC® DSC devices, the incorrect PGXn/EMUXn port is selected
in the “Comm Channel Select” Configuration bits. Check that the port the PICkit 2
Debug Express is connected to is selected.
A configuration setting may be preventing the target from operating properly and
executing code. The target will not enter Debug mode if it is unable to execute
code.
The device is code-protected. Check Configuration bits for code protect settings.
An operation may be attempting in an invalid context. For example, PICkit 2
Debug Express cannot set a breakpoint if the target application is currently
running.
PK2Error0029: Failed PICkit 2 operation
Description: PICkit 2 Debug Express failed to complete a debug operation, such as a
“Halt” or “Step” operation.
Suggested Actions: See PK2Error0028 Suggested Actions.
PK2Error0030: Failed to read target file registers
Description: PICkit 2 Debug Express was unable to complete a read of one or more
target File Registers.
Suggested Actions: See PK2Error0028 Suggested Actions.
PK2Error0031: I/O Operation timeout
Description: A PICkit 2 USB operation timed out.
Suggested Actions: Try the operation again. If it continues to fail, remove the PICkit 2
unit from USB and the target board, reboot the PC, reconnect the PICkit 2 unit to USB
and retry the operation. If this does not work, try updating the firmware using the
PICkit 2 Programmer application.
PK2Error0032: Failed Blank Check (Address - Expected Value - Value Read)
Description: A Blank Check operation failed. The error message specifies the memory
type and address involved, and gives the expected blank value and the value actually
read.
Note:
PICkit 2 Debug Express will terminate the Blank Check operation upon the
first incorrect value read from the target. Only this first incorrect value will
be reported. There may be others.
Suggested Actions: Try erasing the device. If the device is not blank after an erase
check the ICSP connections as described in Chapter 3. “Using In-Circuit Serial Programming™ (ICSP™)”. If the target device has AVDD and AVSS pins, check that these
are properly connected. Verify that PIC18FXXJXX, PIC24X, and dsPIC33F devices
DS51553E-page 58
© 2008 Microchip Technology Inc.
Troubleshooting
have an appropriate capacitance on the VDDCORE/VCAP pin in accordance with the
device data sheet. Some PIC18F devices may require up to 10 uF of capacitance on
the VDD pin to erase properly.
PK2Error0033: User aborted operation
Description: This error is usually given if PICkit 2 Debug Express has popped up a
warning and the user opted to cancel the current operation. For example, PICkit 2
Debug Express may warn that a debug target cannot be programmed with the MCLR
pin disabled. If the user clicks Cancel in the warning dialog, the programmed operation
will be aborted with this error.
Suggested Actions: None.
PK2Error0034: Failed to Initialize
Description: A PICkit 2 Debug Express component was unable to complete its
initialization sequence.
Suggested Actions: This is likely caused by an incomplete or corrupted installation. See
PK2Error0002 Suggested Actions.
PK2Error0035: Failed to retrieve XML Data (node)
PK2Error0036: Failed to open PK2 Script File (filename)
PK2Error0037: PK2 Script File structure size mismatch (struct internal
size file size)
PK2Error0038: Unable to fit block in IO buffer (MemType Direction
Blocksize)
Description: PICkit 2 Debug Express internal error.
Suggested Actions: This is likely caused by an incomplete or corrupted installation. See
PK2Error0002 Suggested Actions.
PK2Error0039: Not halted in debug executive
Description: An operation was attempted that can only be completed when the target
is halted while the target is running application code. This may occur if PICkit 2 Debug
Express is unable to halt the target.
Suggested Actions: Halt the target before attempting the operation again.
PK2Error0040: Operation not supported for current device
Description: The attempted debug operation is not supported for the current target.
Suggested Actions: None.
PK2Error0041: Failed to create Stream
PK2Error0042: Failed Stream Read
PK2Error0043: Failed IStream Write
PK2Error0044: Failed IStream Open
PK2Error0045: No STATSTG
PK2Error0046: Failed IStream Read
PK2Error0047: Failed Stream Write
Description: PICkit 2 Debug Express internal error.
Suggested Actions: This is likely caused by an incomplete or corrupted installation. See
PK2Error0002 Suggested Actions.
© 2008 Microchip Technology Inc.
DS51553E-page 59
PICkit™ 2 User’s Guide
NOTES:
DS51553E-page 60
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Chapter 6. Updating the PICkit 2 Operating System
6.1
INTRODUCTION
How to update the operating system (firmware) for the PICkit 2 Development
Programmer/Debugger is described here.
• Updating the PICkit 2 OS - PICkit 2 Programmer Application
• Updating the PICkit 2 OS – MPLAB IDE
6.2
UPDATING THE PICkit 2 OS - PICkit 2 PROGRAMMER APPLICATION
When the PICkit 2 Programmer application is launched, it will check the firmware version of the PICkit 2 to see if it is the latest version. If not, it will attempt to automatically
download the latest version (Figure 6-1).
FIGURE 6-1:
UPDATE PICkit™ 2 OS WARNING
If there is an error in the automatic download, if you need a different operating system
(OS), or if you have been instructed to do so, you may manually update the OS.
To update the PICkit 2 firmware/OS manually, complete the following steps:
1. Download the latest PICkit 2 firmware/OS from the Microchip web site at
www.microchip.com and place the file in the PICkit 2 installation directory. By
default, the location is:
C:\Program Files\Microchip\PICkit 2 v2
© 2008 Microchip Technology Inc.
DS51553E-page 61
PICkit™ 2 User’s Guide
2. Select Tools & gt; Download PICKit 2 Operating System as shown in Figure 6-2.
FIGURE 6-2:
DOWNLOAD PICkit™ 2 OS
3. Browse to the directory where the latest firmware/OS file was saved.
4. Select the PK2*.hex file and click on the Open button.
The progress of the OS update will be displayed in the status bar of the programming software and the Busy LED on the PICkit 2 will flash. When the update
completes successfully, the status bar will display “Operating System Verified”
and the Busy LED will go out. The firmware/OS update is then complete.
6.3
UPDATING THE PICkit 2 OS – MPLAB IDE
When PICkit 2 is chosen as either the debug tool or programmer in MPLAB IDE,
MPLAB IDE will check the firmware version of the PICkit 2 to see if it is the latest version. If not, it will attempt to automatically download the latest version. Its progress is
recorded in the Output window on the PICkit 2 tab (Figure 6-3).
FIGURE 6-3:
UPDATE PICkit™ 2 OS PROGRESS
If there is an error in the automatic download, if you need a different operating system
(OS), or if you have been instructed to do so, you may manually update the OS.
To update the PICkit 2 firmware/OS manually, complete the following steps:
1. Download the latest PICkit 2 firmware/OS from the Microchip web site at
www.microchip.com and place the file in the PICkit 2 installation directory. By
default, the location is:
C:\Program Files\Microchip\MPLAB IDE\PICkit 2
2. Select PICkit 2 as the debug tool (Debugger & gt; Select Tool & gt; PICkit 2) or programmer (Programmer & gt; Select Programmer & gt; PICkit 2).
DS51553E-page 62
© 2008 Microchip Technology Inc.
Updating the PICkit 2 Operating System
3. Select Debugger & gt; Download OS or Programmer & gt; Download OS as in Figure 6-4.
FIGURE 6-4:
DOWNLOAD PICkit™ 2 OS FROM MPLAB® IDE
4. MPLAB IDE will proceed to download the latest firmware/OS file to the PICkit 2.
The progress of the OS update will be displayed in the Output window, PICkit 2
tab, and the Busy LED on the PICkit 2 will flash. When the update completes successfully, the text in the PICkit 2 tab will state that “PICkit 2 Ready” and the Busy
LED will go out. The firmware/OS update is then complete.
© 2008 Microchip Technology Inc.
DS51553E-page 63
PICkit™ 2 User’s Guide
NOTES:
DS51553E-page 64
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Chapter 7. PICkit 2 UART Tool
7.1
INTRODUCTION
The PICkit 2 Programmer application versions 2.40 and later include the UART Tool
feature. This feature allows PICkit 2 to be used as a serial UART terminal interface for
communicating with a PIC microcontroller. Potential uses include:
•
•
•
•
Displaying debug text output from the microcontroller
Logging microcontroller data to a text file
Developing and debugging a microcontroller UART interface
Interfacing with and sending commands to the microcontroller during
development
The tool supports full duplex asynchronous serial communications from 150 to 38400
baud, including custom non-standard baud rates. The PICkit 2 connects via the ICSP
connector directly to microcontroller TX and RX pins at logic levels. No transceiver is
needed.
7.2
CONNECTING THE PICkit 2 UART TOOL
The PICkit 2 connects to the target serial port target as shown in Figure 7-1. The
PICkit 2 TX signal (out) should connect to the target RX signal (in), and the PICkit 2 RX
signal (in) should connect to the target TX signal (out).
When being used with the UART Tool, the PICkit 2 may not be able to supply VDD voltage to the target depending on the application version. See the version Release Notes
in the PICkit 2 Readme file. However, even when PICkit 2 is not supplying the target
VDD, the PICkit 2 VDD pin must be connected to the target VDD voltage or it will not be
able to communicate.
The PICkit 2 UART Tool will work with target VDD voltages from 2.5 Volts to 5.0 Volts.
FIGURE 7-1:
PICkit™ 2 UART TOOL
Pin 1 Indicator
Pin Description*
1
2
3
4
5
6
1 = No Connect
2 = VDD Target
3 = VSS (ground)
4 = RX (PICkit 2 In)
5 = TX (PICkit 2 Out)
6 = No Connect
* The 6-pin header (0.100 " spacing) accepts 0.025 " square pins.
© 2008 Microchip Technology Inc.
DS51553E-page 65
PICkit™ 2 User’s Guide
The format of the serial signals on pins 4 and 5 is inverted such that a Start Bit = logic
low (VSS), and a Stop Bit = logic high (VDD). The serial data format is always 8 data bits,
no parity, with one stop bit.
The BUSY LED on the PICkit 2 unit acts as an activity light for the serial connection.
Note:
Even though PICkit 2 may not supply the target VDD, the PICkit 2 VDD pin
must be connected to the target VDD voltage or it will not be able to
communicate.
CAUTION
The PICKIT 2 UART Tool is intended for use at logic level signals only. DO NOT connect
the PICkit 2 UART Tool to RS-232 +/- 12 Volt signals! Doing so may cause damage to the
PICkit 2 unit, your computer USB ports and the target serial port.
7.3
THE PICKIT 2 UART TOOL WINDOW
To open the PICkit 2 UART Tool window, select Tools & gt; UART Tool… (Figure 7-2). The
PICkit 2 Programmer window will open and the PICkit 2 Programmer application window will close, as the programmer cannot be used while the UART Tool is active, and
vice versa.
FIGURE 7-2:
PICkit™ 2 UART TOOL WINDOW ASCII MODE
The UART Tool has two modes: ASCII and HEX. The current mode is selected and displayed by the buttons on the upper right hand of the display. The button corresponding
to the active mode will be displayed depressed. For example, in Figure 7-2 the ASCII
mode is active and so the ASCII button appears pressed.
The mode selection affects how serial data is displayed and entered in the window, and
the modes are explained in the next two sections.
DS51553E-page 66
© 2008 Microchip Technology Inc.
PICkit 2 UART Tool
The window may be resized by clicking and dragging on the lower right corner of the
window.
7.3.1
Setting the Baud Rate and Connecting
The baud rate may be selected from the combo box in the upper left corner of the UART
Tool window. Several common baud rates are listed, and by selecting “Custom…” any
baud rate from 150 to 38400 in 1 baud increments may be used (Figure 7-3).
FIGURE 7-3:
BAUD RATE SELECTION
Once a custom baud rate has been set, it will be available as the last item in the baud
rate selection box (Figure 7-4). Only one custom baud rate may be set at a time. Select
“Custom…” again to change the custom baud rate.
FIGURE 7-4:
CUSTOM 14400 BAUD RATE
After selecting the baud rate, click Connect to enable the UART Tool serial interface at
the selected baud. Once the serial interface has been enabled, it may be disabled by
clicking Disconnect. The baud rate may only be changed while the interface is
disconnected.
7.3.2
ASCII Mode
When ASCII mode is selected, serial bytes received from the target’s UART are displayed as ASCII characters in the main window terminal display. All bytes are displayed
consecutively. To display a new line, the target UART must transmit the character values 0x0D (carriage return) and 0x0A (line feed) in sequence. If one of these values is
sent, or they are sent in reverse order, the character(s) will appear as an unprintable
character (box) in the display.
Bytes may be transmitted in three ways:
1. Click on the terminal display to select it. Any characters typed on the PC
keyboard will be immediately transmitted out of PICkit 2.
2. Right click on the terminal display and select Paste from the pop-up menu to
paste any previous copied or cut text. & lt; Ctrl & gt; + & lt; v & gt; may also be used. Any pasted
data will immediately be transmitted out of PICkit 2.
3. Use the “String Macros” at the bottom of the window.
© 2008 Microchip Technology Inc.
DS51553E-page 67
PICkit™ 2 User’s Guide
No transmitted characters will be displayed if the “Echo On” checkbox is unchecked.
Check this box to display transmitted characters along with received characters in the
terminal display.
The “String Macros” at the bottom of the display allow up to four strings of characters
to be entered. Each string can be up to 60 characters long. When Send next to a string
is clicked, the entire string will be transmitted in sequence out of the PICkit 2. The
“String Macros” strings are saved even when the UART Tool is not in use.
When checked, the “Append CR+LF” checkbox above the string macro boxes will automatically transmit the carriage return (0x0D) and line feed (0x0A) characters at the end
of a string when Send is clicked. When unchecked, nothing is transmitted after the
string characters.
Text in the terminal display may be selected (highlighted) with the cursor and copied
into the clipboard by right clicking and selecting Copy or pressing & lt; Ctrl & gt; + & lt; c & gt; .
7.3.3
Hex Mode
The UART Tool Hex mode displays the hex values of bytes received from the target’s
UART in the terminal display.
A line of bytes received by the UART Tool is preceded with the text “RX:”.
A line of bytes transmitted by the UART Tool is preceded with the text “TX:”.
In Figure 7-5, the four hex bytes 0x50, 0x4B, 0x53, and 0x41 were received from the
target (0x50 was received first). The three bytes 0x70, 0x6B, and 0x32 were then
transmitted, 0x70 first.
In Hex mode, bytes may only be transmitted one way: by typing a sequence of one or
more hex values in one of the four “Send Hex Sequences:” boxes. To send a sequence,
click Send next to it. A hex sequence may contain from 1 to 48 bytes.
The “Echo On” checkbox has no function in Hex mode.
Data in the terminal display may be selected (highlighted) with the cursor and copied
into the clipboard by right clicking and selecting Copy or pressing & lt; Ctrl & gt; + & lt; c & gt; .
DS51553E-page 68
© 2008 Microchip Technology Inc.
PICkit 2 UART Tool
FIGURE 7-5:
7.3.4
PICKIT™ 2 UART TOOL WINDOW HEX MODE
Wrap Text
This checkbox affects both modes, ASCII and HEX. When checked, a displayed line
will automatically wrap at the right edge of the terminal display. If unchecked, then a
received line will not wrap and a horizontal scroll bar will appear in the terminal display
to allow the entire line to be viewed.
The terminal display will keep the last 200 lines of received data in the buffer. The vertical scroll bar may be used to view previous data or text.
7.3.5
Log to File
The Log to File button allows all text and data to be saved to a text file as it appears
on the display.
Click Log to File to bring up a Save File dialog. Specify the file location and name and
click Save. While the terminal display is being saved to the log file, the Log to File
button will turn green and display the text “Logging Data…”. (Figure 7-6)
FIGURE 7-6:
© 2008 Microchip Technology Inc.
LOG TO FILE IS ACTIVE
DS51553E-page 69
PICkit™ 2 User’s Guide
To stop logging data from the display and close the log file, click Logging Data….
Note:
7.3.6
Only data appearing on the display after the log file is opened will be written
to the log file. Existing data is not saved. To save existing data, use Copy
and Paste.
Clear Screen
Clear the Clear Screen button to clear all text or data from the terminal display window.
If data is being logged to a file, clearing the screen will not affect the log file.
7.3.7
Exit UART Tool
Click Exit to close the UART Tool window and return to the PICkit 2 Programmer
application main window. The UART Tool terminal display data and settings will be
preserved during any programming operations until the UART Tool is re-entered.
If the PICkit 2 application is closed, the UART Tool settings, including String Macros
and Hex Sequences, will be saved and restored for the next time the UART Tool is
used. The terminal display buffer text and data is not saved when the application is
closed.
DS51553E-page 70
© 2008 Microchip Technology Inc.
PICkit™ 2 USER’S GUIDE
Appendix A. MPLAB IDE Reference
A.1
INTRODUCTION
In MPLAB IDE, you first select a PICkit 2 supported device and then “PICkit 2” from
either the Debugger or Programmer menu to add debugging or programming functions
to MPLAB IDE, respectively. The functions made available are summarized here. For
more information about using the PICkit 2 Development Programmer/Debugger with
MPLAB IDE, see Chapter 4. “PICkit 2 Debug Express”.
• Debugging Functions
• Programming Functions
• Settings Dialog
In addition, “PICkit 2” will be added to the MPLAB IDE status bar, and a PICkit 2 tab
will be added to the Output dialog.
See also Chapter 5. “Troubleshooting” for FAQs on using PICkit 2 Debug Express
and descriptions of PICkit 2 MPLAB IDE error codes.
A.2
DEBUGGING FUNCTIONS
When you select PICkit 2 from the Debugger menu, debug items will be added to the
following MPLAB IDE functions:
• Debugger Menu
• Right Mouse Button Menu
• Toolbars
A.2.1
Debugger Menu
Run F9
Execute program code until a breakpoint is encountered or until Halt is selected.
Execution starts at the current program counter (as displayed in the status bar). The
current program counter location is also represented as a pointer in the Program
Memory window. While the program is running, several other functions are disabled.
Animate
Animate causes the debugger to actually execute single steps while running, updating
the values of the registers as it runs.
Animate runs slower than the Run function, but allows you to view changing register
values in the Special Function Register window or in the Watch window.
To Halt Animate, use the menu option Debugger & gt; Halt, the toolbar Halt or & lt; F5 & gt; .
Halt F5
Halt (stop) the execution of program code. When you click Halt, status information is
updated.
© 2008 Microchip Technology Inc.
DS51553E-page 71
PICkit™ 2 User’s Guide
Step Into F7
Single step through program code.
For assembly code, this command executes one instruction (single or multiple cycle
instructions) and then halts. After execution of one instruction, all the windows are
updated.
For C code, this command executes one line of C code, which may mean the execution
of one or more assembly instruction, and then halts. After execution, all the windows
are updated.
Note:
Do not step into a SLEEP instruction.
Step Over F8
In C code, steps over the current line of code.
Step Out
Not available.
Reset F6
Issue a Reset sequence to the target processor. This issues a MCLR to reset the
Program Counter to the Reset vector.
Breakpoints
Open the Breakpoint dialog. Set, enable or disable breakpoints in this dialog. For more
information on this dialog, see the MPLAB IDE on-line help file.
Note:
You may also right click or double click on a line of code to set a simple
breakpoint.
Program
Download your code to the target device.
Read
Read target memory. Information uploaded to MPLAB IDE.
Read EEData
Read target EEData memory. Information uploaded to MPLAB IDE.
Connect
Attempt to establish or re-establish communications between the PC and PICkit 2. The
progress of this connection is shown on the PICkit 2 tab of the Output dialog.
Download OS
Download the latest PICkit 2 operating system.
Settings
Open the PICkit 2 Settings dialog (see Section A.4 “Settings Dialog”.) Set up
automatic options and enable/disable warnings.
A.2.2
Right Mouse Button Menu
The following will appear on the right mouse menus in code displays, such as program
memory and source code files:
Set/Remove Breakpoint
Set or remove a breakpoint at the currently selected line.
DS51553E-page 72
© 2008 Microchip Technology Inc.
MPLAB IDE Reference
Enable/Disable Breakpoint
Enable or disable a breakpoint at the currently selected line.
Breakpoints
Remove, enable or disable all breakpoints.
Run To Cursor
Run the program to the current cursor location. Formerly Run to Here.
A.2.3
Toolbars
When PICkit 2 is selected as a debugger, these toolbars are displayed in MPLAB IDE:
• Standard debug toolbar (Run, Halt, Animate, Step Into, Step Over, Step Out,
Reset).
• PICkit 2 debug toolbar (Program, Read, Read EEData, Connect).
A.3
PROGRAMMING FUNCTIONS
When you select PICkit 2 from the Programmer menu, program items will be added to
the following MPLAB IDE functions:
• Programmer Menu
• Toolbar
A.3.1
Programmer Menu
Program
Program memory areas: program memory, EEDATA memory, Configuration bits and ID
locations.
Read
Read memory areas: program memory, EEDATA memory, Configuration bits and ID
locations.
Verify
Verify programming of memory areas: program memory, EEDATA memory,
Configuration bits and ID locations.
Erase
Erase all data on the device including program memory, EEDATA memory ID and
Configuration bits.
Blank Check
Check to see that all device memory is erased/blank.
Read EEDATA
Read EEDATA memory.
Connect
Establish communications between the PICkit 2 and the PC.
Download OS
Download PICkit 2 operating system/firmware.
Release from Reset
Set MCLR to VDD.
© 2008 Microchip Technology Inc.
DS51553E-page 73
PICkit™ 2 User’s Guide
Hold in Reset
Set MCLR to ground (zero).
Settings
Open the PICkit 2 Settings dialog (see Section A.4 “Settings Dialog”.) Set up
automatic options and enable/disable warnings.
A.3.2
Toolbar
Program the target device
Program memory areas: program memory, EEDATA memory, Configuration bits and ID
locations.
Read target device memories
Read memory areas: program memory, EEDATA memory, Configuration bits and ID
locations.
Read the target EEDATA memory
Read EEDATA memory.
Verify the contents of the target device
Verify programming of memory areas: program memory, EEDATA memory,
Configuration bits and ID locations.
Erase the target device memories
Erase all data on the device including program memory, EEDATA memory, ID and
Configuration bits.
Verify that target memories are erased
Check to see that all device memory is erased/blank.
Release from Reset
Set the target MCLR pin to VDD.
Hold in Reset
Set the target MCLR pin to VSS.
Connect
Establish communications between the PICkit 2 and the PC.
DS51553E-page 74
© 2008 Microchip Technology Inc.
MPLAB IDE Reference
A.4
SETTINGS DIALOG
Select Debugger & gt; Settings or Programmer & gt; Settings to open the settings dialog and set
up PICkit 2.
A.4.1
Settings Tab
This tab of the PICkit 2 Settings dialog allows you to set automatic options
Connect on startup
When PICkit™ 2 is selected as the programmer, immediately attempt
to connect.
Program on
successful build
When a project builds successfully, immediately attempt to program the
device with the updated code.
Run after successful When a device program successfully, immediately attempt to run the
program
program.
Output to debug file
A.4.2
Output debug information to a file whenever the program is run.
Warnings Tab
This tab of the PICkit 2 Settings dialog allows you to enable or disable warning
messages displayed in the Output window.
• To enable/disable specific messages, click the check box next to the message to
check/uncheck it.
• To enable/disable all messages, click Check All/Uncheck All.
© 2008 Microchip Technology Inc.
DS51553E-page 75
PICkit™ 2 User’s Guide
NOTES:
DS51553E-page 76
© 2008 Microchip Technology Inc.
© 2008 Microchip Technology Inc.
2^1
WP
SCL
SDA
+5V_USB
8
19
10
9
1
8
Vcc
7
WP
6
SCL
5
SDA
U3
24LC512
C9
0.1 μF
1
A0
2
A1
3
A2
4
Vss
C3
22 pF
X1
C2
22 pF 20 MHz
20
1
A0
2
A1
3
A2
4
Vss
2^0
8
Vcc
7
WP
6
SCL
5
SDA
U4
24LC512
C10
0.1 μF
17
18
15
16
14
13
11
12
28
27
26
22
23
24
25
21
2
3
4
5
6
7
WP
+5V_USB
RA0/AN0
VDD
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT/RCV
RA5/AN4/SS/HLVDIN/C2OUT
MCLR/VPP/RE3
RB0/AN12/INT0/FLT0/SDI/SDA
RB1/AN10/INT1/SCK/SCL
RB2/AN8/INT2/VMO
OSC1/CLKI
RB3/AN9/CCP2/VPO
RB4/AN11/KBI0
RB5/KBI1/PGM
OSC2/CLKO/RA6
RB6/KBI2/PGC
RB7/KBI3/PGD
RC0/T1OSO/T13CKI
RC1/T1OSI/CCP2/UOE
RC2/CCP1
VUSB
RC4/D-/VM
RC5/D+/VP
VSS
RC6/TX/CK
VSS
RC7/RX/DT/SDO
PIC18F2550/SO
U1
SDA
SCL
VPP_ON
VPP_FEEDBACK
VDD_TGT_FB
ICSPDAT
ICSPCLK
AUX
MCLR_TGT
R8
2.7 KΩ
+5V_USB
WP
R9
2.7 KΩ
C7
0.47 μF
VDD_TGT_ADJ
R33
33 Ω
1
2
3
4
NC
5
J2
USB
Mini-B
C16
0.1 μF
SW1
PROGRAM
R32
10 KΩ
+5V_USB
+5V_USB
SCL
SDA
J1
ICSP TM
VPP_PUMP
NC
1
2
3
4
5
6
R4
10 KΩ
BUSY
R6
10 KΩ
C8
0.1 μF
C4
0.1 μF
DS1
RED
R2
470 Ω
1
3
5
2
+
-
4
U2
MCP6001U
+5V_USB
TARGET
R5
10 KΩ
R31
100 Ω
C6
0.1 μF
G
Q1
IRLML6402
C5
10 μF
16V
D
S
R34
2.7 KΩ
R7
10 KΩ
+V_TGT
+5V_USB
DS2
GREEN
R1
470 Ω
+5V_USB
POWER
Vdd_TGT_N
Vdd_TGT_P
DS3
YELLOW
R3
470 Ω
+5V_USB
FIGURE B-1:
+5V_USB
C1
0.1 μF
+5V_USB
NOTE: R32 and C16 not populated
PICkit™ 2 USER’S GUIDE
Appendix B. PICkit 2 Schematics
PICkit 2 Development Programmer/Debugger schematic diagrams are shown here.
Demo board schematics are found in their respective user’s guides.
PICkit™ 2 SCHEMATIC DIAGRAM (PAGE 1 OF 2)
DS51553E-page 77
DS51553E-page 78
C13
VPP_PUMP
0.1 μF
R21
1KΩ
C14
10 μF
16V
VPP_FEEDBACK
VPP_ON
MCLR_TGT
D3
BAT54
Q4
MMBT3904
L1
680uH
+V_TGT
R24
2.7 KΩ
R22
4.7 KΩ
R16
10 KΩ
R29
10 KΩ
R27
10 KΩ
+5V_USB
R30
2.7 KΩ
47 μF
25V
C15
D 4
S 5
D 6
Q7
MMBT3904
R25
10 KΩ
R23
100 KΩ
High turns on N
Low turns on P
Q2(P)
3 G
2 S
1 G
Q1(N)
U5
FDC6420C
C11
10 μF
16V
R13
1KΩ
Q8
MMBT3904
R28
100 Ω
VPP
Q6
MMBT3906
D4
ZHCS1000
0.1 μF
C12
VDD_TGT_FB
R26
4.7 KΩ
ICSPDAT
D1
MMBD4148
ICSPCLK
AUX
R17
820 Ω
R19
10 Ω
R14
10 Ω
R10
10 Ω
Q5
MMBT3906
R20
33 Ω
Q3
MMBT3906
R15
33 Ω
Q2
MMBT3906
R11
33 Ω
R36
4.7 KΩ
R35
4.7 KΩ
6
5
4
3
2
1
J3
ICSP TM
AUX
ICSPCLK
ICSPDAT
GND
VDD_TGT
VPP
FIGURE B-2:
VDD_TGT_P
VDD_TGT_N
R12
10 KΩ
+V_TGT
PICkit™ 2 User’s Guide
PICkit™ 2 SCHEMATIC DIAGRAM (PAGE 2 OF 2)
© 2008 Microchip Technology Inc.
VDD_TGT
PICkit™ 2 USER’S GUIDE
Index
Numerics
H
44-Pin Demo Board ................................................. 31
Halt........................................................................... 71
Hex File, Import........................................................ 19
Hold Device in Reset................................................ 11
Hold in Reset............................................................ 74
A
Animate .................................................................... 71
Auto Import Hex + Write Device............................... 25
Auto-Detect .............................................................. 12
B
Blank Check ............................................ 11, 24, 73, 74
Breakpoints .........................................................72, 73
C
Cable Length............................................................ 30
Calibrate VDD & Set Unit ID .................................... 12
Check Communication ............................................. 12
Code Protect .......................................................11, 23
Connect.................................................................... 72
Connecting ............................................................... 73
Connector, 6-Pin ........................................................ 8
Current Limit ............................................................ 18
Customer Notification Service.................................... 5
Customer Support ...................................................... 6
I
ICSP......................................................................... 27
ICSPCLK/ICSPDAT ................................................. 28
Import Hex................................................................ 11
Import Hex File......................................................... 19
Install Hardware ....................................................... 15
Install Software......................................................... 16
Internet Address, Microchip ....................................... 5
L
LEDs .......................................................................... 8
Low Pin Count Demo Board..................................... 31
M
MCLR ................................................................. 73, 74
Microsoft Windows ................................................... 49
MPLAB IDE .............................................................. 71
D
O
Data EEPROM Memory ........................................... 14
Data Protect ............................................................. 11
Debug Express ........................................................ 31
Debugging Functions ............................................... 71
Device Selection .................................................12, 16
Documentation
Conventions ........................................................ 3
Layout ................................................................. 2
Download OS ......................................................72, 73
Download PICkit 2 Programmer Operating System. 12
Operating System .................................................... 12
Operating System, Update....................................... 61
OSCCAL .................................................................. 12
E
Enable Code Protect ................................................ 11
Enable Data Protect ................................................. 11
Erase....................................................... 11, 24, 73, 74
Explorer 16............................................................... 31
Export Hex ............................................................... 11
F
Fast Programming ................................................... 12
File History ............................................................... 11
Firmware .................................................................. 12
Firmware, Update .................................................... 61
Force PICkit 2 .......................................................... 12
Force Target ............................................................ 12
© 2008 Microchip Technology Inc.
P
PGC/PGD................................................................. 28
Program ........................................................72, 73, 74
Program Memory ..................................................... 14
Programmer Application........................................... 10
Programming Functions ........................................... 73
Push Button................................................................ 8
R
Read........................................................23, 72, 73, 74
Read Device............................................................. 11
Read Device + Export Hex File ................................ 25
Read EEDATA ................................................... 73, 74
Read EEData ........................................................... 72
Reading, Recommended ........................................... 4
Readme...................................................................... 4
Reconnect ................................................................ 74
Release from Reset ................................................. 73
Reset
Hold in............................................................... 74
Processor.......................................................... 72
Release from..................................................... 73
Run........................................................................... 71
DS51553E-page 79
PICkit™ 2 User’s Guide
S
Set OSCCAL ............................................................ 12
Settings Dialog ......................................................... 75
Settings tab .............................................................. 75
Step .......................................................................... 72
T
Target Power............................................................ 18
Target Vdd Source ................................................... 12
Troubleshooting ....................................................... 49
U
Update Firmware...................................................... 61
Update Operating System ........................................ 61
USB Port .................................................................... 8
Use VPP First Program Entry................................... 12
V
Vdd .................................................... 13, 18, 19, 29, 49
Verify .......................................................11, 23, 73, 74
Verify Erased............................................................ 74
Verify on Write.......................................................... 11
Vpp ..................................................................... 28, 49
Vss ........................................................................... 30
W
Warning Messages................................................... 75
Warnings tab ............................................................ 75
Warranty Registration................................................. 4
Web Site, Microchip ................................................... 5
Write ......................................................................... 20
Write Device ............................................................. 11
Write on PICkit Button .............................................. 11
DS51553E-page 80
© 2008 Microchip Technology Inc.
Index
NOTES:
© 2008 Microchip Technology Inc.
DS51553E-page 81
WORLDWIDE SALES AND SERVICE
AMERICAS
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
Asia Pacific Office
Suites 3707-14, 37th Floor
Tower 6, The Gateway
Harbour City, Kowloon
Hong Kong
Tel: 852-2401-1200
Fax: 852-2401-3431
India - Bangalore
Tel: 91-80-4182-8400
Fax: 91-80-4182-8422
India - New Delhi
Tel: 91-11-4160-8631
Fax: 91-11-4160-8632
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Santa Clara
Santa Clara, CA
Tel: 408-961-6444
Fax: 408-961-6445
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
Korea - Daegu
Tel: 82-53-744-4301
Fax: 82-53-744-4302
China - Hong Kong SAR
Tel: 852-2401-1200
Fax: 852-2401-3431
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
China - Nanjing
Tel: 86-25-8473-2460
Fax: 86-25-8473-2470
Malaysia - Kuala Lumpur
Tel: 60-3-6201-9857
Fax: 60-3-6201-9859
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
Malaysia - Penang
Tel: 60-4-227-8870
Fax: 60-4-227-4068
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
Taiwan - Hsin Chu
Tel: 886-3-572-9526
Fax: 886-3-572-6459
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-536-4803
China - Xiamen
Tel: 86-592-2388138
Fax: 86-592-2388130
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
China - Xian
Tel: 86-29-8833-7252
Fax: 86-29-8833-7256
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
China - Zhuhai
Tel: 86-756-3210040
Fax: 86-756-3210049
01/02/08
DS51553E-page 82
© 2008 Microchip Technology Inc.
Release Notes for PICkit(R) 2 Microcontroller Programmer
PICkit 2 V2.61.00
Device File V1.61.00
*** Important
*** PICkit 2 software v2.61.00 requires PICkit 2 OS firmware
*** Version 2.32.00 before the application will work correctly.
*** Use the " Download PICkit 2 Firmware " selection on the
*** Tools dropdown menu. The new OS is normally located at
*** C:\Program Files\Microchip\PICkit 2 v2\PK2V023200.hex
24 March 2009
-----------------------------------------------------------------
Table of Contents
-----------------------------------------------------------------
1. Device Support List
2. Operating System Support List
3. Release notes
-----------------------------------------------------------------
1. Device Support List
-----------------------------------------------------------------
=================================================================
= NOTE: This list shows support for the PICkit 2 Programmer =
= software application. It does not show support for using the =
= PICkit 2 within MPLAB IDE. For a list of MPLAB supported =
= parts, see the MPLAB IDE PICkit 2 Readme. =
= (Typically in C:\Program Files\Microchip\MPLAB IDE\Readmes) =
=================================================================
* Indicates new parts supported in this release with v1.61 of the
device file.
+ Indicates parts that require 4.75V minimum VDD for programming.
PICkit 2 may not be able to generate sufficiently high VDD,
so an external 5.0v power supply may be required.
# indicates Midrange parts that support low Vdd programming
Baseline Devices
----------------
PIC10F200 PIC10F202 PIC10F204 PIC10F206
PIC10F220 PIC10F222
PIC12F508 PIC12F509 PIC12F510 PIC12F519
PIC16F505 PIC16F506 PIC16F526
PIC16F54 PIC16F57 PIC16F59
Midrange/Standard Devices
----------------
& gt; & gt; All 'LF' versions of devices are supported
PIC12F609 PIC12HV609
PIC12F615 PIC12HV615
PIC12F629 PIC12F635# PIC12F675 PIC12F683#
PIC16F610 PIC16HV610 PIC16F616 PIC16HV616
PIC16F627 PIC16F628 PIC16F639
PIC16F627A PIC16F628A PIC16F648A
PIC16F630 PIC16F631 PIC16F636# PIC16F676
PIC16F677 PIC16F684# PIC16F685# PIC16F687#
PIC16F688# PIC16F689# PIC16F690#
PIC16F72+
PIC16F73+ PIC16F74+ PIC16F76+ PIC16F77+
PIC16F716
PIC16F737+ PIC16F747+ PIC16F767+ PIC16F777+
PIC16F785 PIC16HV785
PIC16F84A PIC16F87# PIC16F88#
PIC16F818# PIC16F819#
PIC16F870 PIC16F871 PIC16F872
PIC16F873 PIC16F874 PIC16F876 PIC16F877
PIC16F873A PIC16F874A PIC16F876A PIC16F877A
PIC16F882#
PIC16F883# PIC16F884# PIC16F886# PIC16F887#
PIC16F913# PIC16F914# PIC16F916# PIC16F917#
PIC16F946#
Midrange/1.8V Min Devices
----------------
PIC16F722 PIC16LF722
PIC16F723 PIC16LF723 PIC16F724 PIC16LF724
PIC16F726 PIC16LF726 PIC16F727 PIC16LF727
PIC16F1933 PIC16F1934 PIC16F1936 PIC16F1937
PIC16F1938 PIC16F1939
PIC16LF1933 PIC16LF1934 PIC16LF1936 PIC16LF1937
PIC16LF1938 PIC16LF1939
PIC18F Devices
--------------
& gt; & gt; All 'LF' versions of devices are supported
PIC18F242 PIC18F252 PIC18F442 PIC18F452
PIC18F248 PIC18F258 PIC18F448 PIC18F458
PIC18F1220 PIC18F1320 PIC18F2220
PIC18F1230 PIC18F1330 PIC18F1330-ICD
PIC18F2221 PIC18F2320 PIC18F2321 PIC18F2331
PIC18F2410 PIC18F2420 PIC18F2423 PIC18F2431
PIC18F2450 PIC18F2455 PIC18F2458 PIC18F2480
PIC18F2510 PIC18F2515 PIC18F2520 PIC18F2523
PIC18F2525 PIC18F2550 PIC18F2553 PIC18F2580
PIC18F2585
PIC18F2610 PIC18F2620 PIC18F2680 PIC18F2682
PIC18F2685
PIC18F4220 PIC18F4221 PIC18F4320 PIC18F4321
PIC18F4331 PIC18F4410 PIC18F4420 PIC18F4423
PIC18F4431 PIC18F4450 PIC18F4455 PIC18F4458
PIC18F4480
PIC18F4510 PIC18F4515 PIC18F4520 PIC18F4523
PIC18F4525 PIC18F4550 PIC18F4553 PIC18F4580
PIC18F4585
PIC18F4610 PIC18F4620 PIC18F4680 PIC18F4682
PIC18F4685 PIC18F6310 PIC18F6390 PIC18F6393
PIC18F6410 PIC18F6490 PIC18F6493 PIC18F6520
PIC18F6525 PIC18F6527
PIC18F6585 PIC18F6620 PIC18F6621 PIC18F6622
PIC18F6627 PIC18F6628 PIC18F6680 PIC18F6720
PIC18F6722 PIC18F6723
PIC18F8310 PIC18F8390 PIC18F8393 PIC18F8410
PIC18F8490 PIC18F8493
PIC18F8520 PIC18F8525 PIC18F8527 PIC18F8585
PIC18F8620 PIC18F8621 PIC18F8622 PIC18F8627
PIC18F8628
PIC18F8680 PIC18F8720 PIC18F8722 PIC18F8723
PIC18F_J_ Devices
-----------------
PIC18F24J10 PIC18LF24J10
PIC18F24J11 PIC18LF24J11 PIC18F24J50 PIC18LF24J50
PIC18F25J10 PIC18LF25J10
PIC18F25J11 PIC18LF25J11 PIC18F25J50 PIC18LF25J50
PIC18F26J11 PIC18LF26J11 PIC18F26J50 PIC18LF26J50
PIC18F44J10 PIC18LF44J10
PIC18F44J11 PIC18LF44J11 PIC18F44J50 PIC18LF44J50
PIC18F45J10 PIC18LF45J10
PIC18F45J11 PIC18LF45J11 PIC18F45J50 PIC18LF45J50
PIC18F46J11 PIC18LF46J11 PIC18F46J50 PIC18LF46J50
PIC18F63J11 PIC18F63J90 PIC18F64J11 PIC18F64J90
PIC18F65J10 PIC18F65J11 PIC18F65J15 PIC18F65J50
PIC18F65J90
PIC18F66J10 PIC18F66J11 PIC18F66J15 PIC18F66J16
PIC18F66J50 PIC18F66J55 PIC18F66J60 PIC18F66J65
PIC18F66J90
PIC18F67J10 PIC18F67J11 PIC18F67J50 PIC18F67J60
PIC18F67J90
PIC18F83J11 PIC18F83J90 PIC18F84J11 PIC18F84J90
PIC18F85J10 PIC18F85J11 PIC18F85J15 PIC18F85J50
PIC18F85J90
PIC18F86J10 PIC18F86J11 PIC18F86J15 PIC18F86J16
PIC18F86J50 PIC18F86J55 PIC18F86J60 PIC18F86J65
PIC18F86J90
PIC18F87J10 PIC18F87J11 PIC18F87J50 PIC18F87J60
PIC18F87J90
PIC18F96J60 PIC18F96J65 PIC18F97J60
PIC18F_K_ Devices
-----------------
PIC18F13K22 PIC18LF13K22 PIC18F14K22 PIC18LF14K22
PIC18F13K50 PIC18LF13K50 PIC18F14K50 PIC18LF14K50
PIC18F14K50-ICD
PIC18F23K20 PIC18F24K20 PIC18F25K20 PIC18F26K20
PIC18F43K20 PIC18F44K20 PIC18F45K20 PIC18F46K20
PIC24 Devices
-------------
PIC24F04KA200 PIC24F04KA201
PIC24F08KA101 PIC24F08KA102
PIC24F16KA101 PIC24F16KA102
NOTE: To program PIC24F-KA- devices with MCLR used as IO,
Tools & gt; Use High Voltage Program Entry must be enabled.
PIC24FJ16GA002 PIC24FJ16GA004
PIC24FJ32GA002 PIC24FJ32GA004
PIC24FJ32GA102 PIC24FJ32GA104
PIC24FJ48GA002 PIC24FJ48GA004
PIC24FJ64GA002 PIC24FJ64GA004
PIC24FJ64GA102 PIC24FJ64GA104
PIC24FJ64GA006 PIC24FJ64GA008 PIC24FJ64GA010
PIC24FJ96GA006 PIC24FJ96GA008 PIC24FJ96GA010
PIC24FJ128GA006 PIC24FJ128GA008 PIC24FJ128GA010
PIC24FJ128GA106 PIC24FJ128GA108 PIC24FJ128GA110
PIC24FJ192GA106 PIC24FJ192GA108 PIC24FJ192GA110
PIC24FJ256GA106 PIC24FJ256GA108 PIC24FJ256GA110
PIC24FJ32GB002 PIC24FJ32GB004
PIC24FJ64GB002 PIC24FJ64GB004
PIC24FJ64GB106 PIC24FJ64GB108 PIC24FJ64GB110
PIC24FJ128GB106 PIC24FJ128GB108 PIC24FJ128GB110
PIC24FJ192GB106 PIC24FJ192GB108 PIC24FJ192GB110
PIC24FJ256GB106 PIC24FJ256GB108 PIC24FJ256GB110
PIC24HJ12GP201 PIC24HJ12GP202
PIC24HJ16GP304
PIC24HJ32GP202 PIC24HJ32GP204
PIC24HJ32GP302 PIC24HJ32GP304
PIC24HJ64GP202 PIC24HJ64GP204
PIC24HJ64GP206 PIC24HJ64GP210
PIC24HJ64GP502
PIC24HJ64GP504 PIC24HJ64GP506 PIC24HJ64GP510
PIC24HJ128GP202 PIC24HJ128GP204
PIC24HJ128GP206 PIC24HJ128GP210
PIC24HJ128GP306 PIC24HJ128GP310
PIC24HJ128GP502 PIC24HJ128GP504
PIC24HJ128GP506 PIC24HJ128GP510
PIC24HJ256GP206 PIC24HJ256GP210 PIC24HJ256GP610
dsPIC33 Devices
---------------
dsPIC33FJ06GS101 dsPIC33FJ06GS102 dsPIC33FJ06GS202
dsPIC33FJ16GS402 dsPIC33FJ16GS404
dsPIC33FJ16GS502 dsPIC33FJ16GS504
dsPIC33FJ12GP201 dsPIC33FJ12GP202
dsPIC33FJ16GP304
dsPIC33FJ32GP202 dsPIC33FJ32GP204
dsPIC33FJ32GP302 dsPIC33FJ32GP304
dsPIC33FJ64GP202 dsPIC33FJ64GP204
dsPIC33FJ64GP206 dsPIC33FJ64GP306 dsPIC33FJ64GP310
dsPIC33FJ64GP706 dsPIC33FJ64GP708 dsPIC33FJ64GP710
dsPIC33FJ64GP802 dsPIC33FJ64GP804
dsPIC33FJ128GP202 dsPIC33FJ128GP204
dsPIC33FJ128GP206 dsPIC33FJ128GP306 dsPIC33FJ128GP310
dsPIC33FJ128GP706 dsPIC33FJ128GP708 dsPIC33FJ128GP710
dsPIC33FJ256GP506 dsPIC33FJ256GP510 dsPIC33FJ256GP710
dsPIC33FJ128GP802 dsPIC33FJ128GP804
dsPIC33FJ12MC201 dsPIC33FJ12MC202
dsPIC33FJ16MC304
dsPIC33FJ32MC202 dsPIC33FJ32MC204
dsPIC33FJ32MC302 dsPIC33FJ32MC304
dsPIC33FJ64MC202 dsPIC33FJ64MC204
dsPIC33FJ64MC506 dsPIC33FJ64MC508 dsPIC33FJ64MC510
dsPIC33FJ64MC706 dsPIC33FJ64MC710
dsPIC33FJ64MC802 dsPIC33FJ64MC804
dsPIC33FJ128MC202 dsPIC33FJ128MC204
dsPIC33FJ128MC506 dsPIC33FJ128MC510 dsPIC33FJ128MC706
dsPIC33FJ128MC708 dsPIC33FJ128MC710
dsPIC33FJ256MC510 dsPIC33FJ256MC710
dsPIC33FJ128MC802 dsPIC33FJ128MC804
dsPIC30 Devices
---------------
dsPIC30F2010 dsPIC30F2011 dsPIC30F2012
dsPIC30F3010 dsPIC30F3011 dsPIC30F3012
dsPIC30F3013 dsPIC30F3014
dsPIC30F4011 dsPIC30F4012 dsPIC30F4013
dsPIC30F5011^ dsPIC30F5013^ dsPIC30F5015
dsPIC30F5016
dsPIC30F6010A dsPIC30F6011A dsPIC30F6012A
dsPIC30F6013A dsPIC30F6014A dsPIC30F6015
^ These 2 devices are not supported for low VDD programming.
dsPIC30 SMPS Devices
--------------------
dsPIC30F1010
dsPIC30F2020 dsPIC30F2023
PIC32 Devices
--------------------
PIC32MX320F032H PIC32MX320F064H PIC32MX320F128L
PIC32MX320F128H
PIC32MX340F128H PIC32MX340F128L
PIC32MX340F256H
PIC32MX340F512H*
PIC32MX360F256L PIC32MX360F512L
PIC32MX420F032H
PIC32MX440F128L PIC32MX440F128H
PIC32MX440F256H PIC32MX440F512H
PIC32MX460F256L PIC32MX460F512L
KEELOQ HCS Devices
------------------
HCS200 HCS201 HCS300 HCS301 HCS320
HCS360 HCS361 HCS362
HCSxxx File - & gt; Import HEx Notes:
The first line only may be imported from SQTP
*.NUM files generated by the KEELOQ tool in
MPLAB.
Connections for HCS devices
---------------------------------------
PICkit 2 Pin HCS Device Pin
(2) Vdd 8
(3) GND 5
(5) PGC /3 HCS20x, 320
\3 -or- 4 HCS30x, 36x
(4) PGD 6
(1) VPP 2 HCS360, 361 only
MCP250xx CAN Devices
--------------------
MCP25020 MCP25025
MCP25050 MCP25055
!!IMPORTANT!! - MCP250xx devices are OTP and can only be
programmed once.
Connections for MCP250xx devices
---------------------------------------
PICkit 2 Pin MCP Device Pin (DIP)
(1) Vpp 11 Vpp
(2) Vdd 14 VDD
- The MCP device MUST be powered from PICkit 2!
(3) GND 7 Vss
(4) PGD 5 DATA
(5) PGC 6 CLOCK
Serial EEPROM Devices
---------------------
NOTE: Other supported voltage grades are listed in parentheses
next to the device. Select the " LC " part number to program
these other voltage grades.
11LC010 (AA)
11LC020 (AA)
11LC040 (AA)
11LC080 (AA)
11LC160 (AA)
24LC00 (AA)(C) 25LC010A (AA)
24LC01B (AA) 25LC020A (AA)
24LC02B (AA) 25LC040A (AA)
24LC04B (AA) 25LC080A (AA)
24LC08B (AA) 25LC080B (AA)
24LC16B (AA) 25LC160A (AA)
24LC32A (AA) 25LC160B (AA)
24LC64 (AA)(FC) 25LC320A (AA)
24LC128 (AA)(FC) 25LC640A (AA)
24LC256 (AA)(FC) 25LC128 (AA)
24LC512 (AA)(FC) 25LC256 (AA)
24LC1025 (AA)(FC) 25LC512 (AA)
25LC1024 (AA)
93LC46A/B/C (AA)(-C)
93LC56A/B/C (AA)(-C)
93LC66A/B/C (AA)(-C)
93LC76A/B/C (AA)(-C)
93LC86A/B/C (AA)(-C)
Connections for 11LC devices
---------------------------------------
PICkit 2 Pin 11LC Device Pin (DIP)
(2) Vdd ! 8 Vcc
(3) GND 4 Vss
(6) AUX 5 SCIO
! 11LC devices may not program properly below 3.6V VDD.
This is a limitation of the PICkit 2 AUX IO pin.
Connections for 24LC devices
---------------------------------------
PICkit 2 Pin 24LC Device Pin (DIP)
(2) Vdd ! 8 Vcc
(3) GND 4 Vss
(5) PGC 6 SCL (driven as push-pull)
(6) AUX 5 SDA (requires pullup)
7 WP - disabled (GND)
1, 2, 3 Ax pins
Connect to Vdd or GND per
datasheet and to set address
! 24LC devices may not program properly below 3.6V VDD.
This is a limitation of the PICkit 2 AUX IO pin.
Connections for 25LC devices
---------------------------------------
PICkit 2 Pin 25LC Device Pin (DIP)
(1) VPP 1 nCS
(2) Vdd 8 Vcc
(3) GND 4 Vss
(4) PGD 2 SO
(5) PGC 6 SCK
(6) AUX 5 SI
7 nHOLD - disabled (Vdd)
3 nWP - disabled (Vdd)
Connections for 93LC devices
---------------------------------------
PICkit 2 Pin 93LC Device Pin (DIP)
(1) VPP 1 CS
(2) Vdd 8 Vcc
(3) GND 5 Vss
(4) PGD 4 DO
(5) PGC 2 CLK
(6) AUX 3 DI
7 PE - enabled (Vdd)
6 'C' Device ORG
Set to select word size
-----------------------------------------------------------------
2. Operating System Support List
-----------------------------------------------------------------
This tool has been tested under the following operating systems:
Windows XP
Windows Vista 32-bit
Windows Vista 64-bit (Preliminary Testing Only)
NOTE: In Windows Vista, the PICkit2.INI file may be found in
C:\Users\ & lt; username & gt; \AppData\Local\VirtualStore\Program Files\Microchip\PICkit 2 v2
-----------------------------------------------------------------
3. Release notes V2.61.00
-----------------------------------------------------------------
New Features:
-------------
& gt; Programmer-To-Go updated to support 3rd party PICkit 2 workalike
devices with more Programmer-To-Go memory.
Bug Fixes:
-------------
& gt; PIC18F97J60 programming bug in device file v1.60 fixed
& gt; PIC24FJ programming problems introduced in software v2.60 fixed
& gt; Configuration Editor display issue in some Asian editions of
Windows addressed.
-----------------------------------------------------------------
Release notes V2.60.00
-----------------------------------------------------------------
New Features:
-------------
& gt; Low Voltage Programming mode support
Low voltage programming mode (LVP) is now supported for all
PICkit 2 supported devices which feature this option. Refer
to the device datasheet and programming specification for
information on the LVP programming mode.
LVP programming mode is enabled by the menu
" Tools & gt; User LVP Program Entry "
This can only be enabled in Manual Device Select mode. When
enabled, the text " LVP " in red will appear above the Device
select combo-box.
For devices using the PGM pin in LVP mode, PICkit 2 ICSP
connector pin 6 AUX must be connected to the device PGM pin.
NOTE: LVP mode may only be used with devices that *already* have
the LVP configuration bit enabled. Blank devices always have
the LVP bit enabled.
NOTE: For PIC24F--KA-- devices, this option becomes
" Tools & gt; Use High Voltage Program Entry "
This mode MUST be used with PIC24F--KA-- devices that have the
MCLR pin disabled (used as IO) or PICkit 2 will not be able to
detect or program the device.
NOTE: LVP may be used with PICkit 2 Programmer-To-Go. Enable
" Tools & gt; User LVP Program Entry " before starting the
Programmer-To-Go wizard.
& gt; New Configuration Word Editor
The editor dialog is opened by clicking on the " Configuration "
text nest to the configuration word values in the main PICkit 2
display.
The editor allows editing of the individual bits in the
configuration words, but the user must reference the device
datasheet for the meanings of each bit.
The PICkit 2 software does not contain a database of the names
of the configuration bitfields and the meaning of their values.
& gt; New menus Tools & gt; Display Unimplemented Config Bits
This menu allows the user to choose how unimplemented
Configuration Word bits are displayed. In previous versions,
unimplemented bits were always displayed as '0' value. This
did not always match the way MPLAB IDE displayed these " don't
care " bits.
Options are to display as '0' (default), as '1', or as the
value in the imported HEX file / as they were read from the
device.
& gt; Faster PIC18F6xJxx, 8xJxx programming times
& gt; In Manual Device Select mode, PICkit 2 will now verify the
Device ID of the target device matches that of the selected
device. If no device ID is detected, an error is generated.
If the Device ID of a different device is detected, the name
of the matching device will be shown.
NOTE: To turn this feature off, edit the pickit2.ini file and
change the entry for DVER: to N. Ex
DVER: N
Bug Fixes:
-------------
& gt; Fixed some instances of the PICkit 2 software hanging on Reads,
during Verify, or Blank Check with some chipsets.
& gt; When importing a hex file, PICkit 2 should no longer warn when
unused configuration words (with no implemented bits) are not
contained in the HEX file.
The exceptions are some dsPIC30F words that contain reserved
bits. The warning may be ignored for these cases.
& gt; Fixed an issue when programming PIC24FJ appplication code that
self-modifies program memory. Such code should no longer cause
Verify during a Write operation to fail.
& gt; Baseline and Midrange checksums should now be computed correctly
when Code Protect (CP) is enabled.
& gt; Fixed an issue where the silicon revision was sometimes
displayed with junk in the upper word of the value.
NOTE: silicon revision display is enalbed byt adding the INI
file value " REVS: Y "
& gt; Alert Sounds will now point to the correct location for the
default sounds if the software is not installed in the default
location.
& gt; Fixed an issue with the progress bar display during writes
and verifies when using the PE with PIC24 and dsPIC33 devices.
& gt; Fixed an issue where " Tools & gt; Use VPP First Program Entry " may
not have had any effect in Manual Device Select mode.
& gt; Fixed an issue where the " Fail " alert sound was sometimes played
when downloading a memory image to Programmer-To-Go even when
the download was successful.
& gt; When Manual Device Select mode is active, the entire Programmer
menu is no longer inaccessible when no device has been selected.
This allows Manual Device Select mode to be exited without
having to select a device first.
-----------------------------------------------------------------
Release notes V2.55.02
-----------------------------------------------------------------
Bug Fixes:
-------------
& gt; Updates the PIC32 Programming Executive to v0109. The prior
version caused problems programming some PIC32 devices.
See below for additional updates in V2.55.xx
-----------------------------------------------------------------
Release notes V2.55.01
-----------------------------------------------------------------
Bug Fixes:
-------------
& gt; Fixes a UART Tool update rate issue introduced in V2.55.00
See below for additional updates in V2.55.xx
-----------------------------------------------------------------
Release notes V2.55.00
-----------------------------------------------------------------
New Features:
-------------
& gt; Faster PIC24 & dsPIC33 programming
PICkit 2 now supports use of the Enhanced ICSP programming mode
using the Programming Executive (PE) for these devices. In
addition to faster programming times, use of the PE provides
the following:
PIC24H & dsPIC33F:
- Includes the Device ID corruption errata workaround
- Verify is done using a 16-bit CRC and is very quick
- Blank Check is done in the PE and is very quick
PIC24F:
- Verify is still done by reading out the device and
benefits from faster PE reads
- Blank Check is still done by reading out the device and
benefits from faster PE reads
The PE is never used for devices with & lt; 4096 instruction
flash sizes.
Use of the PE may be disabled with programming reverting
to basic ICSP as used in previous releases as follows:
PIC24H & dsPIC33:
- Edit PICkit2.INI to set the following entry to 'N':
PE33: N
- To re-enable, edit the INI file and change the entry
back to 'Y'
- NOTE: Reverting to ICSP mode no longer protects against
the Device ID corruption errata
PIC24F:
- Edit PICkit2.INI to set the following entry to 'N':
PE24: N
- To re-enable, edit the INI file and change the entry
back to 'Y'
NOTE: PICkit 2 Programmer-To-Go does not use the PE in this
release, and still uses basic ICSP programming.
& gt; Import/Export of binary (*.bin) files for serial EEPROMs
When a serial EEPROM device is selected as the current device,
*.bin binary files may be imported and exported in addition to
*.hex files.
NOTE: A file MUST have the .bin extension to be imported or
exported as a binary file. Any other extension will be
treated as a hex format file
& gt; The UART Tool Hex mode allows direct typing
In HEX mode, when the display is selected hex characters may be
typed directly. When the first nibble is typed, it is shown
below the display as " Type Hex : 0_ " where '0' is the first nibble
value. When a second nibble character is typed, the byte is
transmitted. The first nibble may be cancelled by pressing ESC
or typing any non-hex character.
& gt; New menu option " Programmer & gt; Alert Sounds.. "
This option brings up a dialog to optionally select and enable
playing of WAV sound files on success, warning, and/or error
events in the status window. A default WAV sound for each is
included with the installion in the " Sounds " subdirectory of the
PICkit 2 program directory.
Bug Fixes:
-------------
& gt; (Device file v1.53) Fixed an issue with PI32MX4xx device config
masks not including USB configuration bits.
& gt; (Device file v1.53) PIC18F no longer reports verify errors or
reads certain locations improperly when ETBR table read protect
bits are asserted.
& gt; Fixed UART Tool issue where siginifcant amounts of received
data without a newline (ASCII mode) or transmission pause
(HEX mode) would cause sluggishness and lockups of the UART
Tool software.
& gt; Unit ID maximum length set to 14 characters due to a firmware
issue.
& gt; Tools & gt; Troubleshoot... dialog 30kHZ waveform is closer to
30kHz and no longer has breaks in the waveform. This issue
originated with the firmware v2.3x update.
NOTE: The test waveform is only intended to check the edge rise
and fall rates of the PGx signals. The waveform still
contains significant jitter and is only approximately
30kHz in frequency.
-----------------------------------------------------------------
Release notes V2.52.00
-----------------------------------------------------------------
New Features:
-------------
& gt; Menu option " Programmer & gt; Clear Memory Buffers on Erase " allows
the user to select whether or not the application device memory
buffers (Program Memory, EEPROM Data, User IDs, and
Configuration) are cleared to blank values or remain unchanged
when an " Erase " operation is performed. In prior versions, the
behavior has been to always clear the buffers on an " Erase. "
Bug Fixes:
-------------
& gt; Fixed a multiple PICkit 2 support critical issue that was
causing simultaneous use of multiple PICkit 2 units to fail.
This fix requires firmware version 2.32.00 for the PICkit 2 OS.
& gt; Fixed a dsPIC33/PIC24HJ Programmer-To-Go problem causing verify
of devices to fail in Programmer-To-Go mode when Config 8 was
not defined in the hex file.
& gt; Fixed an issue causing the application to crash when
programming PIC32 devices with completely blank Boot Flash.
-----------------------------------------------------------------
Release notes V2.51.00
-----------------------------------------------------------------
New Features:
-------------
& gt; Logic Tool dialog now allows the PICkit 2 VDD to be turned
ON and OFF from the dialog via the " VDD On " checkbox.
NOTE: the voltage value must still be set in the main form.
& gt; UART Tool dialog now allows the PICkit 2 VDD to be turned
ON and OFF from the dialog via the " VDD " checkbox.
NOTE: the voltage value must still be set in the main form.
The VDD checkbox will be disabled when the UART Tool is
" Connected "
To change the VDD setting, the UART Tool must be " Disconnected "
Bug Fixes:
-------------
& gt; Fix for Programmer-To-Go hanging on download for program sizes
greater than half the maximum allowed.
& gt; Fix for PICkit 2 operational problems after exiting Programmer-
To-Go mode. (Including reading junk data, failure to program,
and odd VDD behavior).
& gt; Corrected UART Tool Custom Baud dialog size.
& gt; Reads of PIC32 devices now display " done " at completion.
& gt; Added 100ms delays to PIC32 Program Executive download to fix
errors in some instances.
-----------------------------------------------------------------
Release notes V2.50.02
-----------------------------------------------------------------
Bug Fixes:
-------------
& gt; Fix to try to prevent the problem of PICkit 2 windows
" disappearing " by opening off screen.
If a problem is still found (Pk2 shows up in taskbar, but no
window is visible & it's not minimized) the best solution is
to close the PICkit 2 application (right-click task bar icon
and select " Close " ), then delete the INI file.
& gt; Disables Tools & gt; UART Tool and Tools & gt; Logic Tool when no
PICkit 2 unit is available
& gt; Addresses issues with multiple PICkit 2 unit support:
- When the selected unit is in bootloader, no longer asks twice
to select a unit.
- Fix for a " Download Failed " issue when updating a unit with
other units connected to the PC.
- After updating a unit's OS, it will open the dialog asking
the user to select a unit (if more than 1 are present).
After the update reset, the unit may enumerate with a
different USB ID.
*** IMPORTANT NOTES WHEN USING MULTIPLE PICKIT 2 UNITS ***
* *
* 1) When updating a unit's OS, it is strongly recommended *
* that it be the only unit connected. *
* 2) Never connect more than 1 PICkit 2 with firmware OS *
* earlier than v2.30.01. It may crash the PICkit 2 app *
* and/or Windows. *
* 3) Never connect more than 1 PICkit 2 in Bootloader mode *
* ( " Busy " LED blinking slowly). This may crash Windows. *
* 4) Never update the firmware OS of a unit when another unit *
* in bootloader mode is connected, or has OS earlier than *
* v2.30.00 *
* 5) The PIckit 2 Programmer Application will detect up to a *
* maximum of 8 connected PICkit 2 units. *
*****************************************************************
-----------------------------------------------------------------
Release notes V2.50.01
-----------------------------------------------------------------
Bug Fixes:
-------------
& gt; Requires firmware v2.30.01 which fixes an issue with 24LC
serial EEPROM reads.
-----------------------------------------------------------------
Release notes V2.50.00
-----------------------------------------------------------------
New Features:
-------------
& gt; PIC32 Device Support
See section 2 of this file for specific part numbers supported.
ASCII view options are not available for PIC32 devices, and
Fast Programming is always enabled.
& gt; Multiple PICkit 2 unit support on one PC
Multiple PICkit 2 units may be used with multiple instances of
the PICkit 2 Programmer application and with MPLAB. For
example, one might be used in MPLAB as a debugger, a 2nd with
the UART Tool, and a 3rd with the Logic Tool.
When opening the PICkit 2 application or selecting " Tools & gt;
Check Communications " a dialog will open if multiple units are
found. The dialog lists all connected PICkit 2 units and their
assigned UnitID string, and is used to select a unit to use.
Versions of MPLAB that are not aware of multiple units (v8.10
and earlier) will use the PICkit 2 unit listed in the dialog
as Unit# = 0.
& gt; Multiple Window View option with resizable memory windows.
New in v2.50.00 is the " View " menu, with two selectable view
options:
" Single Window " - this is the default window used by prior
versions.
" Multi-Window " - The PICkit 2 application window is divided
up into 3 windows:
Main Window - essentially, the top of the
Single Window display.
Program Memory - Program memory contents are
displayed in a separate
re-sizable window.
EEPROM Data - separate resizable window
with device EEPROM contents.
The EEPROM Data window is only displayed for devices which
have internal EEPROM memory. Both memory region windows may
also be closed or minimized, reducing the screen footprint
of the application to only the Main Window. Close memory
windows may be opened by selecting them under the " View " menu.
The " Associate / Memory Displays in Front " option associates
the windows so they move, minimize, and come into focus
together. It also shows memory displays always in front of
the main window. If this option creates problems with a
particular display, it can be unchecked to disable it.
NOTE: If a multi-window display problem occurs, or a window
is " lost " , the defaults can be restored by deleting the
PICkit2.INI file in the installation directory.
& gt; PICkit 2 Programmer-To-Go
This new functionality allows a memory image to be downloaded
to the PICkit 2 and programmed later without a PC. All PIC
MCU families are supported with the exception of PIC32. See
" Help & gt; Programmer-To-Go User Guide " for more information.
& gt; Manual Device Select
" Programmer & gt; Manual Device Select " may used to select devices
in all families from a drop-down box. This can be useful for
importing HEX files to view when no device is present, and to
download a memory image for Programmer-To-Go when a device is
not avaiable to connect.
& gt; Logic Tool
The Logic Tool, available under " Tools & gt; Logic Tool " allows
the PICkit 2 to be used to provide stimulus to and monitor
signals in a target circuit. It also provides a 3-channel
logic analyzer with complex trigger options. See " Help & gt;
Logic Tool User Guide " for more information.
& gt; UART Tool VDD
When using the UART Tool, the PICkit 2 unit may supply VDD to
the target circuit. The UART tool is now documented in the
PICkit 2 User's Guide.
& gt; Memory display select & copy data
The contents of the Program Memory display and EEPROM Data
display may be selected and copied. Use the mouse with click
and drag to select portions of the memory data. Right click
and select " Select All " or press ctrl-A to select the entire
memory contents. Right click and select " Copy " or press
ctrl-C to copy the data to the clipboard. The selected
addresses and data are copied to the clipboard as tab-delimited
text.
This works with both View options.
& gt; Display of HEX file Code / Data Protect settings
When a hex file with Code Protect and/or Data Protect bits
asserted in the Configuration bits is loaded, this is noted
by displaying " Code/Data/All Protect " next to the Configuration
Word(s) display. Similarly, the protect settings are noted for
Configuration read from a device. Note that protection
settings in an imported hex file or read from a device may not
be turned off in the application.
& gt; MCP250xx CAN device programming support. See section 2 for
specific part numbers. IMPORTANT: These devices are One-
Time-Programmable (OTP) and CANNOT be reprogrammed. Also,
the devices MUST be powered from PICkit 2 during programming.
& gt; PIC18 J-series programming change
PICkit 2 v2.50 changes the way Configuration words are programmed
to match the behavior of the MPLAB IDE. When programming, the
upper nibble of configuration words is always set to hex " F " .
When erasing, unused configuration bits are masked off to " 0 " .
& gt; PIC24FJ programming change
PICkit 2 v2.50 changes the way Configuration words are programmed
to match the behavior of the MPLAB IDE. When programming, the
upper byte of configuration locations is always set to hex " FF " .
Unimplemented bits are shown as '1' in the Program Memory
window.
& gt; PIC24HJ / dsPIC33FJ Programming change
PICkit 2 v2.50 now always disables the JTAGEN configuration bit.
& gt; The PICkit 2 application window remembers its last location on
the screen when closed and re-opened.
& gt; Warns if the hex file contains settings for some Configuration
Words but not others.
& gt; Now displays 16-bit device revisions when REVS: is enabled in
the INI file.
& gt; Preliminary Microsoft Windows Vista 64-bit OS support.
Bug Fixes:
-------------
& gt; Fixed an issue where application could not open the Device File
if it did not have write permissions in the application
directory.
& gt; Fixed display issues with DPI settings other than 96 (Normal)
& gt; When the attached PICkit 2 is in Bootloader mode, the
" Help & gt; About " dialog now correctly reports the bootloader
version.
& gt; Fixed an issue where the view mode was always reset to
" Hex Only "
& gt; The " Write on PICkit Button " no longer programs endlessly when
the button is held down. It programs once and waits for the
button to be released.
& gt; Fixed issues with detection on PIC18 K-Series devices erasing
or corrupting Midrange devices on startup or when selecting
" Check Communication " .
& gt; Fixed issue with 16F5x baseline hex import, which could cause
configuration verify errors when programming.
-----------------------------------------------------------------
Release notes V2.40.00
-----------------------------------------------------------------
New Features:
-------------
& gt; New menu option " Tools - & gt; Use VPP First Program Entry "
When selected, can allow PICkit 2 to connect to and program
devices with configurations and code that intereferes with the
ICSP signal pins.
Symptoms that might require turning this option on include
Writing a device and getting a 'Verification of configuration
failed.' error, and not being able to connect to the device
for further programming operations.
NOTE that when this option is enabled, the target MUST be
powered from the PICkit 2 VDD pin. It will not work with
target-powered devices.
& gt; VDD set value retained across application sessions.
When the PICkit 2 Programmer application is opened, the value
in the VDD set box when the application was last closed will be
restored. However, if a part is detected from a device family
different than the family that was active when the application
was last closed, the VDD box value will not be restored and it
will be set to a default value.
For example:
When the application was closed:
PIC18F family was active, VDD was set to 3.1V
Then when restarted:
If PIC18F device is detected - VDD is restored to 3.1V
If no device detected - VDD is restored to 3.1V
(Family is defaulted to last used)
If Midrange PIC16F device detected - VDD defaults to 5.0V
(any family besides last used (18F), VDD set default)
& gt; Calibrate Vdd & Set Unit ID
This option under the " Tools " menu allows the PICkit 2 Vdd
output voltage to be calibrated using a Volt Meter. This also
increases the accuracy of detected voltages for powered
targets. Frequently accuracies within 2% can be achieved.
NOTE: Since the PICkit 2 voltages are referenced to the USB
voltage, the calibration may not be valid if the
PICkit 2 is moved to another USB port or host PC.
NOTE: The PICkit 2 VDD output high end is still limited by
the USB voltage and the D4 diode drop.
The calibration is stored in the PICkit 2 unit, so a unit
will remain calibrated when used with the MPLAB IDE.
A Unit ID may also be assigned to a PICkit 2 unit. The
PICkit 2 programmer application will identify the attached
PICkit 2 unit with the ID in the application title bar.
This can be useful in keeping track of and identifying
multiple PICkit 2 units.
NOTE: This menu option is not available if memory editing has
been disabled with an " EDIT: N " entry in the INI file.
See " Release notes V2.01.00 " for more information.
& gt; OSCCAL instruction verification.
For devices with an OSCCAL oscillator calibration value
instruction in the last location of program memory, the
PICkit 2 GUI will indicate if an invalid instruction value
is detected in the Device Configuration display.
During a WRITE or ERASE operation, if an invalid OSCCAL value
is detected, the application will warn the user and give them
the option to abort the operation or continue.
& gt; KEELOQ HCS part support.
HCSxxx File - & gt; Import HEx Notes:
The first line only may be imported from SQTP
*.NUM files generated by the KEELOQ tool in
MPLAB.
Connections for HCS devices
---------------------------------------
PICkit 2 Pin HCS Device Pin
(2) Vdd 8
(3) GND 5
(5) PGC /3 HCS20x, 320
\3 -or- 4 HCS30x, 36x
(4) PGD 6
(1) VPP 2 HCS360, 361 only
& gt; Serial EEPROM support:
24LC I2C bus devices:
Bus Speed-
400kHz with Tools - & gt; Fast Programming checked
100kHz with Tools - & gt; Fast Programming unchecked
NOTE: Bus pullups are required for all
programming operations. 400kHz requires
2k Ohm pullups.
Ax Chip Select checkboxes-
These are only enabled for devices that support
address chip selects, and allow programming of
multiple devices on the same bus.
Connections for 24LC devices
---------------------------------------
PICkit 2 Pin 24LC Device Pin (DIP)
(2) Vdd 8 Vcc
(3) GND 4 Vss
(5) PGC 6 SCL (driven as push-pull)
(6) AUX 5 SDA (requires pullup)
7 WP - disabled (GND)
1, 2, 3 Ax pins
Connect to Vdd or GND per
datasheet and to set address
25LC SPI bus devices:
Bus Speed-
~925kHz with Tools - & gt; Fast Programming checked
~245kHz with Tools - & gt; Fast Programming unchecked
Connections for 25LC devices
---------------------------------------
PICkit 2 Pin 25LC Device Pin (DIP)
(1) VPP 1 nCS
(2) Vdd 8 Vcc
(3) GND 4 Vss
(4) PGD 2 SO
(5) PGC 6 SCK
(6) AUX 5 SI
7 nHOLD - disabled (Vdd)
3 nWP - disabled (Vdd)
93LC Microwire bus devices:
Bus Speed-
~925kHz with Tools - & gt; Fast Programming checked
~245kHz with Tools - & gt; Fast Programming unchecked
Connections for 93LC devices
---------------------------------------
PICkit 2 Pin 93LC Device Pin (DIP)
(1) VPP 1 CS
(2) Vdd 8 Vcc
(3) GND 5 Vss
(4) PGD 4 DO
(5) PGC 2 CLK
(6) AUX 3 DI
7 PE - enabled (Vdd)
6 'C' Device ORG
Set to select word size
& gt; UART Tool
The UART Communication Tool, available under the " Tools " menu,
allows the PIckit 2 to be used as a serial UART interface for
communicating with a microcontroller. Potential uses include:
- Display debug text output from the microcontroller
- Logging microcontroller data to a text file
- Developing & debugging a serial UART interface
- Sending commands to the microcontroller during development
The PICkit 2 unit connects as follows:
PICkit 2 Pin Target UART
(1) VPP
(2) Vdd Vdd (Vcc)
(3) GND GND
(4) PGD TX - inverted, logic level
(5) PGC RX - inverted, logic level
(6) AUX
IMPORTANT CONNECTION NOTES:
PICkit 2 cannot supply Vdd when using the UART Tool.
The PICkit 2 Vdd pin MUST be connected to the target UART
Vdd or it will not work.
TX & RX signals are inverted (Start Bit = GND, Stop Bit =
Vdd) at logic levels. The PICkit 2 CANNOT be
connected to RS-232 +/- 12V signals.
The UART Tool window may be resized (expanded) and the PICkit 2
BUSY LED acts as an activity light (for both RX & TX)
Baud Rate:
The baud rate is selectable from the dropdown box in the
upper left corner. Common rates are included, however
by selecting " Custom... " any baud rate from 150 to
38400 in 1 baud increments may be used.
Connect/Disconnect:
The baud rate can only be changed when Disconnect is
selected. Data will only be received and trasmitted when
Connect is selected.
Mode : ASCII
- Received bytes are displayed as ASCII characters.
- Bytes are transmitted by typing on the keyboard,
using the String Macros, or pasting text.
- Transmitted data is not displayed unless " Echo On "
is checked.
- If " Append CR + LF " is checked, then when " Send " is
clicked for a String Macro, an extra two bytes
comprising of a Carriage Return (0x0D) and Line Feed
(0x0A) are sent after the string data.
- A New Line is displayed when both a Carriage Return
and Line Feed are received. Individually, they will
display as a box character.
Mode : Hex
- Received bytes are displayed as hex values preceded by
" RX: "
- Bytes are transmitted only by using the Hex Sequence
boxes. Transmitted bytes are always displayed as hex
values preceded by " TX: "
String Macros / Hex Sequences:
These text boxes allow strings of ASCII characters or
hex bytes to be entered and sent all at once by clicking
the " Send " button. They can also be used for frequently
used string commands.
In ASCII mode, each box has a limit of 60 characters.
In Hex mode, each box has a limit of 48 bytes.
Wrap Text:
In either mode, determines whether text without a newline
will wrap at the right edge of the display area, or be
displayed on a single line with a horizontal scroll bar.
The display will keep about 200 lines of received text in
the buffer.
Log to File:
Allows received & transmitted data to be saved to a text
file as it appears in the display area. Only data
received and transmitted after the logfile is opened will
be saved. Existing data in the display is not saved.
While logging data, the button turns green. To stop
logging data and close the file, click the button again.
Clear Screen:
Clears the display buffer. Does not affect log file.
Exit UART Tool:
Returns to the PICkit 2 Programmer interface.
& gt; New Operating System firmware v2.10. If you are using a
version of MPLAB IDE prior to 7.62, it will want to reprogram
the firmware to an earlier version. If you switch between
applications frequently and want to prevent this, do the
following -
Copy the file:
C:\Program Files\Microchip\PICkit 2 v2\PK2V021000.hex
into:
C:\Program Files\Microchip\MPLAB IDE\PICkit 2\
Thanks to Lanchon, xiaofan, and many other users & Microchip
forum members for all their suggestions, comments, and feedback.
-----------------------------------------------------------------
Release notes V2.30.00
-----------------------------------------------------------------
New Features:
-------------
& gt; File - Import Hex and File - Export Hex are now affected by the
memory region checkboxes for parts with EEPROM data. During
import, unchecked regions will not be imported and the existing
memory buffer contents will be unchanged (unless a different
part is detected.) During export, unchecked memory regions
will not be included in the saved hex file.
This allows only EEPROM data to be imported from a hex file,
for example, or all data except EEPROM. On export, it allows
creation of a hex file without EEPROM data, or with only
EEPROM data.
& gt; For Vdd = 3.6V Max parts, now sets voltage to a nominal 3.3V.
& gt; New view format for Program Memory and EEPROM Data
" Word ASCII " displays the same as " Hex+ASCII " in prior releases.
ASCII characters are displayed in the same order bytes
appear in the memory word. Ex:
'694D 7263 636F 6968 iM rc co ih'
" Byte ASCII " - new display format where ASCII characters are
displayed in memory byte order with a space in between.
This gives better readability to strings in memory. Ex:
'694D 7263 636F 6968 M i c r o c h i'
& gt; Low Vdd programming of selected Midrange parts, all PIC18F, and
most dsPIC30F parts.
-----------------------------------------------------
|NOTE: Low Vdd programming WILL NOT WORK if any |
|config code, data, or write protect bits are active! |
-----------------------------------------------------
-----------------------------------------------------
|NOTE: This is not the same as LVP programming, which |
|uses the PGM pin for program mode entry. |
-----------------------------------------------------
Previously, programming always used a Bulk Erase which required
a minimum Vdd of 4.5V for Midrange parts, many PIC18F parts,
and dsPIC30F parts.
Midrange: Some Midrange parts support a flash row erase
process at below 4.5V. These devices are now
supported for programming at Vdd & lt; 4.5V using
the row erase.
See the device support list for supported parts.
PIC18F: All PIC18F parts now program down to 3.0V. Some
will program at lower voltages; the user will be
warned if the voltage is too low.
dsPIC30F: Most dSPIC10F devices now program down to 3.0V.
The exceptions are the dsPIC30F5011 and
dsPIC30F5013.
-----------------------------------------------------
|NOTE: The [ERASE] button/menu still uses Bulk Erase |
|only. |
-----------------------------------------------------
Therefore, [ERASE] cannot be used at voltages below the Bulk
Erase minimum Vdd.
Parts that support the low Vdd programming can be left erased
by following these steps:
1) Connect to the device
2) Select menu Device Family - & gt; {family of device in use}
This clears all buffers to the erased state
3) Click [WRITE]
4) The device is now in a completely erased state.
(NOTE this will not work if any protect bits are set)
Bug Fixes:
----------
& gt; Fixed issue with PIC18F config bit WRTC preventing the
programming of CONFIG7.
& gt; Fixed issue with EEPROM read. When PICkit 2 was started with
no device attached, then a device was attached and the first
operation was a read, EEPROM Data memory would not be read.
Now corrected.
Firmware Update:
----------------
& gt; This version requires firmware v2.02.00. MPLAB IDE
version 7.60 and prior will detect the new version and ask to
download v2.01. However, it is safe to use v2.02 with these
MPLAB IDE releases.
-----------------------------------------------------------------
Release notes V2.20.04
-----------------------------------------------------------------
Bug Fixes:
----------
& gt; Fixed handle issue causing crashes with Program On PICkit Button
-----------------------------------------------------------------
Release notes V2.20.00
-----------------------------------------------------------------
New Features:
-------------
& gt; dsPIC30 support
& gt; PIC18LF_J_ support:
NOTE: If these devices do not have VDDCORE being supplied
by an external regulator from the general VDD (that
is able to handle 3.6 Volts), but VDDCORE is
powered directly from the PICkit 2 VDD output, the
following precautionary steps must be taken. These
prevent a potentially damaging overvoltage on
VDDCORE:
Step 1 - Do not connect the target device to the
PICkit 2 unit when opening the
programming application.
Step 2 - After the application is opened, select
Menu " Device Family & gt; PIC18F_J_ " (if
this is not the current family)
Step 3 - Change the " VDD PICkit 2 " voltage box
to between 2.5 and 2.7 Volts
Step 4 - Connect the target device to the
PICkit 2 unit.
Step 5 - Detect the device by either trying a
programming operation (such as Read)
or again selecting menu
" Device Family & gt; PIC18F_J_ "
Bug Fixes:
----------
& gt; Fix issue with with Erase voltage warning dialog and Auto-
Import-Write that was causing an exception.
-----------------------------------------------------------------
Release notes V2.11.00
-----------------------------------------------------------------
New Features:
-------------
& gt; Imports/exports new MPLAB PIC24HJ and dsPIC33 HEX file format
Bug Fixes:
----------
& gt; Baseline & Midrange hex files imported with Code Protect config
bit asserted now display correct checksum
& gt; PIC18F hex files imported with add Code Protect config bits
asserted now display correct checksum
NOTE: PIC18F hex fies imported with only some (not all) CP bits
will display a checksum not matching MPLAB
& gt; Code Protect masks for PIC24HJ and dsPIC33 parts updated
-----------------------------------------------------------------
Release notes V2.10.01
-----------------------------------------------------------------
New Features:
-------------
& gt; 44-Pin Demo Board User's Guide included with installation and
linked to under " Help " menu.
& gt; 'Tools & gt; Write on PICkit Button' state now saved in INI file.
& gt; If an Auto-Import-Write fails,the button is now left enabled
to more easily retry.
Bug Fixes:
----------
& gt; Auto-Import-Write function no longer locks up if VDD is set to
" Force Target " and no target power is present. Also, when set
to " Auto-Detect " , popup dialogs indicating new power mode are
suppressed.
-----------------------------------------------------------------
Release notes V2.10.00
-----------------------------------------------------------------
New Features:
-------------
& gt; dsPIC33FJ support and PIC24HJ support
& gt; Better support of devices with configuration set for /MCLR OFF
& gt; Troubleshooting Wizard for assistance debugging ICSP
connections.
& gt; Added Programmer - & gt; Hold Device in Reset and /MCLR checkbox
Allows control over device /MCLR signal.
(Active low when selected, tri-state when not)
& gt; Frequently used menu items have keyboard shortcuts.
& gt; Auto functionality added to Import HEx & Write Device.
When selected hex file is updated, it is automatically imported
and written to the device.
-----------------------------------------------------------------
Release notes V2.01.00
-----------------------------------------------------------------
New Features:
-------------
& gt; PIC24FJ part support
& gt; Significantly faster programming times for PIC18F
& gt; ASCII views of data
& gt; File menu import history
& gt; Verify on Write can be turned off
& gt; Verify and Blank Check will stop on the first error, and report
the location of the error.
& gt; Begin programming on PICkit 2 button.
& gt; Separate enables for Program Memory and Data Memory
Code Protects.
& gt; Target VDD support may be set to
Auto-Detect
Always Powered from PICkit 2
Always Powered by Target Board
& gt; Selectable programming speed for heavily loaded ICSP lines
& gt; Pop-up with memory address on program memory and data memory
& gt; Menu settings are remembered the next time the application is
started.
& gt; Memory Region Selection:
The following programmer functions will always operate on all
regions of device memory, regardless of memory region select
checkboxes:
Programmer - & gt; Erase
programmer - & gt; Blank Check
For devices with EEPROM Data Memory, the checkboxes will
affect the following programmer functions:
Programmer - & gt; Read (including Read & Export button)
Programmer - & gt; Write (including Import & Write button)
Programmer - & gt; Verify
The regions affected are as follows:
Program Checkbox: EE Data Checkbox: Read/Write/Verify:
----------------- ----------------- ------------------
[X] [X] All regions
[X] [ ] Program Memory, UserIDs,
Config Word(s)*
[ ] [X] EE Data only*
[ ] [ ] - not allowed -
*NOTE that region selections may not work properly if
code protect, data protect, or write protects are
presently active in the device.
Program Memory and EEPROM Data editing:
---------------------------------------
By default, program memory and EEPROM data may be edited in the
display windows.
To disable this feature, edit the INI file
C:\Program Files\Microchip\PICkit 2 v2\PICkit2.ini
(Created when the application is first run)
Change the " EDIT " parameter to " N " :
EDIT: N
PICKIT™ 2
LOGIC TOOL USER GUIDE
1 Introduction
The PICkit 2 Logic Tool allows the PICkit 2 ICSP connector pins to be used for stimulating and probing
digital signals in a target circuit, and as a simple 3 channel logic analyzer. The Logic Tool is opened by
selecting Tools & gt; Logic Tool … in the main PICkit 2 application window.
The Logic Tool has two operating modes. The Logic I/O mode is useful for triggering inputs to a PIC
microcontroller or other digital circuitry, and can monitor digital signals to display their state. In
essence, it provides an alternative for wiring buttons and LEDs to pins or signals while debugging or
developing I/O functions.
The Analyzer mode can display waveforms of up to 3 digital signals, and trigger on specific events such
as a rising edge on one signal when another signal is at a logic high level. This may be very useful for
debugging serial communication buses such as UART, SPI, and I2C. It is also very applicable to
monitoring the behavior of general microcontroller I/O.
Information in this guide covers:
Logic I/O mode
Analyzer mode
© 2008 Microchip Technology Inc.
Page 1 of 16
PICkit™ 2 Logic Tool Users Guide
2 Logic I/O Mode
The PICkit 2 Logic Tool “Logic I/O” mode is the default mode when the Logic Tool is first opened. It
allows simple stimulus and monitoring of digital signals. The Logic Tool mode is set by the two buttons
in the upper right of the Logic Tool window.
The 6-pin PICkit 2 ICSP connector has 4 signal pins that can be used inject a digital signal into a circuit
or display the state of a digital signal from a circuit. The remaining two pins are dedicated for Vdd and
Ground connections.
The 6 ICSP pins can function as follows in Logic I/O mode:
Pin
1
2
3
4
5
6
ICSP Function
VPP/MCLR
VDD
GND
PGD
PGC
AUX
Logic I/O Function
Digital Output
VDD - must connect to or match target VDD
GND - must connect to target circuit ground
Digital Output or Digital Input
Digital Output or Digital Input
Digital Output or Digital Input
IMPORTANT
The PICkit 2 VDD pin must be connected to the target circuit VDD supply, or set to provide a VDD
output voltage in the main PICkit 2 application form.
The voltage level at the VDD pin sets the output high voltage for pins 4, 5, & 6 when used as outputs.
For example, if using the PICkit 2 to provide digital stimulus to a 3.3 Volt circuit, the VDD pin should
be either set to or connected to a 3.3 V supply to limit the output high voltage to 3.3 Volts.
Pin 1’s output voltage swing is determined by the voltage on the VDD pin when the Logic I/O is first
enabled.
IMPORTANT
When used as inputs, pins 4 & 5 may be used to monitor signals down to 2.5 Volt logic, as these are
TTL input buffers. Pin 6, as an input, may be used to monitor signals down to 3.6 Volt logic. It may
not reliably report high signal states for lower voltage logic signals as the input buffer is a Schmitt
Trigger.
© 2008 Microchip Technology Inc.
Page 2 of 16
PICkit™ 2 Logic Tool Users Guide
2.1
Configuring the Logic Tool Logic I/O
First, to use the Logic I/O mode the Logic I/O mode button on the upper right of the logic window must
be depressed as shown in Figure 2-1.
FIGURE 2-1:
INITIAL LOGIC I/O MODE DISPLAY
Energizer Energi To Go Mini USB Cell Phone Charger
This portable cell charger device runs off two standard AA batteries, and connects via a
Secondly, the 4 PICkit 2 pins used for Logic I/O digital signals (pins 1, 4, 5, & 6) will remain tri-stated
(inactive) until the Enable IO button is pressed, as shown in Figure 2-2. Once the IO is enabled, it
becomes active and can be configured. If no valid voltage is detected on the VDD pin when clicking
Enable IO a dialog will pop up to alert the user, and the PICkit 2 pins will remain disabled.
© 2008 Microchip Technology Inc.
Page 3 of 16
PICkit™ 2 Logic Tool Users Guide
FIGURE 2-2:
LOGIC I/O MODE ENABLED
Now that the pins of the PICkit 2 unit are enabled, the pin directions and output states can be configured.
2.1.1
Setting Pin Direction
Pins 4, 5, & 6 may be configured as Outputs (output a digital signal from PICkit 2) or Inputs (monitor a
digital signal state connected to the pin). Pin 1 is only available as an Output.
Click the radio buttons next to the Pin # to set the pin as an Output or Input. When the pin is an Input,
the connected signal state is displayed in the blue “Inputs” box as shown in Figure 2-3 and Figure 2-4.
FIGURE 2-3:
LOGIC I/O INPUT SIGNAL IS LOGIC LOW (‘0’)
FIGURE 2-4:
LOGIC I/O INPUT SIGNAL IS LOGIC HIGH (‘1’)
© 2008 Microchip Technology Inc.
Page 4 of 16
PICkit™ 2 Logic Tool Users Guide
Note: Pin 4 and Pin 5 have a 4.7k Ohm pulldown resistor internal to the PICkit 2. This resistor is
necessary for the PICkit 2 debugger functions, but note that this pulldown resistor will affect
any digital signal it is connected to. Generally, this is only an issue when using Pin 4 or Pin 5
as an input. See the PICkit 2 schematic in the PICkit 2 User’s Guide Appendix for the pin
circuit diagrams.
When a pin is selected as an Output, the pin will drive the logic level shown in the read “Outputs” box.
Toggle the output state by clicking on the Output state box. Alternatively, a keyboard shortcut key can
used for each pin to toggle the output. The shortcut keys are:
Pin
1
4
5
6
Shortcut Key
& lt; A & gt;
& lt; S & gt;
& lt; D & gt;
& lt; F & gt;
FIGURE 2-5:
LOGIC I/O OUTPUT LOGIC LOW (‘0’)
FIGURE 2-6:
LOGIC I/O OUTPUT LOGIC HIGH (‘1’)
© 2008 Microchip Technology Inc.
Page 5 of 16
PICkit™ 2 Logic Tool Users Guide
3 Logic Analyzer Mode
The Analyzer mode of the PICkit 2 Logic Tool enables using PICkit 2 as a simple 3 channel logic
analyzer to capture, view, and measure the digital waveforms of up to 3 signals.
3.1
Connecting the PICkit 2 in Analyzer Mode
The PICkit 2 ISCP connector pins 4, 5, & 6 are used as the inputs for the 3 logic channels.
Pin
1
2
3
4
5
6
ICSP Function
VPP/MCLR
VDD
GND
PGD
PGC
AUX
Logic Analyzer Function
- (No Connect)
VDD - must connect to or match target VDD
GND - must connect to target circuit ground
Analyzer Channel 1
Analyzer Channel 2
Analyzer Channel 3
For example, to monitor a SPI bus, the analyzer channel pins could be connected to monitor the 3 main
bus signals as follows:
Logic Analyzer Pin
Analyzer Channel 1
Analyzer Channel 2
Analyzer Channel 3
SPI Bus Signal
SCK
SDO (bus master output)
SDI (bus master input)
IMPORTANT
The PICkit 2 VDD pin must be connected to the target circuit VDD supply, or set to provide a VDD
output voltage in the main PICkit 2 application form.
Having the VDD pin connected is necessary as the PICkit 2 logic channel pins are clamped to the VDD
pin voltage. If no voltage is present on VDD, the analyzer channel pins will be essentially clamped to
ground!
It is possible to have PICkit 2 output a VDD voltage without connecting pin 2 to the circuit VDD, as
long as the VDD level is greater than or equal to the target circuit logic high voltage.
Note: Pin 4 and Pin 5 have a 4.7k Ohm pulldown resistor internal to the PICkit 2. This resistor is
necessary for the PICkit 2 debugger functions, but note that this pulldown resistor will affect
any digital signal these pins are connected to. See the PICkit 2 schematic in the PICkit 2
User’s Guide Appendix for the pin circuit diagrams.
IMPORTANT
Channels 1 & 2 (pins 4 & 5) may be used to monitor signals down to 2.5 Volt logic, as these are TTL
input buffers. Channel 3 (pin 6) may be used to monitor signals down to 3.6 Volt logic. It may not
reliably report high signal states for lower voltage logic signals as the input buffer is a Schmitt Trigger.
© 2008 Microchip Technology Inc.
Page 6 of 16
PICkit™ 2 Logic Tool Users Guide
3.2
The Logic Analyzer Window
The Logic Tool analyzer window is divided into 3 sections as show in Figure 3-1. These are
1. Display – for viewing and measuring captured waveforms.
2. Trigger – for setting trigger conditions for a capture
3. Acquisition – for setting the waveform sample rate and the waveform relation to the trigger
sample.
Each section will be covered one at a time.
FIGURE 3-1:
ANALYZER WINDOW SECTIONS
1
2
© 2008 Microchip Technology Inc.
3
Page 7 of 16
PICkit™ 2 Logic Tool Users Guide
3.2.1
The Analyzer Display Section
The display section of the analyzer window allows the waveform to be viewed, zoomed, measured, and
saved as a bitmap file.
Figure 3-2 shows a SPI bus waveform capture of a 2-byte transmission, and details the elements of the
display window section.
FIGURE 3-2:
Trigger
ANALYZER DISPLAY
Time Scale
Division Line
Waveform Scroll
Waveform
Zoom Level
Save
Waveform
Trigger
The trigger is a pre-defined event in the monitored signals that causes a capture of the signal
waveform. Triggering is discussed in detail in section 3.2.2 The Analyzer Trigger Section.
On the waveform display, the point where the trigger occurred is indicated by a vertical red line. In
Figure 3-2, the trigger was set to occur at the first rising edge of Channel 1, the SPI SCLK clock
signal.
Time Scale
Above left of the waveform display is the time scale. This is how much time each Division Line in
the waveform represents. In Figure 3-2, each division is 50 microseconds of time.
Division Line
A division line is a gray vertical line across the waveform display, which can be used to give a time
reference to the displayed waveform. In Figure 3-2, the first 8 clocks on Channel 1 occupy about 3
divisions, so transmitting the first SPI byte took about 3 x 50 = 150 us.
Smaller hash marks at the top and bottom of the display subdivide each time division into 5 smaller
units. Since each time division in Figure 3-2 is 50 us, the smaller hash marks represent 10 us of
time.
Waveform Scroll
The captured waveform is longer than can be shown all at once effectively in the display, so the
horizontal scroll bar allows the display to scroll for viewing the entire waveform.
© 2008 Microchip Technology Inc.
Page 8 of 16
PICkit™ 2 Logic Tool Users Guide
Waveform Zoom Level
The waveform Zoom allows 4 levels of zoom to be selected. Normally, at 1x zoom each sample of a
waveform is displayed as a pixel. A waveform is 1024 pixels, of which 500 can be displayed in the
window. By selecting zoom level “0.5x”, the waveform is compressed so 2 samples are shown per
pixel, which allows the entire waveform to be view at once, but with a loss of detail.
Zoom levels 2x and 4x display the waveform with 2 pixels per sample and 4 pixels per sample,
respectively. This allows relative time details between the waveforms to be more easily seen.
Figure 3-3 shows the SPI waveform at zoom levels of 0.5x, 1x, and 2x. Note that the time scale
changes as the zoom is changed.
FIGURE 3-3:
ANALYZER WINDOW SECTIONS
0.5x Zoom
1x Zoom
2x Zoom
Save Waveform
Click the Save button to save the current waveform display in a bitmap file. The time scale will be
added to the bottom of the display, as shown in Figure 3-3. If cursors are active, the cursors and
their times will also be saved with the display.
Note that the entire waveform is saved. In Figure 3-3, the 1x and 2x waveforms were truncated after
saving to only show the first portion.
© 2008 Microchip Technology Inc.
Page 9 of 16
PICkit™ 2 Logic Tool Users Guide
3.2.2
The Analyzer Display Cursors
The display cursors are useful for making time and frequency measurements in the displayed waveform.
Click to check the “Cursors” checkbox and enable the cursors.
Place the X cursor by left-clicking in the waveform display.
Place the Y cursor by right-clicking in the waveform display.
It can be helpful to use Zoom for exact placement of the cursors. When zoomed, the cursors will get
“wider” as they are the width of a sample and the sample width grows with increasing zoom.
Above the waveform display, the time difference between the Trigger and each cursor is displayed,
along with the difference between the triggers. The time period between the cursor is also displayed as
the related frequency.
In Figure 3-4, the cursors are used to measure the period (19 us) and frequency (53 kHz) of the SPI
clock in channel 1. The X cursor sample is 116us after the Trigger sample, and the Y cursor point is 135
us after the Trigger.
FIGURE 3-4:
ANALYZER DISPLAY CURSORS
Enable / Disable
Cursors
X Cursor
(Left click mouse)
© 2008 Microchip Technology Inc.
Time difference from
cursor to trigger
Time delta between cursors
(period frequency)
Y Cursor
(Right click mouse)
Page 10 of 16
PICkit™ 2 Logic Tool Users Guide
3.2.3
The Analyzer Trigger Section
The “trigger” is a user-defined set of events in the monitored signals that causes the capture of a
waveform.
Each channel can be assigned one of the following trigger events:
Trigger Events
‘*’ (Don’t Care)
‘1’ (Logic High)
‘0’ (Logic Low)
‘/’ (Rising Edge)
‘\’ (Rising Edge)
The analyzer channel is ignored for triggering purposes
The channel must be at a logic high state to trigger
The channel must be at a logic low state to trigger
The channel must transition from low to high states to trigger
The channel must transition from high to low states to trigger
All trigger events on all channels must happen at once in order for the trigger to activate data capture.
For example, for Figure 3-3, The trigger was set to simply detect the first rising edge on channel 1:
Figure 3-3 Trigger Conditions
Ch 1 = /
(rising edge)
Ch 2 = *
(ignore)
Ch 3 = *
(ignore)
If the trigger conditions are changed as follows, where both a rising edge must be detected on channel 1
at the same time channel 2 is at a logic high state, the trigger will happen on the second clock instead as
shown in Figure 3-5. During first clock’s rising edge, channel 2 is logic low, so this does not fully
satisfy the trigger condition.
Figure 3-5 Trigger Conditions
Ch 1 = /
(rising edge)
Ch 2 = 1
(logic high)
Ch 3 = *
(ignore)
FIGURE 3-5:
TRIGGER CH 1 RISING EDGE WHEN CH 2 IS HIGH
Finally, it is also possible to specify how many times the trigger condition must occur before waveform
capture is initiated, up to 256 times. For example, suppose we wanted to capture the 16th byte of a long
SPI transmission sequence. If we triggered on the first clock edge of the first byte, we probably
wouldn’t be able to see the 16th byte, as the analyzer would stop sampling before it occurred. However,
we can set the analyzer to pass up the first 15 bytes, by setting the trigger count to 15 bytes * 8 clocks +
1 = 121 times. This way, it will start counting clock edges on the first byte, but it won’t trigger the data
capture until the 16th byte is transmitted.
© 2008 Microchip Technology Inc.
Page 11 of 16
PICkit™ 2 Logic Tool Users Guide
To illustrate, we’ll add a count of 4 times to our trigger conditions of Figure 3-5:
Now, we’ll trigger on the 4th rising edge of channel 1 that occurs while channel 2 is logic high. This will
be the last clock of the first SPI byte as shown in Figure 3-6.
FIGURE 3-6:
TRIGGER CH 1 RISING EDGE WHEN CH 2 IS HIGH OCCURS 4 TIMES
3.2.4
The Analyzer Acquisition Section
The “Acquisition” section of the analyzer window is used to set the waveform sample rate, the position
of the trigger relative to the captured waveform, and to start or “run” the analyzer.
FIGURE 3-7:
ACQUISITION SETTINGS
Sample Rate
The sample rate is how often the analyzer channels are looked at. Each waveform capture is only 1024
samples long, so if we want to look at a longer period of time in the waveform display, we have to
sample less often.
© 2008 Microchip Technology Inc.
Page 12 of 16
PICkit™ 2 Logic Tool Users Guide
The trade-off is that at higher sample rates, we can see more detail and faster signals but only a small
window of time. At lower sample rates, we can see a longer window of elapsed time but at less detail
and may miss fast pulses.
Generally, the sample rate should be set at least 10 times the highest frequency or 5 times the fastest
pulse width to get a decent representation of the waveform. Any waveform that has frequency higher
than half the sample rate may alias Aliasing means that waveform edges are missed and so the
waveform can appear slower than it actually is.
Of course, the sample rate can always be set slower than these limits if all that’s desired is to get a
general idea of what’s going on in the circuit without much detail. For example, the sample rate could
be set much slower so it could be seen how many SPI bytes are being sent. In Figure 3-8 we can see that
8 bytes are being sent on the SPI bus. Now that we know how many bytes are sent, we could set the
sample rate higher and adjust the trigger count to see each byte in detail to figure out the byte value.
FIGURE 3-8:
8 SPI BYTES AT SLOW SAMPLE RATE
In the PICkit 2 Logic Tool analyzer, the sample rate may be selected from those shown in Table 3-1.
TABLE 3-1:
SUPPORTED SAMPLE RATES
Waveform Limitations
1
Captured Waveform Length
Maximum Frequency
(1024 samples)
(before aliasing)
1 ms
500 kHz
Sample Rate
Time Between
Samples
1 MHz
1 us
500 kHz
250 kHz
100 kHz
50 kHz
25 kHz
2 us
4 us
10 us
20 us
40 us
2 ms
4.1 ms
10.2 ms
20.5 ms
41 ms
250 kHz
125 kHz
50 kHz
25 kHz
12.5 kHz
10 kHz
5 kHz
100 us
200 us
102.4 ms
204.8 ms
5 kHz
2.5 kHz
Note 1:
Waveform length is rounded to the nearest 0.1 decimal place.
© 2008 Microchip Technology Inc.
Page 13 of 16
PICkit™ 2 Logic Tool Users Guide
Trigger Position
Changing the trigger position allows more flexibility over how the captured data relates to the trigger
event. For example, we might be more interested in what happened before the trigger, rather than after.
There are 6 selectable trigger positions:
Start of Data
This is the trigger position used in all the prior Figure waveforms. All the waveform
data, except for one division, is captured after the trigger occurs. This is best used when
all the waveform data of interest happens after the trigger.
FIGURE 3-9:
START OF DATA TRIGGER POSITION
Trigger event is here
Waveform captured
Ch 1
Ch 2
Ch 3
Center of Data
This is best used when all the waveform data of interest happens around the trigger. The
trigger event is in the middle of the waveform display.
FIGURE 3-10:
CENTER OF DATA TRIGGER POSITION
Trigger event is here
Waveform
captured
Ch 1
Ch 2
Ch 3
End of Data
All the waveform data, except for just over one division, is captured prior to the trigger
occurs. This is best used when all the waveform data of interest happens before the
trigger.
FIGURE 3-11:
END OF DATA TRIGGER POSITION
Trigger event is here
Waveform captured
Ch 1
Ch 2
Ch 3
© 2008 Microchip Technology Inc.
Page 14 of 16
PICkit™ 2 Logic Tool Users Guide
Delay 1 Window
Delay 2 Windows
Delay 3 Windows
In these cases, the trigger position is considered “Start of Data” but the waveform capture
is delayed 1000 samples (nearly one waveform display) after the trigger. This allows a
user to capture events that occur further out than the display width after a trigger happens,
without reducing the sample rate.
In other words, when “Delay 1 Window” is selected, the analyzer will wait 1000 samples
after the trigger event occurs before it begins recording waveform data. When “Delay 2
Windows” is selected, it will wait 2000 samples etc.
Each waveform display is 1024 samples, so the 1000 sample delay increment gives a
small overlap between successive delay captures. Assuming that the data of interest after
the trigger is repeatable and consistent, this allows a total waveform of up to 4 times the
sample rate window width to be pieced together. For example, it would be possible to
collect 4 ms worth of waveform data after a trigger event at the 1 MHz sample rate.
FIGURE 3-12:
DELAY 1 WINDOW TRIGGER POSITION
Trigger event is here
Delay 1000 samples
Waveform captured
Ch 1
Ch 2
Ch 3
© 2008 Microchip Technology Inc.
Page 15 of 16
PICkit™ 2 Logic Tool Users Guide
Running the Analyzer
Once the trigger conditions, sample rate, and trigger position are set as desired click the RUN button to
begin collecting waveform data and looking for trigger events.
When the analyzer is running, it will show the dialog in Figure 3-13 and the “Busy” LED on the PICkit
2 unit will be lit.
FIGURE 3-8:
ANALYZER RUNNING
Once the trigger condition is met the “Busy” LED will turn off, the “Waiting for Trigger” dialog will
close, and the analyzer waveform display will be updated with the newly captured data.
If the analyzer is not triggering as expected or if for any other reason it is necessary to stop the analyzer
from running, press the PICkit 2 unit pushbutton. When an analyzer run is cancelled, the waveform
display is not updated.
IMPORTANT
When the analyzer is running, the PICkit 2 unit is unable to service USB requests. The application will
wait until the run completes at a trigger condition or is cancelled by the pushbutton. If the PICkit 2 unit
is unplugged from USB during a run, the PICkit 2 application may hang waiting for a response from
the PICkit 2 unit.
© 2008 Microchip Technology Inc.
Page 16 of 16