User manual

Theory of Operation
© 2008 Microchip Technology Inc. DS51766A-page 19
Configuration>Debug.
When Debugger>Program
is selected, the application code is programmed into
the device’s memory via the ICSP protocol as described above.
A small “debug executive” program is loaded into the high area of program
memory of the target device. Since the debug executive must reside in program
memory, the application program must not use this reserved space. Some devices
have special memory areas dedicated to the debug executive. Check your device
data sheet for details.
Special “in-circuit debug” registers in the target device are enabled. These allow
the debug executive to be activated by the debugger.
The target device is held in Reset by keeping the V
PP/MCLR line low.
2.7.2 Debugging Details
Figure 2-7 illustrates the MPLAB ICD 3 in-circuit debugger system when it is ready for
debugging.
FIGURE 2-7: MPLAB
®
ICD 3 IN-CIRCUIT DEBUGGER 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
registers of the target device. Commands on PGC and PGD communicate directly to
these registers to set the breakpoint address.
Next, the Debugger>Run
function or the Run icon (forward arrow) is usually pressed
from MPLAB IDE. The debugger 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
mechanism of the target device “fires” and transfers the device’s Program Counter to
the debug executive (much like an interrupt) and the user’s application is effectively
halted. The debugger communicates 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 queries to the debugger to get information about the target device,
such as file register contents and the state of the CPU. These queries are ultimately
performed by the debug executive.
+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