Four things will happen when a debug session has been initiated:
- The project will build
- MPLAB® X IDE will connect to the selected debug tool and download the built image
- The Debug Icons will appear on the Toolbar
- The application in the PIC® MCU will run according to the debug startup option
An illustration of MPLAB X IDE's user interface immediately after a debug session has been started. This example shows the operation when the Debug Startup option is set to MAIN.
When the program being debugged is not running, the location of the Program Counter is shown on the screen with a green line.
When a debug session has been started a new toolbar will appear.
The Debug icon toolbar contains 9 buttons which allow for program control and ease of debugging.
Looking at Global Variables and SFRs
Global Variables (variable with fixed addresses and scope) can most easily be view by the Watches Window. When the Watches Window is opened the user can add a list of variables to "watch". Each time the debug session pauses the program the value of the items being watched is updated. PIC Special Function Registers SFRs work just like Static variables and can be added to any Watches Window
To open the Watches window select Window->Debugging->Watches from the toolbar. The Watches window will appear as a tab in the lower right hand corner ( the Output Window). Right clicking anywhere in the Watches window will allow you to add or delete Watches.
Observing Local Variables
Local Variables (variables who exist only on the stack) can be view by the Variables Window. When the Variables Window is opened the variables who are 'local' to the active function are displayed. The user has the choice of selecting all local variables or just those 'near' the program counter.
To open the Variblees window select Window->Debugging->Variables from the toolbar. Just like the Watches window the Variables Window will appear as a tab in the lower right hand corner ( the Output Window). The three icons on the left hand side of the Variables window allow you to modify the range of the local variables displayed or to add Watches to the Variables window.
Watches can be added to the Variables Window. This allows one window to display Global variables, SFRs, and Local Variables. Some user's find it easier to debug with only one window show data values.
Finishing the Debug Session
When the debugging has been complete and you wish to create an image which can run in the PIC MCU without the need of a programmer/debugger two step are needed. The first step is to end the debug session. Once the debug session has been ended you will need to create the production ready imageTo end the debug session click on the "Finish Debug Session" icon