Datasheet

Emulator User’s Guide for MPLAB X IDE
DS52085A-page 40 2013 Microchip Technology Inc.
3.8.2 Debugging Details
Figure 3-14 illustrates the MPLAB REAL ICE in-circuit emulator system when it is ready
for debugging.
FIGURE 3-14: MPLAB
®
REAL ICE™ IN-CIRCUIT EMULATOR READY FOR
DEBUGGING
Typically, in order to find out if an application program will run correctly, a breakpoint is
set early in the program code. When a breakpoint is set from the user interface of
MPLAB IDE, the address of the breakpoint is stored in the special internal debug reg-
isters of the target device. Commands on PGC and PGD communicate directly to these
registers to set the breakpoint address.
Next, the Debug>Debug Project
function is usually selected in MPLAB IDE. The emu-
lator will then tell the debug executive to run. The target will start from the Reset vector
and execute until the Program Counter reaches the breakpoint address previously
stored in the internal debug registers.
After the instruction at the breakpoint address is executed, the in-circuit debug mech-
anism of the target device “fires” and transfers control to the debug executive (much
like an interrupt) and the user’s application is effectively halted. The emulator commu-
nicates with the debug executive via PGC and PGD, gets the breakpoint status
information and sends it back to MPLAB IDE. MPLAB IDE then sends a series of que-
ries to the emulator to get information about the target device, such as file register con-
tents and the state of the CPU. These queries are ultimately performed by the debug
executive.
The debug executive runs just like an application in program memory. It uses some
locations on the stack for its temporary variables. If the device does not run, for
whatever reason, such as no oscillator, a faulty power supply connection, shorts on the
target board, etc., then the debug executive cannot communicate to the MPLAB REAL
ICE in-circuit emulator and MPLAB IDE will issue an error message.
Another way to stop execution is to select Debug>Pause
. This toggles the PGC and
PGD lines so that the in-circuit debug mechanism of the target device switches execu-
tion from the user’s code in program memory to the debug executive. Again, the target
application program is effectively halted, and MPLAB IDE uses the emulator
communications with the debug executive to interrogate the state of the target device.
+5V
+12V
4.7 k
4.7 k
Internal Circuits
Program
Memory
File
Registers
Internal
Debug
Registers
VPP/MCLR
PGC
PGD
1
5
4
Executive
Debug
Area Used by
Target
be
Running
must
for Debug
Executive
to Function
Area
VDD
Hardware
Stack Shared
by Debug Exec
Debug Exec
Reserved
for Debug
Executive