Operaon
User Guide
© 2023 Microchip Technology Inc. and its subsidiaries
DS-50003529B - 45
Figure 4-6. MPLAB ICD 5 Ready to Begin Debugging - PIC MCU
To nd out whether an application program will run correctly, a breakpoint is typically set early in the
program code. When a breakpoint is set from the user interface of MPLAB X IDE, the address of the
breakpoint is stored in the special internal debug registers of the target device. If using ICSP only,
commands on PGC and PGD communicate directly to these registers to set the breakpoint address.
Next, the Debug > Debug Main Project function is usually selected in MPLAB X IDE. The debugger
instructs the debug executive to run the target application. The target starts from the Reset vector
and executes until the Program Counter reaches the breakpoint address that was stored previously
in the internal debug registers.
After the instruction at the breakpoint address is executed, the in-circuit debug mechanism of the
target device “res” and transfers the device’s program counter to the debug executive (like an
interrupt) and the user’s application is eectively halted. The debugger communicates with the
debug executive via PGC and PGD, gets the breakpoint status information, and sends it back to
MPLAB X IDE. MPLAB X IDE then sends a series of queries to the debugger to get information about
the target device, i.e., le register contents and the state of the CPU. These queries are performed by
the debug executive.
The debug executive runs like an application in program memory or special test memory. It uses
some locations on the stack for its temporary variables. If the device does not run, for whatever
reason (no oscillator, faulty power supply connection, shorts on the target board, etc.), then the
debug executive cannot communicate to the MPLAB ICD 5, and MPLAB X IDE will issue an error
message.
Another way to halt the target is to select Debug > Pause. This toggles the PGC and PGD lines
so that the in-circuit debug mechanism of the target device switches the Program Counter from
the user’s code in program memory to the debug executive. The target application program is
eectively halted, and MPLAB X IDE uses the debugger communications with the debug executive to
interrogate the state of the target device.
4.4.2.4 Requirements for Debugging
To debug (set breakpoints, see registers, etc.) with the MPLAB ICD 5 In-Circuit Debugger system,
there are critical elements that must be working correctly:
• The debugger must be powered, must be connected to a computer, and must be communicating
with the MPLAB X IDE software.