This lab steps through several procedures to teach the following:
- How to select the appropriate debugger/programmer
- How to download firmware (including the debug executive) into a PIC® MCU
- How debugging techniques on hardware compare to simulator debugging
- How to directly control SFRs and alter program variables on a PIC® MCU during operation
- How to remove the debug executive from a project and create a customer deliverable HEX which runs without a debugger/programmer
Hardware Tools (Optional)
|Tool|| About|| Purchase|
| Windows|| Linux|| Mac OSX|
Integrated Development Environment
Visual, Interactive Simulator Demo
The contents of the following zip file need to be placed in this directory:
| Windows|| Linux|| Mac OSX|
Project and Source Files
Close any open projects by right clicking on the project name and selecting “Close”Click the Open Project icon
Browse to C:\MTT\TLS0101\Lab03.X and select Open Project
Double click on Lab03.c under Source Files to open the C file in the editor window
Notice the variable delayVal. This variable is defined with an initial value of decimal 10. This variable, delayVal, is used to control the execution time of the delay() function. We will alter this variable in the latter part of Lab03.
Verify the Hardware Tool
If you wish to run this lab on hardware this is where you need to select your debugger/programmer.
Verify the Hardware Tool assigned to this project is the Proteus VSM Viewer (if you don't have hardware) or REAL ICE/ICD3 (if you have hardware).
Right click on Lab03 from the project list
Under the Conf:[default] section ensure the Proteus VSM Viewer or REAL ICE / ICD3 has been selected.Click OK
Debug ProjectClick Debug Project icon to build a debug image and download it to the VSM Viewer / REAL ICE / ICD3. You will notice the project builds, and then starts the VSM View or programs the Explorer16 processor through the REAL ICE / ICD3
Above we see the editor window showing Lab03.c after simulation ready to continue at the beginning of main().
Set breakpoints on the two LATA assignment statements within the while(1) loop
Click on the left margin of lines of code containing LATA=0xAA; and LATA = 0x55;
You should notice the green bar on the line with the breakpoint set
Skid on breakpoint. When running on hardware, the PIC MCU may execute the instruction at the breakpoint and THEN stop. Under software simulation, the CPU halts BEFORE the instruction is executed. Stopping after executing the breakpoint instruction is referred to as a Skid.
If the green bar is located below the red bar you are observing a “skid”. The red bar indicates where the break point was set and the green bar is where the processor stopped. Depending on the particular version of MPLAB® X IDE and the debugger, you will need to take this skid onto consideration when debugging on hardware.
Operation of ProgramClick the Continue icon to move the program to the next breakpoint. Each time the PIC MCU stops at a break point, observe the LEDs on the VSM implementation of the Explorer16 change. Repeat this step several times until you are familiar with the operation of this program.
Remove Breakpoints from the Code
From the Window menu select Debugging, then Breakpoints
Right click in the Breakpoint Window and select Delete All
Do you see the LEDs blink or do they appear to stay on constantly? At question is the speed of the processor. The clock rate of the PIC MCU is such that the delay() function executes so quickly the human eye cannot easily notice the toggling of the LEDs. To adjust the speed we will manually adjust the variable delayVal using MPLAB X IDE.Pause the Simulation by clicking the Pause icon
Adding Variables to the Watches Window
Open the Watch Window (if not already open) by selecting it from the Window menu. Watches from previous labs might show up (right-click and select Delete All)
Within the Watch Window right click and select New Watch…
Highlight the “Global Symbols” radial button
Select the variable delayVal from the menuClick “OK”
If LATA is not already in the Watch window repeat the above step to add this SFR to the list of data points to watch
You may notice delayVal is displayed with a value of “0x00AA” and not “10” as written in the source code. The Watch window will default to display values in HEX while the value in the code was decimal. To synchronize the value in the Watch window with what radix we coded we will change the display on the Watch Window
Changing the Radix of the Watches Window
Within the watch Window Right Click on ‘delayVal’
Move the mouse over Display Value As and select Decimal
Highlight the Value displayed for delayVal (in this case 10)
Change the number to 2048 then press Enter
To save the changes we need to enter the new delayVal into the source code
Change the line of coding reading delayVal = 10; to delayVal = 2048;
Before we rebuild and then run the code we will manually control the SFRs on the PIC MCU. Directly controlling the contents of SFRs can be very useful during the debugging process. For today’s lab we will manually alter the LATA SFR to allow a different pattern to be displayed on the LEDS.
In the Watch Window enter 0x003C
Notice an immediate change in SFR value as displayed on the LEDS