Upload
guilherme-cruz
View
221
Download
0
Embed Size (px)
Citation preview
8/3/2019 51184d_MPLAB_ICD
1/104
2000 Microchip Technology Inc. DS51184D
MPLAB ICD
USERS GUIDE
Information contained in this publication regarding device applications and the like is intended by way of suggestion
only. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with
respect to the accuracy or use of such information. Use of Microchips products as critical components in life support
systems is not authorized except with express written approval by Microchip.
2000 Microchip Technology Incorporated. All rights reserved.The Microchip logo and name, PIC, PICmicro, PICMASTER, PICSTART, PRO MATE, KEELOQ, and MPLAB are regis-
tered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. In-Circuit Serial Program-
ming, ICSP, MPASM, MPLINK, MPLIB and PICDEM are trademarks of Microchip Technology in the U.S.A. and other
countries.
Intel and Pentium are registered trademarks of Intel Corporation.
Microsoft, Internet Explorer, Windows, Windows NT, Windows 2000, and Intellimouse are registered trademarks of Mi-
crosoft Corporation in the United States and/or other countries.
Netscape is a registered trademark of Netscape Communications Corporation in the United States and/or other
countries.
All product/company trademarks mentioned herein are the property of their respective companies.
8/3/2019 51184d_MPLAB_ICD
2/104
MPLAB ICD Users Guide
DS51184D
2000 Microchip Technology Inc.
8/3/2019 51184d_MPLAB_ICD
3/104
MPLAB ICD USERS GUIDE
Table of Contents
2000 Microchip Technology Inc. DS51184D-page i
Preface
Introduction ................................................................................................ 1
Highlights ................................................................................................... 1
About This Guide ....................................................................................... 1
Warranty Registration ................................................................................ 3
Recommended Reading ............................................................................ 4
Troubleshooting ......................................................................................... 4The Microchip Internet Web Site ............................................................... 5
Development Systems Customer Notification Service .............................. 6
Customer Support ..................................................................................... 8
Chapter 1. Overview and Installation
1.1 Introduction ..................................................................................... 9
1.2 Highlights ........................................................................................ 9
1.3 What MPLAB ICD Is ....................................................................... 9
1.4 Resources Used By MPLAB ICD .................................................. 101.5 MPLAB ICD System Components ................................................ 11
1.6 How MPLAB ICD Helps You ......................................................... 14
1.7 Installing MPLAB ICD Hardware ................................................... 15
1.8 Applying Power to the System Components ................................ 17
1.9 Installing MPLAB IDE Software .................................................... 17
Chapter 2. Tutorial PIC16F877
2.1 Introduction ................................................................................... 19
2.2 Highlights ...................................................................................... 19
2.3 Running MPLAB IDE .................................................................... 20
2.4 Creating a Hex File for Debugging ............................................... 21
2.5 Setting Up MPLAB ICD ................................................................. 29
2.6 Setting Programming and Debugging Options ............................. 30
2.7 Programming the PIC16F877 ....................................................... 32
8/3/2019 51184d_MPLAB_ICD
4/104
MPLAB ICD Users Guide
DS51184D-page ii
2000 Microchip Technology Inc.
2.8 Setting Up the Demo Board ..........................................................33
2.9 Running Tut877 .............................................................................332.10 Debugging Tut877 .........................................................................34
2.11 Tut877 Main Routine .....................................................................39
2.12 Tut877 Corrected Source Code ....................................................40
Chapter 3. General Setup
3.1 Introduction ...................................................................................43
3.2 Highlights ......................................................................................43
3.3 Running MPLAB IDE .....................................................................43
3.4 Setting Up the Development Mode ...............................................44
3.5 Setting Up the MPLAB ICD Dialog ................................................45
3.6 Setting Up the ICD Options Dialog ................................................47
3.7 Using MPLAB Projects ..................................................................51
Chapter 4. Basic Functions
4.1 Introduction ...................................................................................53
4.2 Highlights ......................................................................................53
4.3 MPLAB ICD Operations ................................................................53
4.4 Program Execution ........................................................................54
4.5 Breakpoints ...................................................................................55
4.6 Modifying Functions ......................................................................55
4.7 Loading a Hex File for Debugging .................................................56
4.8 Upgrading the MPLAB ICD Operating System (Firmware) ...........56
Chapter 5. Troubleshooting
5.1 Introduction ...................................................................................57
5.2 Highlights ......................................................................................57
5.3 Common Problems .......................................................................57
Appendix A. Hardware Specifications
A.1 Introduction ...................................................................................61
A.2 MPLAB ICD Module and Header ..................................................61
A.3 MPLAB ICD Demo Board ..............................................................68
8/3/2019 51184d_MPLAB_ICD
5/104
Table of Contents
2000 Microchip Technology Inc. DS51184D-page iii
Glossary
Introduction .............................................................................................. 75Highlights ................................................................................................. 75
Terms ...................................................................................................... 75
Index .........................................................................................................93
Worldwide Sales and Service .................................................................96
8/3/2019 51184d_MPLAB_ICD
6/104
MPLAB ICD Users Guide
DS51184D-page iv
2000 Microchip Technology Inc.
8/3/2019 51184d_MPLAB_ICD
7/104
2000 Microchip Technology Inc. DS51184D-page 1
MPLAB ICD USERS GUIDE
Preface
Introduction
This first chapter contains general information that will be useful to know
before using MPLAB ICD.
Highlights
The information you will garner from this chapter:
About this Guide
Warranty Registration
Recommended Reading
Troubleshooting
The Microchip Internet Web Site
Development Systems Customer Notification Service
Customer Support
About This Guide
Document LayoutThis document describes how to use MPLAB ICD as a development tool to
debug firmware on a target board. The manual layout is as follows:
General Information This section.
Chapter 1: Overview and Installation Describes what MPLAB ICD
is, how it works and how to install MPLAB ICD hardware and MPLAB
IDE software and establish communications.
Chapter 2: Tutorial PIC16F877 Shows you how to develop and
debug an application using MPLAB IDE Projects and MPLAB ICD.
Chapter 3: General Set Up Tells you how to get MPLAB ICD up and
running.
Chapter 4: Basic Functions Describes the basic functions of
MPLAB ICD.
Chapter 5: Troubleshooting Provides information on solving com-
mon problems.
Appendix A: Hardware Specifications Provides a technical descrip-
tion of the MPLAB ICD Header, MPLAB ICD Module, and MPLAB ICD
Demo Board hardware.
8/3/2019 51184d_MPLAB_ICD
8/104
MPLAB ICD Users Guide
DS51184D-page 2
2000 Microchip Technology Inc.
Glossary A glossary of terms used in this guide.
Index Cross-reference listing of terms, features, and sections of this
document.
Worldwide Sales and Service A listing of Microchip Technology
Sales and Service locations and telephone numbers worldwide.
Conventions Used in this Guide
This manual uses the following documentation conventions:
Table: Documentation Conventions
Description Represents Examples
Code (Courier font):
Plain characters Sample code
Filenames and paths
#define STARTc:\autoexec.bat
Angle brackets: < > Variables ,
Square brackets [ ] Optional arguments MPASMWIN[main.asm]
Curly brackets and
pipe character: { | }
Choice of mutually exclusive
arguments
An OR selection
errorlevel {0|1}
Lower case
characters in
quotes
Type of data filename
Ellipses... Used to imply (but not show)
additional text that is not rele-vant to the example
list
[list_option..., list_option]
0xnnn A hexadecimal number where
n is a hexadecimal digit
0xFFFF, 0x007A
Italic characters A variable argument; it can be
either a type of data (in lower
case characters) or a specific
example (in uppercase
characters).
char isascii(char, ch);
Interface (Helvetica font):
Underlined, italic
text with right arrow
A menu selection from the
menu bar
File > Save
Bold characters A window or dialog button to
click
OK, Cancel
Characters in angle
brackets < >
A key on the keyboard ,
8/3/2019 51184d_MPLAB_ICD
9/104
2000 Microchip Technology Inc. DS51184D-page 3
Preface
Documentation Updates
All documentation becomes d ated, and this users guide is no exception.
Since MPLAB IDE and other Microchip tools are constantly evolving to meet
customer needs, some MPLAB IDE dialogs and/or tool descriptions may differ
from those in this document. Please refer to our web site at
www.microchip.com to obtain the latest documentation available.
Documentation Numbering Conventions
Documents are numbered with a DS number. The 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:
Warranty Registration
Please complete the enclosed Warranty Registration Card and mail it
promptly. Sending in your Warranty Registration Card entitles you to receive
new product updates. Interim software releases are available at the Microchip
web site.
Documents (Helvetica font):
Italic characters Referenced books MPLAB IDE Users
Guide
Table: Documentation Conventions (Continued)
Description Represents Examples
XXXXX = The document number.
A = The revision level of th e do cu ment.
8/3/2019 51184d_MPLAB_ICD
10/104
MPLAB ICD Users Guide
DS51184D-page 4
2000 Microchip Technology Inc.
Recommended Reading
This users guide describes how to use MPLAB ICD. The user may also findthe data sheets for specific microcontroller devices informative in developing
firmware.
README.ICD
For the latest information on using MPLAB ICD, read the README.ICD file
(ASCII text file) included with the MPLAB ICD software. The README.ICD file
contains update information that may not be included in this document.
README.XXX
For the latest information on other Microchip tools (MPLAB, MPASM, etc.),
read the associated README files (ASCII text file) included with the MPLAB
IDE software.
MPLAB IDE Users Guide (DS51025)
Comprehensive guide that describes installation and features of Microchips
MPLAB Integrated Development Environment, including the editor and
simulator functions in the MPLAB IDE environment.
MPASM Users Guide with MPLINK and MPLIB (DS33014)
This users guide describes how to use the Microchip PICmicro assembler
(MPASM), the l inker (MPLINK), and the librarian (MPLIB).
Microchip Technology Library CD-ROM (DS00161)
This CD-ROM contains comprehensive application notes, data sheets, and
technical briefs for all of Microchip products. To obtain this CD-ROM, contact
the nearest Microchip Sales and Service location (see back page).Embedded Control Handbook Vol.1 & 2 and the Embedded Control
Update 2000 (DS00092, DS00167, and DS00711)
These handbooks contain a wealth of information about microcontroller
applications. To obtain these documents, contact the nearest Microchip Sales
and Service location (see back page).
The application notes described in these manuals are also obtainable from
Microchip Sales and Service locations or from the Microchip web site
(http://www.microchip.com).
Microsoft Windows Manuals
This manual assumes that users are familiar with their Microsoft Windows
operating system. Many excellent references exist, and should be consulted
for general operation of Windows.
Troubleshooting
See Chapter 5 for information on common problems.
8/3/2019 51184d_MPLAB_ICD
11/104
2000 Microchip Technology Inc. DS51184D-page 5
Preface
The Microchip Internet Web Site
Microchip provides on-line support on the Microchip World Wide Web (WWW)site.
The web site is used by Microchip as a means to make files and information
easily available to customers. To view the site, the user must have access to
the Internet and a web browser, such as Netscape Communicator or
Microsoft Internet Explorer. Files are also available for FTP download from
our FTP site.
Connecting to the Microchip Internet Web Site
The Microchip web site is available by using your favorite Internet browser
to connect to:
http://www.microchip.com
The file transfer site is available by using an FTP service to connect to:
ftp://ftp.microchip.com
The web site and file transfer site provide a variety of services. Users may
download files for the latest Development Tools, Data Sheets, Application
Notes, User's Guides, Ar ticles, and Sample Programs. A variety of Microchip
specific business information is also available, including listings of Microchip
sales offices, distributors and factory representatives. Other data available for
consideration is:
Latest Microchip Press Releases
Technical Support Section with Frequently Asked Questions Design Tips
Device Errata
Job Postings
Microchip Consultant Program Member Listing
Links to other useful web sites related to Microchip Products
Conferences for products, Development Systems, technical information
Listing of seminars and events
8/3/2019 51184d_MPLAB_ICD
12/104
MPLAB ICD Users Guide
DS51184D-page 6
2000 Microchip Technology Inc.
Development Systems Customer Notification Service
Microchip provides a customer notification service to help our customers keepcurrent on Microchip products with the least amount of effort. Once you
subscribe to one of our list servers, you will receive email notification
whenever we change, update, revise or have errata related to that product
family or development tool. See the Microchip web site at
www.microchip.com.
The Development Systems list names are:
Compilers
Emulators
Programmers
MPLAB Otools (Other Tools)
Once you have determined the names of the lists that you are interested in,
you can subscribe by sending a message to:
with the following as the body:
subscribe yourname
Here is an example:
subscribe mplab John Doe
To UNSUBSCRIBE from these lists, send a message to:
with the following as the body:
unsubscribe yourname
Here is an example:
unsubscribe mplab John Doe
The following sections provide descriptions of the available Development
Systems lists.
Compilers
The latest information on Microchip C compilers, Linkers and Assemblers.These include MPLAB C17, MPLAB C18, MPLINK object linker, MPASM
Assember, as well as the Librarian, MPLIB for MPLINK object linker.
To SUBSCRIBE to this list, send a message to:
with the following as the body:
subscribe compilers yourname
8/3/2019 51184d_MPLAB_ICD
13/104
2000 Microchip Technology Inc. DS51184D-page 7
Preface
Emulators
The latest information on Microchip In-Circuit Emulators. These includeMPLAB ICE and PICMASTER emulators.
To SUBSCRIBE to this list, send a message to:
with the following as the body:
subscribe emulators yourname
Programmers
The latest information on Microchip PICmicro microcontroller (MCU) device
programmers. These include PRO MATE II and PICSTART Plus
programmers.To SUBSCRIBE to this list, send a message to:
with the following as the body:
subscribe programmers yourname
MPLAB
The latest information on Microchip MPLAB IDE, the Windows Integrated
Development Environment for development systems tools. This list is focused
on MPLAB IDE, MPLAB SIM, MPLAB IDE Project Manager and general
editing and debugging features. For specific information on MPLAB IDEcompilers, linkers and assemblers, subscribe to the COMPILERS list. For
specific information on MPLAB IDE emulators, subscribe to the EMULATORS
list. For specific information on MPLAB IDE device programmers, please
subscribe to the PROGRAMMERS list.
To SUBSCRIBE to this list, send a message to:
with the following as the body:
subscribe mplab yourname
Otools (Other Tools)
The latest information on other development system tools provided by
Microchip. For specific information on MPLAB IDE and its integrated tools
refer to the other mail lists.
To SUBSCRIBE to this list, send a message to:
with the following as the body:
subscribe otools yourname
8/3/2019 51184d_MPLAB_ICD
14/104
MPLAB ICD Users Guide
DS51184D-page 8
2000 Microchip Technology Inc.
Customer Support
Users of Microchip products can receive assistance through several channels:
Distributor or Representative
Local Sales Office
Field Application Engineer (FAE)
Corporate Applications Engineer (CAE)
Hotline
Customers should call their distributor, representative or field application
engineer (FAE) for support. Local sales offices are also available to help
customers. See the back cover for a listing of sales offices and locations.
Corporate applications engineers (CAEs) may be contacted at
(480) 792-7627.
In addition, there is a Systems Information and Upgrade Line. This line
provides system users a listing of the latest versions of all of Microchip's
development systems software products. Plus, this line provides information
on how customers can receive any currently available upgrade kits.
The Hotline Numbers are:
1-800-755-2345 for U.S. and most of Canada, and
1-480-792-7302 for the rest of the world.
8/3/2019 51184d_MPLAB_ICD
15/104
2000 Microchip Technology Inc. DS51184D-page 9
MPLAB ICD USERS GUIDE
Chapter 1. Overview and Installation
1.1 Introduction
This section gives you a preview of the MPLAB ICD (In-Circuit Debugger)
features and functions, as well as its hardware and software elements.
1.2 Highlights
Topics covered in this chapter:
What MPLAB ICD Is
Resources Used By MPLAB ICD
MPLAB ICD System Components
How MPLAB ICD Helps You
MPLAB ICD Kit Components
Installing MPLAB ICD Hardware
Applying Power to the System Components
Installing MPLAB IDE Software
1.3 What MPLAB ICD Is
MPLAB ICD utilizes the In-Circuit Debugging capability of the PIC16F87X andMicrochips In-Circuit Serial Programming (ICSP) protocol to both
program and act as an in-circuit debugger for PIC16F87X devices. It operates
under MPLAB IDE, connects to an application, and runs like the PIC16F87X
microcontroller in the design.
MPLAB ICD is intended to be used as an evaluation and debugging aid in a
laboratory environment.
The MPLAB ICD offers these features:
Real-time and single-step code execution
Breakpoint
In-circuit debugging
Built-in programming
3.0V to 5.5V operating range
Operation from voltage (VDD) supplied by the target application
Operating frequencies from 32 kHz to 20 MHz
Source level and symbolic debugging
MPLAB IDE user interface
Compatibility with Microsoft Windows 3.X, Windows 95/98,
Windows NT, and Windows 2000
RS-232 Interface
8/3/2019 51184d_MPLAB_ICD
16/104
MPLAB ICD Users Guide
DS51184D-page 10
2000 Microchip Technology Inc.
1.4 Resources Used By MPLAB ICD
Due to the built-in in-circuit debugging capability of the PIC16F87X and ICSPfunction offered by the debugger, the MPLAB ICD uses the following on-chip
resources:
MCLR/VPP is shared for programming
Low-voltage ICSP programming is disabled
Note: Low Voltage Programming is not supported by MPLAB ICD.
MPLAB ICD requires you to disable low voltage programming
while in Debug mode.
RB6 and RB7 reserved for programming and in-circuit debugging
Six or seven general purpose file registers are reserved for debug mon-
itor (see below) First program memory location (address 0x0000) must be a NOP
instruction
The last 256 or 288 words of program memory area are reserved for
Debug Code (depending on device, see below)
One stack level is not available
Data and Program Memory Used by MPLAB ICD
The MPLAB ICD uses the following file register and program memory
locations in the PIC16F87X target device:
Note: If you have an MPLAB ICD firmware version older than 2.00, you
must contact your sales office to obtain an MPLAB ICD firmware
upgrade in order to use the MPLAB ICD with a PIC16F87X other
than the PIC16F876/877.
Processor File Registers Used Program Memory Used
PIC16F870/871/872 0x70, 0x0BB-0x0BF 0x06E0-0x07FF
PIC16F873/874 0x6D,0x16D, 0x0EB-
0x0F0, 0x1EB-0x1F0
0x0EE0-0x0FFF
PIC16F876/877 0x70, 0x1EB-0x1EF 0x1F00-0x1FFF
8/3/2019 51184d_MPLAB_ICD
17/104
2000 Microchip Technology Inc. DS51184D-page 11
Overview and Installation
1.5 MPLAB ICD System Components
There are two versions of MPLAB ICD. The MPLAB ICD Evaluation Kit(DV164001) and the MPLAB ICD Module (DV164002). The MPLAB ICD
Evaluation Kit (DV164001) includes the items listed below (Figure 1.1). The
MPLAB ICD Module (DV164002) contains the same items except for items 1,
3 and 5, which are not included.
1. The MPLAB ICD Header
2. The MPLAB ICD Module
3. The MPLAB ICD Demo Board
4. RS-232 cable
5. 40-pin DIP and 28-pin SDIP connection sockets
6. 9-inch 6-conductor modular cable
7. CD with complete MPLAB IDE software and documentation8. Manuals:
- MPLAB ICD Users Guide (this document)
- MPLAB IDE Users Guide (not shown)
- MPASM with MPLINK and MPLIB Users Guide(not shown)
9. A Warranty Registration card (not shown)
Figure 1.1: MPLAB ICD Evaluation Kit Components
21
3
4
5
6
7
8
8/3/2019 51184d_MPLAB_ICD
18/104
MPLAB ICD Users Guide
DS51184D-page 12
2000 Microchip Technology Inc.
Figure 1.2: MPLAB ICD System Components
In addition to the included components, you will need a power supply to power
the MPLAB ICD Demo Board or your target application. Power can be
supplied by a PICSTART Plus power supply (part AC162039) connected to
the MPLAB ICD Demo Board or by your target application. For more
information, refer to Section A.3.
System Configurations
There are two possible MPLAB ICD system configurations:
Connect the PC and the MPLAB ICD Module. Connect the MPLAB ICDModule and the MPLAB ICD Header. Plug the MPLAB ICD Header into
the socket on the MPLAB ICD Demo Board or your target application.
This configuration only applies if you have the MPLAB ICD Evaluation
Kit.
Connect the PC and the MPLAB ICD Module. Connect the MPLAB ICD
Module and the MPLAB ICD Demo Board (if you have the MPLAB ICD
Evaluation Kit) or your target application. Plug a PIC16F87X device into
the socket on the MPLAB ICD Demo Board or your target application.
(The PIC16C87X may be soldered directly onto the target board.)
MPLABICD Module
MPLABICD DemoBoard
MPLABICD Header
RS
-232
1
2
3
Power
MPLAB ICDDEMOBOARD
To Header orDemo/Target Board
To Module
To Module
To PC
8/3/2019 51184d_MPLAB_ICD
19/104
2000 Microchip Technology Inc. DS51184D-page 13
Overview and Installation
1.5.1 MPLAB ICD Module
The MPLAB ICD Module contains all debugging, programming, and controllogic. It is connected to the PCs serial port via a 9-pin serial cable and to the
MPLAB ICD Demo Board or target application using a 6-wire modular cable.
The application board must have a 6-wire modular connection (shown as item
12 in Section 1.5.3) unless you have the MPLAB ICD Evaluation Kit, in which
case the MPLAB ICD Module can be connected to the MPLAB ICD Header
and then the MPLAB ICD Header plugged into a socket on the MPLAB ICD
Demo Board or target application.
The MPLAB ICD Module contains the firmware to provide serial
communications to the PC, to drive the MPLAB ICD communications to the
Demo Board/target board (or to the MPLAB ICD Header), and to program a
target PIC16F87X using ICSP, all from the MPLAB IDE. The MPLAB ICD
Module is powered from the MPLAB ICD Demo Board or the targetapplication and requires 70 mA (max) in addition to what the target
consumes.
The modular cable connects to the MPLAB ICD Header or the target
application with the appropriate connections to the PIC16F87X to allow in-
circuit emulation of QFP and DIE parts as described in Section 1.7.2.
1.5.2 MPLAB ICD Header
The MPLAB ICD Header, included only in the MPLAB ICD Evaluation Kit,
provides a means of connecting the MPLAB ICD Module to a target board that
does not incorporate a 6-wire modular connection into its design. The MPLAB
ICD Module connects to the MPLAB ICD Header via a 9-inch modular cable.
For in-circuit emulation, a 40-pin PIC16F87X needs to be plugged into theMPLAB ICD Header, which then plugs into a 28-pin or 40-pin PIC16F87X DIP
socket on the MPLAB ICD Demo Board or target application as described in
Section 1.7.1.
The MPLAB ICD Header is powered by the Demo Board/target board, from a
3.0V to 5.5V source.
1.5.3 MPLAB ICD Demo Board
The MPLAB ICD Demo Board, included only in the MPLAB ICD Evaluation
Kit, is provided for demonstration and evaluation of the PIC16F87X without a
target application board. It can be connected to the MPLAB-ICD Module
directly or via the MPLAB ICD Header. The PIC16F877 can be unpluggedfrom the MPLAB ICD Header and plugged directly into the MPLAB ICD Demo
Board for stand-alone operation.
The MPLAB ICD Demo Board (Figure 1.3) has the following hardware
features:
1. 40- and 28-pin sockets. For information on using stand-offs to select the
desired pin count socket, see Section A.3.
8/3/2019 51184d_MPLAB_ICD
20/104
MPLAB ICD Users Guide
DS51184D-page 14
2000 Microchip Technology Inc.
2. Eight DIP switches to connect and disconnect each of the eight LEDs to
and from its respective PORTC pin.
3. Eight red LEDs connected to PORTC for displaying 8-bit binary values.
4. Two push-button switches, one for RESET and one for external stimulus
on RB0.
5. A potentiometer for analog input on RA0.
6. A small prototyping area.
7. A connector area to access the I/O pins of the PIC16F87X for expansion
prototyping.
8. A jumper to select the RC oscillator (see Section A.3.8) or an external
crystal.
9. Socket for external crystal.
10. A connector for a 9V, 0.75A power supply, similar to the PICSTART Plus
programmer power supply. Refer to refer to Section A.3.11. Provisions for a MAX232 and associated hardware that may be popu-
lated to add RS-232 capability.
12. A modular cable connection that can be used to connect the MPLAB ICD
Demo Board directly to the MPLAB ICD Module.
Figure 1.3: MPLAB ICD Demo Board
1.6 How MPLAB ICD Helps You
The MPLAB ICD allows you to:
Debug your source code in your own application
Debug your hardware in real-time
Program a target PIC16F87X using Microchips ICSP protocol
TO
ICDMODULE
1
4
3
2
5
6
78
9
10
11
11
12
8/3/2019 51184d_MPLAB_ICD
21/104
2000 Microchip Technology Inc. DS51184D-page 15
Overview and Installation
1.7 Installing MPLAB ICD Hardware
There are two ways to use the MPLAB ICD and, hence, two ways to install thehardware.
1.7.1 Connecting the MPLAB ICD Module, Header, and
Demo/Target Board
Figure 1.4: MPLAB ICD Connection with Header
This type of installation is only applicable if you have the MPLAB ICD
Evaluation Kit. Install the MPLAB ICD system hardware by following these
steps:
1. Plug the 40-pin PIC16F87X device into the 40-pin DIP socket in the
MPLAB ICD Header board.
To RS-232
Power in
Demo Board or Target Application
MPLABICD Module
MPLABICD Demo Board
Target socke t
MPLABICD Header
To debug this part on the
target or Demo Board
Use this part on the
Header
PIC16F870 PIC16F871
PIC16F871 PIC16F871
PIC16F873 PIC16F874
PIC16F874 PIC16F874
PIC16F876 PIC16F877PIC16F877 PIC16F877
8/3/2019 51184d_MPLAB_ICD
22/104
MPLAB ICD Users Guide
DS51184D-page 16
2000 Microchip Technology Inc.
2. Connect the 9-inch modular cable between the MPLAB ICD Module and
the MPLAB ICD Header.
3. If you are debugging a 40-pin part using the MPLAB ICD Demo Board or
a target board, insert the two 20-pin male to male headers (stand-offs)
onto the MPLAB ICD Demo Board or target board sockets. Then, plugthe MPLAB ICD Header board into the stand-offs (see Section A.3).
If you are debugging a 28-pin part using the MPLAB ICD Demo Board or
a target board, insert the two 14-pin male to male headers (stand-offs)
onto the MPLAB ICD Demo Board or target board sockets. Then, plug the
MPLAB ICD Header board into the stand-offs (see Section A.3).
4. Connect the RS-232 cable between the serial port of the host computer
and the MPLAB ICD Module.
1.7.2 Connecting the MPLAB ICD Module and Demo/
Target Board
Figure 1.5: MPLAB ICD Connection Without Header
Note 1: Devices without a 40-pin equivalent cannot be used with the
MPLAB ICD Header. To debug such devices, you must connectthe MPLAB ICD Module directly to the demo/target board as
described in Section 1.7.2.
2: If you have an MPLAB ICD firmware version older than 2.00,
you must contact your sales office to obtain an MPLAB ICD
firmware upgrade in order to use the MPLAB ICD with a
PIC16F87X other than the PIC16F876/877.
To RS-232 Power in
Demo Board or Target Application
MPLAB ICD Mod ule
MPLABICD Demo Boa rd
Target socke t
PIC16F87X
8/3/2019 51184d_MPLAB_ICD
23/104
2000 Microchip Technology Inc. DS51184D-page 17
Overview and Installation
You can connect the MPLAB ICD Module directly to the MPLAB ICD Demo
Board (if you have the MPLAB ICD Evaluation Kit), or directly to your target
board if your target board incorporates a modular cable connection describedin the following table.
This configuration also provides full MPLAB ICD functionality.
1. Plug a PIC16F87X into the 28-pin or 40-pin DIP socket in the MPLAB
ICD Demo Board or target board.
2. Connect the 9-inch modular cable between the MPLAB ICD Module and
the MPLAB ICD Demo Board or your target board.
3. Connect the RS-232 cable between the serial port of the host computer
and the MPLAB ICD Module.
1.8 Applying Power to the System Components
MPLAB ICD must be run using external (target board) power.
To prevent damage to any part of the system, power up the system
components in the following sequence:1. Turn on the power to the host computer.
2. Turn on the power to the MPLAB ICD Demo Board/target application
which also powers the MPLAB ICD Module. (For the MPLAB ICD Demo
Board, you can use the 9 VDC center-positive power adapter supplied
with the PICSTART Plus Programmer.)
Turn the system components off in reverse order.
1.9 Installing MPLAB IDE Software
To install the MPLAB IDE software, refer to the installation instructions found
in the MPLAB IDE Users Guide.
The MPLAB ICD functions with the MPLAB IDE software under the following
operating systems:
Microsoft Windows 3.1x
Windows 95/98
Windows NT
Windows 2000
Pin Signal
1 RB3
2 RB6
3 RB7
4 Ground
5 +VDD
6 VPP
8/3/2019 51184d_MPLAB_ICD
24/104
MPLAB ICD Users Guide
DS51184D-page 18
2000 Microchip Technology Inc.
NOTES:
8/3/2019 51184d_MPLAB_ICD
25/104
2000 Microchip Technology Inc. DS51184D-page 19
MPLAB ICD USERS GUIDE
Chapter 2. Tutorial PIC16F877
2.1 Introduction
The MPLAB ICD is a programmer for the PIC16F87X family, as well as an in-
circuit debugger. This tutorial will help you start using the MPLAB ICD
hardware and software to program your part and debug source code.
This tutorial uses a sample project, Tut877. The tut877.asm program is
a simple implementation of the PIC16F877s analog-to-digital (A/D)
converter using the MPLAB ICD Demo Board. This program configures the
A/D module to convert an A/D channel 0 (connected to the potentiometer
on the MPLAB ICD Demo Board) and display the results on the LEDs on
PORTC.
This tutorial requires the use of the MPLAB ICD Demo Board. Therefore, if
you have the standalone MPLAB ICD Module (DV164002) rather than the
MPLAB ICD Evaluation Kit (DV164001), this chapter is not applicable.
2.2 Highlights
Topics covered in this chapter:
Running MPLAB IDE
Creating a Hex File for Debugging
Setting up MPLAB ICD Setting Programming and Debugging Options
Programming the PIC16F877
Setting up the Demo Board
Running Tut877
Debugging Tut877
Tut877 Main Routine
Tut877 Corrected Source Code
8/3/2019 51184d_MPLAB_ICD
26/104
MPLAB ICD Users Guide
DS51184D-page 20
2000 Microchip Technology Inc.
2.3 Running MPLAB IDE
After installing the MPLAB IDE software, invoke it by executing the filemplab.exe.
For more information on installing and using the MPLAB IDE, refer to the
MPLAB IDE Users Guide(DS51025) and the README.LAB file in the MPLAB
install directory.
Figure 2.1: MPLAB IDE
8/3/2019 51184d_MPLAB_ICD
27/104
2000 Microchip Technology Inc. DS51184D-page 21
Tutorial PIC16F877
2.4 Creating a Hex File for Debugging
You will need to create a new project to include the source file tut877.asm
and build the hex file tut877.hex. See the next sections for instructions on
how to create a new project, tut877.pjt.
2.4.1 New Project Directory
In File Manager (Windows 3.1) or Windows Explorer, create a subdirectory for
the new project, \MPLAB\tut877. Move the tut877.asm file from \MPLAB
to this subdirectory.
2.4.2 New Project
Select Project > New Project, select the directory for the new project, and thenenter tut877.pjt in the File Name box. Click OK.
Figure 2.2: New Project tut877.pjt
8/3/2019 51184d_MPLAB_ICD
28/104
MPLAB ICD Users Guide
DS51184D-page 22
2000 Microchip Technology Inc.
2.4.3 Project Dialog
The Edit Project dialog should open.
Figure 2.3: Edit Project Dialog Before Setting Development Mode
Notice the development mode. It indicates we are working with the
MPLAB SIM simulator and a PIC12C508 processor. Your display will indicate
whatever development mode and processor you were working with previously
in the MPLAB IDE. We will need to change these settings now.
Click Change.
8/3/2019 51184d_MPLAB_ICD
29/104
2000 Microchip Technology Inc. DS51184D-page 23
Tutorial PIC16F877
Figure 2.4: Setting the Development Mode
Select MPLAB ICD Debugger under Tools. Make sure you select the
PIC16F877 processor. Click OK.
A window will inform you that no hex file has been built for this project. We will
build the hex file later. Click OK.
MPLAB IDE will now establish communications with the MPLAB ICD. The
MPLAB ICD dialog will momentarily appear during this process. If you receive
an error message, double-check the connections for power supply, socket
seating, and cable seating. For more detailed troubleshooting information,
refer to Chapter 5.
The MPLAB ICD dialog must remain open throughout the tutorial. Do not
close the MPLAB ICD dialog when it appears. If you want, you can move the
dialog.
8/3/2019 51184d_MPLAB_ICD
30/104
MPLAB ICD Users Guide
DS51184D-page 24
2000 Microchip Technology Inc.
Figure 2.5: Edit Project Dialog
Notice that the correct development mode and processor are shown in the
Edit Project dialog.
Click on the line tut877 [.hex] in the Project Files area of the Edit Project
dialog, and then click the Node Properties button.
8/3/2019 51184d_MPLAB_ICD
31/104
2000 Microchip Technology Inc. DS51184D-page 25
Tutorial PIC16F877
2.4.4 Set Node Properties
The Node Properties dialog shows the command line switches for the tool, inthis case the MPASM assembler. When you first open this dialog, the checked
boxes represent the default values for the tool. For this tutorial, these settings
do not need to be changed from their defaults.
Click OK to return to the Edit Project dialog.
Figure 2.6: Node Properties Dialog
8/3/2019 51184d_MPLAB_ICD
32/104
MPLAB ICD Users Guide
DS51184D-page 26
2000 Microchip Technology Inc.
2.4.5 Add Node
Click Add Node from the Edit Project dialog to open the Add Node dialog.Select tut877.asm for this tutorial, and then click OK.
Figure 2.7: Add Node
8/3/2019 51184d_MPLAB_ICD
33/104
2000 Microchip Technology Inc. DS51184D-page 27
Tutorial PIC16F877
2.4.6 Complete Project Setup
In this simple example, no entries were made in the Path boxes. As yourapplication becomes more complex, you may need to enter the directories of
your Include Files in the appropriate boxes.
The MPASM assembler always makes a .hex file with the same name as the
source .asm file. The Project Manager will create a tut877.hex file when
the project is built.
Figure 2.8: Edit Project Dialog with Node
Click OK to close the Edit Project Dialog.
Now select Project > Save Projectfrom the MPLAB IDE menu to save your
project.
8/3/2019 51184d_MPLAB_ICD
34/104
MPLAB ICD Users Guide
DS51184D-page 28
2000 Microchip Technology Inc.
2.4.7 Make Project
Select Project > Make Projectfrom the menu to compile the application usingthe MPASM assembler.
A Build Results window shows the command line sent to the assembler. It
should look like this:
Figure 2.9: Build Results Window
Click the X in the upper right corner of the Build Results window to close it. Or,
click the Restore icon next to the X to resize the window. Subsequent builds
will use this smaller Build Results window.
Note: When you successfully build the project, a window will inform you
that the project has been rebuilt and that you must reprogram the
ICD in order to effect the change. If you do not want to see this
warning each time you rebuild, check the checkbox to ignore this
warning. We will do this later in the tutorial. Click Close.
Note: Message [302] is simply letting you know that, at the designated
line number (i.e., 31, 32, and 34) you are specifying a file register
that is not in bank zero. This is not an error and your code will com-
pile correctly.
8/3/2019 51184d_MPLAB_ICD
35/104
2000 Microchip Technology Inc. DS51184D-page 29
Tutorial PIC16F877
2.5 Setting Up MPLAB ICD
At this point, the MPLAB ICD dialog should be on your desktop. Make theselections described in this section to set up the MPLAB IDE for use with the
MPLAB ICD hardware.
Figure 2.10: MPLAB ICD Dialog
Table 2.1: MPLAB ICD Dialog
Item Options
Status The Status bar displays the executed MPLAB ICD
function and the status. When you program a
device, you can watch the progress in this area.
When the operation is complete, the Status box
displays the message Waiting for user command.
COM Port and Baud
Rate Pull-Down Menus
Do not change these values for this tutorial.
Upload Options Pull-
Down Menu
Select Minimum for now. Later in the tutorial we will
change this for debugging.
Operating Frequency
Range Pull-Down
Menu
Select the operation frequency range of
2 MHz 10 MHz.
Options Click this button to bring up the ICD Options dialog.
8/3/2019 51184d_MPLAB_ICD
36/104
MPLAB ICD Users Guide
DS51184D-page 30
2000 Microchip Technology Inc.
2.6 Setting Programming and Debugging Options
To program the t arget PIC16F877 device, the ICD O ptions dialog must firstbe set up for programming. The small MPLAB ICD dialog was opened
when you entered the MPLAB ICD development mode. Click Options in
the MPLAB ICD dialog to open the ICD Options dialog.
Figure 2.11: MPLAB ICD Options Dialog
8/3/2019 51184d_MPLAB_ICD
37/104
2000 Microchip Technology Inc. DS51184D-page 31
Tutorial PIC16F877
2.6.1 Configuration Bits and Device Selection
This section of the ICD Options dialog allows you to set the variousconfiguration bits on the PIC16F87X processors. Click the arrow and select
from the list.
2.6.2 IDs and Checksum
The checksum for the data and the ID code are displayed here. For this
tutorial, Use Checksum as ID by selecting the checkbox.
2.6.3 Voltages
Allows you to check the VDD and VPP voltages on the target application by
clicking the Update button.
MPLAB ICD develops its needed VPP 13V from the target boards VDD
through use of a switching boost converter.
Table 2.2: Configuration Bits and Device Selection
Item Options
Device The PIC 16F877 d evice should be shown, as
selected in the Development Mode dialog. If not,
select Options > Development Mode, select the cor-
rect device, and click OK. Then use the Project
menu item Project > Save to save your project.
Oscillator RC is used in this tutorial. Check the MPLAB ICD
Demo Board to make sure the oscillator jumper JP1is correctly placed for the RC OSC option (see item
8 in Figure 1.3). For more information on the oscilla-
tor, see Section A.3.8.
Watchdog Timer For this tutorial, the Watchdog Timer (WDT) should
be off/disabled.
Power Up Timer For this tutorial, the Power-Up Timer (PWRT)
should be on/enabled.
Brown Out Detect For this tutorial, the Brown-Out Detect (BOD)
should be off/disabled.
Low Voltage Program Low voltage ICSP programming should be disabled
when using the MPLAB ICD. This means that you
may use RB3 as digital I/O and you must use HV onMCLR for programming.
Code Protect Data EE Turn off code protection for this tutorial.
Flash Memory Write No memory will be written to EECON for this
tutorial.
Code Protect Turn off code protection for this tutorial.
8/3/2019 51184d_MPLAB_ICD
38/104
MPLAB ICD Users Guide
DS51184D-page 32
2000 Microchip Technology Inc.
2.6.4 Program Options
The program address range (Start Address and End Address) is the range ofprogram or data memory that will be read, programmed or verified.
Make sure that all checkboxes under Program Options are checked. This
means that all memory, ID, and configuration bits will be programmed. Also,
all memory will be erased before programming and Debug Mode will be
enabled.
Click Def. Addr to set the address range to the maximum program memory
available based on the device you selected.
2.6.5 Function Buttons
During the tutorial you will click these buttons to perform the assigned function
on the PIC16F87X in the MPLAB ICD Header or Demo/Target board.
2.7 Programming the PIC16F877
Click the Program button to program tut877.hex and debug code into the
PIC16F87X in the MPLAB ICD Header or MPLAB ICD Demo Board.
Programming may take a couple of minutes. During programming, the Status
box shows the current phase of the operation. When programming is
complete, the Status box displays the message Waiting for user command.
You can minimize or move the MPLAB ICD dialog, but do not close it. Closing
the MPLAB ICD dialog will disable the ICD. To reenable the ICD, you will have
to select Options > Development Mode. Select Editor Only and click Apply.
Then select MPLAB ICD and click OK to reenable the ICD.
Note: The debug code is special code at 1F00h-1FFFh in the PIC16F877
that must be present to use the in-circuit debugging capabilities of
the MPLAB ICD.
8/3/2019 51184d_MPLAB_ICD
39/104
2000 Microchip Technology Inc. DS51184D-page 33
Tutorial PIC16F877
2.8 Setting Up the Demo Board
Before you begin debugging, make sure the MPLAB ICD Demo Board is setup as follows:
the RC OSC option has been selected using jumper JP1.
the DIP switch (SW3) has all switches in the ON position to connect all
LEDs to their respective PORTC pin.
Figure 2.12: Setting Up the Demo Board
2.9 Running Tut877
The MPLAB ICD executes in real-time mode or in step mode.
Real-time execution occurs when the PIC16F87X in the MPLAB ICD
Header is put in MPLAB IDEs Run mode.
Step mode execution can be accessed after the processor is halted.
Begin in real-time mode:
Open the tut877.asm file for viewing (File > Open)
Click the Run toolbar button or issue the Debug > Run > Run command
The Status bar at the bottom of the MPLAB IDE desktop should turn yellow.To change the colors that signify a program run, select Options > Environment
Setup and click the Colors tab.
On the MPLAB ICD Demo Board, turn the arrow on the potentiometer (RA0)
till it points to the DIP switch (SW3). Observe the LEDs. If the program were
working correctly, you would see a binary representation of the voltage value
across the potentiometer. However, an insidious bug has been placed in the
Tut877 program! Of course, this will give us the opportunity to debug the code.
POTENTIOMETER
LEDs
DIP SwitchesOSC Jumper
8/3/2019 51184d_MPLAB_ICD
40/104
MPLAB ICD Users Guide
DS51184D-page 34
2000 Microchip Technology Inc.
Click the Halt toolbar button or issue the Debug > Run > Halt command to
stop the program execution. Reset the program by selecting Debug > Run >
Reset.
2.10 Debugging Tut877
Any of the following could be preventing the Tut877 program from working:
The A/D converter value is not being properly written to PORTC (LEDs)
The A/D converter is not on or has not been set to convert
A typo in the source code is causing the program to function improperly
To explore the first possibility, you will set a breakpoint at the line of the file
that writes the value of A/D result to PORTC. Highlight or place the cursor on
the following line of code from tut877.asm:
movf ADRESH,W ;Write A/D result to PORTC
Click on the right mouse button to access a shortcut menu. Select Break
Point(s)from the shortcut menu as shown in Figure 2.13. This line will now be
marked as a breakpoint. To change the colors that mark a breakpoint, select
Options > Environment Setup and click the Colors tab.
Figure 2.13: Set Breakpoint
8/3/2019 51184d_MPLAB_ICD
41/104
2000 Microchip Technology Inc. DS51184D-page 35
Tutorial PIC16F877
Click the Run toolbar button or issue the Debug > Run > Run command to run
the program once again in real-time mode.
A breakpoint will stop a programs execution when the program executes the
line marked as a breakpoint. However, our sample program is not halting.
Therefore, halt it yourself now by clicking the Halt toolbar button or issuing the
Debug > Run > Haltcommand.
Look at the source code (tut877.asm) window and notice where the
program halted. Our sample program halted on one of the two lines in the
Wait routine as shown in Figure 2.14. Based on the halt location and the fact
that the program never reaches the breakpoint, we conclude that the problem
is in the A/D conversionthe A/D flag for conversion complete is not being
set.
Figure 2.14: Program Halted
A/D conversion initialization and setup occurs at the beginning of the program.
To check out this code, first reset the program by selecting Debug > Run >
Reset. The first instruction after Start should be highlighted.
8/3/2019 51184d_MPLAB_ICD
42/104
MPLAB ICD Users Guide
DS51184D-page 36
2000 Microchip Technology Inc.
Open a new watch window so you can watch the A/D register values change
as the program executes. Select Window > Watch Windows > New Watch
Window. The Add Watch Symbol dialog will open, with the Watch_1 newwatch window behind it. Add the symbols ADCON0 and ADCON1 as shown
in Figure 2.15.
Figure 2.15: Adding Watch Symbols
Click Close when finished. The selected symbols should now be visible in the
watch window as shown in Figure 2.16.
Figure 2.16: Watch Window
In the MPLAB ICD dialog, set the upload options to Minimum & Watch
Windows. Single stepping and halting may be slower now, but this setting
allows us to see the Watch windows for debugging. Close or minimize the
MPLAB ICD Options dialog.
In the tut877.asm source code, set a breakpoint at the second instruction
after Start. Again, highlight or place the cursor on the following line of code
from tut877.asm:
clrf PORTC ;Clear PORTC
Click on the right mouse button to access a shortcut menu. Select Break
Point(s)from the shortcut menu. This line will now be marked as a breakpoint.
8/3/2019 51184d_MPLAB_ICD
43/104
2000 Microchip Technology Inc. DS51184D-page 37
Tutorial PIC16F877
Finally, click the Run toolbar button or issue the Debug > Run > Run
command to run the program in real-time mode.
This time the program will stop after it executes the breakpoint line of code,
and the instruction after the breakpoint will be highlighted as shown in
Figure 2.17.
Figure 2.17: Program Halted After Break
Now single step by clicking on the Step toolbar button or issuing the Debug >
Run > Stepcommand. Single step twice and then examine the values of the
registers ADCON0 and ADCON1 in the Watch window. You should notice that
ADCON0 has a value of 40 hex as shown in Figure 2.18.
8/3/2019 51184d_MPLAB_ICD
44/104
MPLAB ICD Users Guide
DS51184D-page 38
2000 Microchip Technology Inc.
Figure 2.18: Updated Watch Window
This corresponds to the binary value designated in the program, but is this
value correct? On examining the PIC16F87X Data Sheet (DS30292) section
on A/D, you will see that the last bit should be a one, not a zero, to turn the
A/D module on.
To fix this bug, change:
movlw B'01000000' ;Fosc/8, A/D enabled
to
movlw B'01000001' ;Fosc/8, A/D enabled
Select File > Save to save your changes and select Project > Make Project to
rebuild the project.
A message will tell you the program has been rebuilt and you must reprogram
the ICD in order for your changes to take effect. Click the Program button in
the MPLAB ICD dialog to reprogram the ICD to reflect your change.
When the MPLAB ICD dialogs Status box indicates that it is waiting for your
next command, you are ready to run your program again.
Click the Run toolbar button or issue the Debug > Run > Runcommand to run
the program in real-time mode. Some of the LEDs should now be lit. Turn the
potentiometer (RA0) to change the value displayed on the LEDs.
The source code in this tutorial contained only one bug. However, real code
may have more. Using the MPLAB ICD and MPLAB IDE debugging functions,
you can successfully find and fix the bugs in your code.
8/3/2019 51184d_MPLAB_ICD
45/104
2000 Microchip Technology Inc. DS51184D-page 39
Tutorial PIC16F877
2.11 Tut877 Main Routine
The main routine of tut877.asm (Figure 2.19) begins by configuringPORTC, the A/D module and Timer0. It then waits for a Timer0 overflow to
start the A/D conversion of the value from the potentiometer. When the
conversion is complete, the value is displayed on the LEDs, and the program
loops back to wait for another Timer0 overflow to start another A/D
conversion.
For more information on A/D module operation and a list of related application
notes, refer to the PICmicro Mid-Range MCU Family Reference Manual
(DS33023).
Figure 2.19: Program Flow Chart
Start
Configure PORTC
as All Outputs
Configure A/D
left justify, FOSC/8 clock
1 analog channel
Configure Timer0
Prescaler assigned to Timer0
1:256 prescale
Timer0 Overflow?
No
Yes
Start A/D Conversion
ConversionNo
Yes
Complete?
Write A/D Result to PORTC
8/3/2019 51184d_MPLAB_ICD
46/104
MPLAB ICD Users Guide
DS51184D-page 40
2000 Microchip Technology Inc.
2.12 Tut877 Corrected Source Code
This is a functional version of tut877.asm.
;**********************************************************
;* TUT877.ASM
;**********************************************************
;* Microchip Technology Incorporated
;* 16 December 1998
;* Assembled with MPASM V2.20
;**********************************************************
;* This program configures the A/D Module to convert on
;* A/D channel 0 (the potentiometer) and display the
;* results on the LEDS on PORTC. Make sure that the DIP
;* switch SW3 has all switches in the ON position.
;**********************************************************
list p=16f877
; Include file, change directory if needed
include
; Start at the reset vector
org 0x000
nop
Start
banksel PORTC
clrf PORTC ;Clear PORTC
movlw B'01000001' ;Fosc/8, A/D enabled
movwf ADCON0
banksel OPTION_REG
movlw B'10000111' ;TMR0 prescaler, 1:256
movwf OPTION_REG
clrf TRISC ;PORTC all outputs
movlw B'00001110' ;Left justify,1 analog channel
movwf ADCON1 ;VDD and VSS references
banksel PORTC
Main
btfss INTCON,T0IF ;Wait for Timer0 to timeout
goto Main
bcf INTCON,T0IF
bsf ADCON0,GO ;Start A/D conversion
Wait
btfss PIR1,ADIF ;Wait for conversion to complete
goto Wait
8/3/2019 51184d_MPLAB_ICD
47/104
2000 Microchip Technology Inc. DS51184D-page 41
Tutorial PIC16F877
movf ADRESH,W ;Write A/D result to PORTC
movwf PORTC ;LEDs
clrf PORTC
WaitPush
btfss PORTB,0
goto WaitPush
movwf PORTC
goto Main ;Do it again
end
8/3/2019 51184d_MPLAB_ICD
48/104
MPLAB ICD Users Guide
DS51184D-page 42
2000 Microchip Technology Inc.
NOTES:
8/3/2019 51184d_MPLAB_ICD
49/104
2000 Microchip Technology Inc. DS51184D-page 43
MPLAB ICD USERS GUIDE
Chapter 3. General Setup
3.1 Introduction
This chapter describes how to get the hardware and software for the
MPLAB ICD up and working.
3.2 Highlights
Topics covered in this chapter:
Running MPLAB ICD
Setting Up the Development Mode
Setting Up the MPLAB ICD Dialog
Setting Up the ICD Options Dialog
Using MPLAB Projects
3.3 Running MPLAB IDE
After installing MPLAB IDE, invoke it by executing the f ile mplab.exe.
For more information on installing and using MPLAB IDE, refer to the
MPLAB IDE Users Guide (DS51025) and the included file readme.lab in
the MPLAB IDE install directory.
Figure 3.1: MPLAB IDE
8/3/2019 51184d_MPLAB_ICD
50/104
MPLAB ICD Users Guide
DS51184D-page 44
2000 Microchip Technology Inc.
3.4 Setting Up the Development Mode
Use the Development Mode dialog to select MPLAB ICD for use with theMPLAB IDE software.
1. Select Options > Development Mode. Select the MPLAB ICD Debugger
development mode, and select the processor you are going to use. Click
OK.
Below the Processor is a brief description of any limitations that exist for
this processor on the MPLAB ICD. A more detailed description of limita-
tions may be viewed by clicking on Details.
2. The MPLAB ICD dialog will appear. You will use this dialog to set up the
debugger.
3. If MPLAB IDE cannot find the MPLAB ICD, check your hardware connec-
tions (Section 1.7) and then go to step 1. If you still cannot connect, see
the next section or troubleshooting chapter (Chapter 5).
Figure 3.2: Development Mode Dialog Box
You may also access the Development Mode dialog from the Edit Project
dialog by clicking Change next to the Development Mode item. See Chapter 2
for more information on setting up projects.
Note: You can move the MPLAB ICD dialog, but do not close it.
8/3/2019 51184d_MPLAB_ICD
51/104
2000 Microchip Technology Inc. DS51184D-page 45
General Setup
3.5 Setting Up the MPLAB ICD Dialog
The MPLAB ICD dialog is always open when the ICD is enabled. You canminimize or move the MPLAB ICD dialog, but do not close it. Closing this
dialog disables the debugger. You must then select Options > Development
Mode, select None (Editor Only), and click Apply. Then, select MPLAB ICD,
and click OK to reenable the debugger.
Figure 3.3: MPLAB ICD Dialog
The MPLAB ICD dialog has the following settings and buttons.
Table 3.1: MPLAB ICD Dialog
Item Options
Status The Status bar displays the executed MPLAB ICD
function and the status.
COM Port Select th e CO M port (COM1, CO M2, COM3 or
COM4) for MPLAB ICD communications.
Baud Rate Select the COM port baud rate for MPLAB ICDcommunications.
Upload Options The options for the amount of data uploaded are:
Minimum (FSR, W, Status, PCLATH) (Very Fast)
SFRs only (Fast)
Minimum and Watch windows (Pretty Fast)
All Registers (Slow)
If you are using breakpoints and single step, you
can upload selected data to improve speed. The
first selection has less than a second delay, where
as the last selection will have a delay of
approximately 2 seconds. Data will be uploaded on
a single step, a breakpoint or a halt.
8/3/2019 51184d_MPLAB_ICD
52/104
MPLAB ICD Users Guide
DS51184D-page 46
2000 Microchip Technology Inc.
Operating Frequency
Range
Select the operation frequency range of the
MPLAB ICD. Options are:
32 kHz 500 kHz
500 kHz 2 MHz
2 MHz 10 MHz
10 MHz 20 MHz
Note: If you are using a version of MPLAB IDE previous to 5.20, you need
to change development modes to save the above settings. Select
Options > Development Mode, select None (Editor Only), and click
Apply. Then select MPLAB ICD Debugger, and click OK.
Reconnect If you had to change the COM port or baud rate,click Reconnect to reestablish communications
using the new values.
Program Programs the device.
Options Opens the ICD Options dialog (see next section).
Table 3.1: MPLAB ICD Dialog (Continued)
Item Options
8/3/2019 51184d_MPLAB_ICD
53/104
2000 Microchip Technology Inc. DS51184D-page 47
General Setup
3.6 Setting Up the ICD Options Dialog
The ICD Options dialog is accessed by clicking Options in the MPLAB ICDdialog. The ICD Options dialog can be closed or minimized without disabling
the ICD.
The ICD Options dialog (Figure 3.4) has all the programming and setup
functions for the MPLAB ICD. These functions include basic programmer
functions like blank check, read, program, verify, erase, and the debugger
functionality.
Figure 3.4: MPLAB ICD Options Dialog
8/3/2019 51184d_MPLAB_ICD
54/104
MPLAB ICD Users Guide
DS51184D-page 48
2000 Microchip Technology Inc.
3.6.1 Configuration Bits and Device Selection
This section of the dialog allows you to set the various configuration bits onthe PIC16F87X processors. To select, click on the arrow to see the list of
choices, and then select the correct item.
3.6.2 IDs and Checksum
Table 3.2: Configuration Bits and Device Selection Options
Item Options
Device This box shows the processor you sele cted in th e
Development Mode dialog. If you change the device
here, any open MPLAB IDE projects will close and
program memory, configuration bits, and IDs will be
cleared.
Oscillator RC, LP, XT or HS
Watchdog Timer Select On/Enable or Off/Disable. Usually should bedisabled for debugging.
Power Up Timer Select On/Enable or Off/Disable. Usually should be
disabled for debugging.
Brown Out Detect Select On/Enable or Off/Disable. Must be disabled
for debugging.
Low Voltage Program Select low-voltage programming function or use
RB3 as digital I/O and use HV on MCLR for pro-
gramming. Low-voltage programming must be dis-
abled for debugging.
Code Protect Data EE Select On/Enable or Off/Disable. Must be disabled
for debugging.
Flash Memory Write Select whether to allow unprotected program mem-
ory to be written by EECON control. Usually should
be disabled for debugging.
Code Protect Select the desired range. Must be disabled for
debugging.
Table 3.3: IDs and Checksum Selection Options
Item Options
Checksum Displays the checksum for the data.
ID Code Displays the ID code.
Use Checksum as ID To use the checksum as the ID, select the check-
box.
8/3/2019 51184d_MPLAB_ICD
55/104
2000 Microchip Technology Inc. DS51184D-page 49
General Setup
3.6.3 Voltages
3.6.4 Program Options
Select or clear the checkbox next to the item to select or deselect the memory
areas for the programmer functions. For example, if you want to read program
memory only, select Program Memory and clear the checkboxes for the other
memory types.
Table 3.4: Voltage Selection Options
Item Options
VDD Displays the current value of the VDD voltage.
MPLAB ICD develops its needed VPP 13V from
the target boards VDD through use of a charge
pump.
VPP Displays the current value of the VPP voltage.
Update Allows you to check the current value o f the VDD
and VPP voltages on the target application.
Table 3.5: Program Selection Options
Item Options
Start Address,
End Address
The starting and ending address range in program
memory for programming, reading or verification.
Note: The address range does not apply to the
Erase function. The Erase function will
erase all data on the PIC16F87X.The default program address range is set to the
maximum program memory available based on the
device you selected. To identify file register and pro-
gram memory locations that the ICD uses in the tar-
get device, see Section 1.4.
Configuration Bits Program the configuration bits. You can set the con-
figuration bits in the top portion of the ICD Options
dialog.
ID Locations Program the ID locations. You can set the ID loca-
tions in the IDs and Checksum area of the ICD
Options dialog.
EEPROM Data For devices with data EEPROM, program the datamemory from the data in the EEPROM Memory
window.
Erase All before
Program
If this option is checked and you click Program, all
program memory will be erased before program-
ming begins. This results in faster programming
times. Do not use this option with VDD voltages
below 4.5.
8/3/2019 51184d_MPLAB_ICD
56/104
MPLAB ICD Users Guide
DS51184D-page 50
2000 Microchip Technology Inc.
3.6.5 Function Buttons
Click the Function buttons to perform the assigned function on the
PIC16F87X in the MPLAB ICD Header. If you have specified an address
range in the Program Options section, the assigned function will be performed
on the specified memory range and type only (except for the erase function).
Enable Debug Mode Select this option to program debug code into a
device. The debugging operations will be enabled
each time you click Program.
If you are only using MPLAB ICD to program a part,
clear the Enable Debug Mode check box. The
debug code will not be downloaded to program
memory and MPLAB ICD will not be enabled for
debug operations.
Table 3.5: Program Selection Options (Continued)
Item Options
Table 3.6: Function Button Selection Options
Item Options
Blank Checks to see if device is blank.
Read Reads memory areas specified under Program
Options: program memory, configuration bits, ID
locations, and/or EEPROM data.
Program Programs memory areas specified under Program
Options: program memory, configuration bits, ID
locations, and/or EEPROM data. Also downloads
debug code in program memory if Enabled Debug
Mode is checked.
Verify Verifies programming of memory areas specified
under Program Options: program memory, configu-
ration bits, ID locations, and/or EEPROM data.
Erase Erases all data o n the PIC16F87X including mem-
ory, ID, and configuration bits. Do not use this
option with VDD voltages below 4.5.
Download Operating
System
Downloads an updated version of the MPLAB ICD
operating system (firmware) to the MPLAB ICDs
FLASH processor. See also Section 4.8.
Self Test Performs a self-test on the MPLAB ICD hardware.
Note: If there is no PIC16F87X on the MPLAB
ICD Header or target/Demo Board or if the
device is not programmed with debug
code, the self test will indicate that the
debug module doesnt exist.
8/3/2019 51184d_MPLAB_ICD
57/104
2000 Microchip Technology Inc. DS51184D-page 51
General Setup
3.7 Using MPLAB ProjectsMPLAB IDE is the host software for the MPLAB ICD and the MPLAB SIM
simulator. It functions as a sophisticated debugging tool, providing access to
RAM, ROM, EEPROM, and a variety of other debug functions.
3.7.1 MPLAB IDE Project Features
Developing and debugging code in the MPLAB IDE environment is based on
projects. Although emulation can be performed without having a project open,
projects have the following advantages:
Single or multiple source files can be easily built and maintained.
Symbolic debugging is available.
The debugging environment can be saved for later use.
Some of the information that is retained with a project is:
Development mode and processor
Source files associated with the project
Name of the final PICmicro MCU executable file
Open windows and their sizes and positions
Named break settings
Configuration bit settings
3.7.2 Creating a Project
Select Project > New Project to create a project and open the Edit Project
dialog. The project will contain information about your source, object, a nd
other files, as well as a variety of important project settings.
Def.Addr Restores the Start and End addresses to the
defaults for the device.
End addresses with Debug Mode enabled:
PIC16F870/871/872:0x6DF
PIC16F873/874:0xEDF
PIC16F876/877:0x1EFF
End address with Debug Mode disabled:
PIC16F870/871/872:0x7FF
PIC16F873:0xFFF
PIC16F876/877:0x1FFF
Table 3.6: Function Button Selection Options (Continued)
Item Options
Note: If you do not put your source files into a project, MPLAB IDE cannot
debug properly.
8/3/2019 51184d_MPLAB_ICD
58/104
MPLAB ICD Users Guide
DS51184D-page 52
2000 Microchip Technology Inc.
3.7.3 Saving a Project
To save your current project to retain the values for later use or to use as abackup or default as you continue with your debugging, click OK in the Edit
Project dialog. Then select Project > Save Projectto save your project.
Development Mode
The selected development mode is retained with the project information. To
change the development mode for a project, follow these steps:
Open the project. The previously used development mode will be
selected.
Change the development mode by selecting Options > Development
Modeto access the Development Mode dialog. Select the development
mode and click OK.
Select Project > Save Project to save the project.
For more information on creating and using projects, refer to the MPLAB IDE
Users Guide(DS51025).
8/3/2019 51184d_MPLAB_ICD
59/104
2000 Microchip Technology Inc. DS51184D-page 53
MPLAB ICD USERS GUIDE
Chapter 4. Basic Functions
4.1 Introduction
This chapter discusses the basic operations of MPLAB ICD and MPLAB IDE
debugging functions of the In-Circuit Debugger. For more information on
general debugging features, refer to the MPLAB IDE Users Guide (DS51025).
4.2 Highlights
Topics covered in this chapter:
MPLAB ICD Operations Program Execution
Breakpoints
Modifying Functions
Loading a Hex File for Debugging
Upgrading the MPLAB ICD Operating System (Firmware)
4.3 MPLAB ICD Operations
The MPLAB ICD is a programmer for the PIC16F87X family, as well as an in-
circuit debugger. It programs hex files into the PIC16F87X and offers basic
debugging features like real-time code execution, stepping, and breakpoints.Its debug feature is built inside the PIC16F87X and activated by programming
the Debug Code into the target processor. It has limited functions when
compared to a full-featured in-circuit emulator (Section 1.4), but provides cost-
effective functions to debug and program applications for a PIC16F87X.
To enable in-circuit debugging, the Debug Code (residing in the
microcontroller in the MPLAB ICD Module) is programmed into the target
PIC16F87X. The code is an MPASM module that will be programmed into the
PIC16F87X automatically by MPLAB IDE. This code will reside at the end of
program memory. For example, it will reside in 0x1F00 to 0x1FFF of the
PIC16F877 processor (see Section 1.4).
8/3/2019 51184d_MPLAB_ICD
60/104
MPLAB ICD Users Guide
DS51184D-page 54
2000 Microchip Technology Inc.
4.4 Program Execution
The MPLAB ICD executes in real-time mode or in step mode.
Real-time execution occurs when the PIC16F87X in the MPLAB ICD
Header or Demo Board/target board is put in the MPLAB IDE s Run
mode.
Step mode execution can be accessed after the processor is halted.
4.4.1 Real-Time Execution
When the MPLAB ICD is run in real time, instructions execute just as the
processor would without the debugger. The PIC16F87X executes in real time
until a breakpoint halts the debugger or until the HALT function is manually
executed.
To execute in real time, click the Run toolbar button or issue the Debug > Run
> Runcommand. The Debug toolbar provides Run, Halt, and Step buttons for
controlling the debugger. While in the run mode, register displays on the
screen will not update.
4.4.2 Step-Mode Execution
Step-Mode Execution occurs when you single step the processor with the
Debug > Run > Step command. Step-mode execution allows you to step
through the code one instruction at a time, watch the program flow, and see
the register contents at each instruction (as set in the dialog box).
Debug > Run > Animate automatically single steps the processor until you
halt it. To view the changing registers in the Special Function Register window
or the Watch windows, use Animate. Animate runs slower than the Run
function.
Note: With the design of the MPLAB ICD, it is IMPOSSIBLE to single stepthrough an interrupt. Due to hardware restrictions, it is IMPOSSI-
BLE to jump to the interrupt vector memory location while doing a
single step function.
8/3/2019 51184d_MPLAB_ICD
61/104
2000 Microchip Technology Inc. DS51184D-page 55
Basic Functions
4.5 Breakpoints
A breakpoint is a state where the processor halts after a certain condition ismet. The MPLAB ICD provides the followings ways to set a breakpoint:
Break on Address Match
Break on User Halt
4.5.1 Break on Address Match
The Debug function of the PIC16F87X allows one breakpoint to be set. This
breakpoint can be at any program memory address location. The processor
breaks after the instruction is executed. For example, if a breakpoint is set at
address 005Ah, the processor breaks after executing the instruction at
address 005Ah.
To set a breakpoint, select Debug > Break Settings. You can also set a
breakpoint by selecting the source code address in Program Memory or
selecting the line of code in the source code window, clicking the right mouse
button to access a shortcut menu, and selecting Break Point(s) from the
shortcut menu.
4.5.2 Break on User Halt
The PIC16F87X executes until you click the Halt button or select Debug >
Run > Halt.
4.6 Modifying Functions
If you need to modify the program being debugged, simply assemble a new
hex file and download it. You can also use the Modify dialog to edit program
memory before downloading it into the PIC16F87X with the Program button.
If you do this, the object code generated by your source code will not match
the code in the PIC16F87X.
You can use Window > Modify to change a register, words of programmemory or data in the EEPROM area. Select Window > File Registersand
Window > Special Function Registersto view internal data registers.
Note: MPLAB ICD only supports one breakpoint. If you set multiple
breakpoints, they will be shown as enabled in the Breakpoint Set-
tings Window, but only the last breakpoint set will actually be
enabled, whether it was set through the Breakpoint Settings or by
using the right mouse button.
8/3/2019 51184d_MPLAB_ICD
62/104
MPLAB ICD Users Guide
DS51184D-page 56
2000 Microchip Technology Inc.
4.7 Loading a Hex File for Debugging
If you have a hex code file that you would like to program into your device fordebugging (i.e., you have used a tool other than the MPLAB IDE to generate
your hex code), you may load the hex code to the MPLAB IDE using the File >
Import > Import to Memorycommand. To identify file register and program
memory locations that ICD uses in the target device, see Section 1.4. Your
code should be limited accordingly.
Once the hex file is imported, you can use the Windows menu to open the
following windows:
Program Memory
Special File Registers
File R egisters
EEPROM Memory
4.8 Upgrading the MPLAB ICD Operating System
(Firmware)
MPLAB ICD now supports downloadable firmware starting with Firmware
v2.02 and MPLAB IDE v5.00.
After upgrading to the PIC16LF876, future downloads can be performed
through the MPLAB ICD software. If operation below 4.5V is not required inthe target application, a PIC16F876 can be substituted for the PIC16LF876.
See engineering tech. note ETN-21D on the our web site
(http:\\www.microchip.com) for more information on upgrading.
Operating System Downloads After System Upgrade
To perform a download of a new MPLAB ICD operating system after system
upgrade, do the following:
From the MPLAB ICD dialog, click Options to open the ICD Options
dialog.
In the ICD Options dialog, click Download ICD Operating System.
The Open Existing File dialog will appear.
Select the version of the operating system (firmware) you wish to down-
load from the list. The file name format is icd*.obj, where * is the operat-
ing system version number. Click OK.
The selected operating system file will download to the MPLAB ICD.
Note: If you need to specify values for the EEPROM data memory in your
source code, use a starting address of 0x2100.
8/3/2019 51184d_MPLAB_ICD
63/104
2000 Microchip Technology Inc. DS51184D-page 57
MPLAB ICD USERS GUIDE
Chapter 5. Troubleshooting
5.1 Introduction
This section describes some common problems associated with running the
MPLAB ICD and the steps to follow to resolve those problems.
5.2 Highlights
Topic covered in this chapter:
Common Problems
5.3 Common Problems
Communications cannot be established with the MPLAB ICD.
If you cannot establish communications with the MPLAB ICD, follow these
steps:
1. Make sure there is power to the MPLAB ICD Demo Board/target appli-
cation. MPLAB ICD is powered by the MPLAB ICD Demo Board/target
application. Also, if you are using the MPLAB ICD Demo Board, make
sure the power supply has the correct rating (9.0V, 0.75A).
2. Check that the MPLAB ICD Header is plugged into the MPLAB ICD
Demo Board/target application correctly; e.g., all MPLAB ICD Header
pins are plugged into the socket and the MPLAB ICD Header is correctlyoriented. Also, make sure you are using the correct stand-off if you are
using the MPLAB ICD Demo Board.
3. Check that the PIC16F87X is plugged into the MPLAB ICD Header cor-
rectly; e.g., all pins are plugged into the socket and the PIC16F87X is
correctly oriented.
4. Check that the connection between the MPLAB ICD and the host com-
puter, via the RS-232 cable, is secure.
5. Check that the connection between the MPLAB ICD Header and
MPLAB ICD Module, via the 9-inch modular cable, is secure.
6. Check the settings in the MPLAB ICD dialog. Make sure you selected the
correct PICmicro MCU, COM port, and baud rate for your application.
The MPLAB IDE attempts to establish communication with the MPLAB ICD
upon enabling the debugger. If communication cannot be established, no
programming or debugging can occur. An error message appears if the
attempt to establish communication fails. If a communication attempt fails, try
again after correcting the problem or cancel.
8/3/2019 51184d_MPLAB_ICD
64/104
MPLAB ICD Users Guide
DS51184D-page 58
2000 Microchip Technology Inc.
SOLUTIONS:
Make sure the power supply is connected and the LED on the
MPLAB ICD Module is on and not blinking. If the LED on the MPLAB
ICD Module is blinking, reset the MPLAB ICD Module by cycling the
power to the application on and off. Then reselect the COM port for
the MPLAB ICD in the MPLAB ICD dialog box. The LED should stop
blinking.
Try connecting the MPLAB ICD Module to a different serial port. If your
PC has a 25-pin serial port, you will need a 25-pin to 9-pin serial port
adapter.
Make sure that a COM port is properly set up exclusively for use by the
debugger. Check the resources to ensure they are operating properly
and that there are no conflicts with other devices. This commonly hap-
pens when you have a modem or other serial device that is improperlyconfigured. Consult your Windows manual or other reference literature.
You can try removing, reconfiguring or disabling the conflicting device,
but do so only if you are familiar with those procedures. See the steps
below for Windows 3.1 or Windows 95.
Some system errors are caused by driver and hardware incompatibility.
See the steps below for Windows 95.
If you have a COM port but the MPLAB IDE will not let you select it (the
option is grayed out) you may be able to assign the port manually by
editing the mplab.ini file. Typically, this occurs if you have a gap in
your COM port list (i.e., you have a COM1, COM2, and a COM4, but no
COM3). In this case you may be able to fix it by opening mplab.ini
(use FIND to locate this file) and editing the section called [MPLAB ICD]so that the setting CommPort=1 is set to the port you want selected.
This is just a work-around to a deeper problem in which Windows is
incorrectly reporting port availability through the 16-bit driver.
You must use the Microsoft Windows communications driver that is
native to the version of Windows that you use. If you use Windows 3.10,
look for the file COMM.DRV in your \WINDOWS\SYSTEM directory.
That file MUST have a time of 3:10a. The time denotes the version. If
you are using Windows for Workgroups, look for the same file as above,
but the time stamp on that file should be 3:11a. If these files differ, you
may need to re-install windows or install that file from another source.
This problem is not likely to occur in Windows 95.
Make sure you are not using a third party communications driver. Openyour system.ini file and look for the line in the [OPTIONS] section
that reads
COMM.DRV=COMM.DRV
If this line reads differently you are using a different communications
driver.
8/3/2019 51184d_MPLAB_ICD
65/104
2000 Microchip Technology Inc. DS51184D-page 59
Troubleshooting
Windows 3.1:
A serial mouse will use a COM port, as will an external modem. An internal
modem has its own COM port, so if you have a second COM port on your
PC, set it so it wont conflict with either the mouse or the modem.
Windows 95:
Windows 95 requires special attention to setting up COM ports. If you sus-
pect a driver - hardware incompatibility, try changing Flow Control to Hard-
ware and/or turning off the FIFO for the serial port. In Windows 95 this is
done in the Control Panel. Click the System Icon. Next, click the Device
Manager tab, and click Port Settings. If necessary, expand the Ports
selection by clicking the + sign next to it. Double-click the I/O port that the
MPLAB ICD is connected to. This is where you can set flow control to Hard-
ware. To turn off the FIFO, click the Advanced button, deselect the Use
FIFO box, and click OK.If communications still cannot be established, contact Microchip Customer
Support as described in General Information.
The MPLAB ICD Module returns a communications error on Reset,
Single Step, Halt or Run.
When using the MPLAB ICD Demo