Debug Tools: Monitoring, I/O, Breakpoints, and Other Neat Stuff
Monitoring the Program & I/O
Press F5 to download and debug the latest version of your Hello World test program.
In the Debugger window, notice the upper left panel is labeled Source and currently contains the main.c program source code.
The panel below that panel is labeled Procedure and is sometimes referred to as the Call Stack. This panel displays the function currently being executed at the top of the list and then the path it took to get there. Hold that thought and then direct your attention back to the panel containing main.c. Press the F11 button (single step) once. The highlighting in main.c should have moved forward in the instruction list, indicating that the next instruction to be executed is “MCU_init ();”, which is a “call” to function MCU_init. A call is the same as a JUMP SUBROUTINE or GOSUB in other programming languages. Think of MCU_init as a subroutine that runs only once when the uC first begins program execution.
Press F11 again and notice how the Source and Procedure panels both change. The uC is now executing the MCU_init function.
Press F11 a few more times, noticing the changes in the Source panel. Also, if you’re curious about assembly language and register-level debugging, notice the changes in the Assembly and Register panels.
Press Shift + F11 to step out of the current function (MCU_init) and back to the calling function (main).
If the Data:2 panel in the lower left is not currently displaying the LoopCount variable, right click anywhere in that panel, select Add Expression, and enter LoopCount. Spell it exactly that way since C is case sensitive. The new variable should then display in the Data:2 panel.
Press the F5 button to put the uC into Run mode rather than single step mode. The LoopCount value may or may not be visibly changing, depending on how your PC is set up. This value is actually changing constantly, but the debugger’s default setting is to update the displayed value of the variable only when the program stops. Verify by watching the LoopCount value and pressing F5, F6, F5, F6 a few times to start and stop the uC. Verify that the toolbar Run button (green right arrow) is changing colors as you go from Run mode to Stop mode.
If the uC program is not running, press F5 to start the execution again. Right mouse click anywhere within the Data:2 panel and select Mode > Periodical, Rate: 1. This will update the displayed value every 100 mS.
In the Data:1 panel, change the Mode to Periodical with an update rate of 100 mS using the same method as in the Data:2 panel.
Expand the _PTAD and Bits areas in Data:1. Watch the PTAD1 line while repeatedly pressing and releasing button SW0. Notice the value changing from 1 to 0 and back again. Notice also that the number turns red briefly the first time it has changed state since the last display update. This is a nice feature. Also watch the PTAD4 entry and notice that it is changing to match the state of LED1.
If the Source panel is not currently displaying the main.c file, right click that panel and select Open Source File, main.c, OK.
Locate the text “LoopCount < 32767;” and right click anywhere on it, then select Set Breakpoint. A red breakpoint symbol should appear to the left of that program code.
Press F5 to run the program and notice that the lower right Command panel indicates “STARTED RUNNING Breakpoint”. F5 started the program, it was running, and then it encountered a breakpoint and stopped. The Source and Assembly panels indicate the stop point: right at the breakpoint we just set, which is in the middle of a for instruction that is looping and incrementing LoopCount.
Notice the value of the LoopCount variable in the Data:2 panel. Press F11 repeatedly and watch the value increasing. If the value does not change, verify that you still have the update mode set correctly (right mouse click anywhere within the Data:2 panel and select Mode > Periodical, Rate: 1).
Optional: If you are curious about the assembly language code, watch the Assembly panel while repeatedly pressing Ctrl+F11 to step through each assembly language instruction. Also, check out the right click options in the Assembly panel.
You’ve just used an unconditional breakpoint. Now we’ll set a conditional breakpoint. Ctrl+R to reset the uC again, then open main.c in the Source panel. Right click anywhere in Source and select Show Breakpoints. This will open a window in which you can set certain conditions that must be satisfied before the breakpoint will cause the program to break. In the Condition field, enter the condition “LoopCount==14” (this says “break at this point when LoopCount is equal to 14”). Click OK, OK.
Press F5 to Run and watch the Source, Data:2, and Command panels.
There are a number of other very nice features in the debugger tool that you may wish to explore and learn on your own. Have fun!
Stand-alone uC Circuit Example:
Minimum Circuit Required for the Hello World Example Program
Here is the minimum circuit required for running the Hello World program with a stand-alone RS08 microcontroller:
Input PTA1 MUST be set to pullup. This would be done by using the Device Initialization tool mentioned in the beginning of this lab.
Capacitor C1 may not be required in all situations, but the uC may not go into Run mode without it. More information about operating modes may be found in the uC data sheet.
R1 is sized to limit PTA4 current to a level that will not overload and damage the uC chip. Do not change the value of R1.
It would make sense to develop and test the program on the demo board first. You would not have the option to test and debug while it is plugged into the breadboard. It is possible to connect to the uC for debugging, but that connection is beyond the scope of this lab.
Care should be exercised when removing the uC chip from the demo board and breadboard since the pins are very delicate, plus the chips are static sensitive.
Links to Executable Programming Examples Provided with this Training Material (CD or unzipped directory)
Place the RS08 chip back into the demo board and go through the following examples as you desire.
Keyboard Interrupt with STOP (low power mode) Instruction – contains C and Assembly mixed
This program demonstrates the use of low power “stop” mode and “keyboard interrupts”, the latter of which basically allows the chip to detect active input signals.
Open the device initialization tool and notice that some of the blocks are aqua, indicating that they have been changed from their original settings. Specifically, the COP feature is turned off, keyboard interrupt requests are enabled, and the KBIP1 feature is set active for pin 7 to detect low or falling edges. With this setup, any time pin 7 is pulled low by external circuitry (SW0 on the demo board), a keyboard interrupt is generated. Hold that thought.
The first thing done is the main function is that the uC is put into low power stop mode. This may be useful for applications where power consumption must be minimized, such as battery powered systems. The uC will stay in stop mode until SW0 is pressed, at which time a keyboard interrupt is generated (because the KBIP1 input is seen going low) and the uC is automatically taken out of stop mode and into run mode. The uC then continues running the program after the STOP command, toggling the output connected to LED1, acknowledging the interrupt, and then going into stop mode again.
In this program example, some simple Boolean logic is demonstrated (NOR, AND, OR functions, etc.). Also, parameter passing with a function is demonstrated in the NOR function. Nothing fancy is happening with the device initialization.
Chasing Lights Pulse Width Modulation (PWM) Demo
This demo uses the built-in timer module to generate a 34 uS timebase. See MTIM settings in Device Initialization. Also, KBIP1 is set up again to monitor the input tied to SW0. This program makes plentiful use of functions and parameter passing to alternately dim and brighten the lights. This dimming effect is accomplished through PWM, which basically blinks the LEDs very fast and controls apparent brightness by varying the duty cycle (percentage of entire cycle during which LED is on as compared to off).
Pay special attention to the following lines in which the program waits until the next 34 uS time tick:
while( ! SIP1_MTIM); // wait for overflow interrupt flag from timer
MTIMSC_TRST = 1; // reset timer and acknowledge the interrupt
Also pay attention to this code, which checks to see if the user has pressed the input button recently:
This example shows how to work with multi-dimensional arrays, a powerful and commonly used C construct.
In addition, it demonstrates something called “compiler directives” – the commands beginning with a # sign. If you do not understand these commands, ask your lab instructor to clarify.
Finally, the program shows how to determine uC memory usage and how constant arrays and variable arrays are stored in different memory areas. This could be useful to know when conserving memory is important. Read and follow the comment instructions provided in the program.
This program shows several examples of enumeration, which is a programming technique for assigning integer values to some words such as LED names & statuses and musical notes. Since there is no speaker attached, you cannot hear the musical notes.
analog voltage present. However, following the device initialization and program logic demonstrates how the analog input comparator could be used. Note that “SIP1_ACMP” is a bit that gets set when the analog compare condition is true, that is, the positive compare input is greater than the negative compare input.
Real Time Clock (RTC) Interrupt Demo
Look at the device initialization and main function to see how real time clock interrupts are used. Basically, a clock on the uC running in the background sets bit “SIP1_RTI” high every 131.072 mS. This is used to blink LED3 approximately once per second and LED2 approximately 8 times per second.
Documents Provided with this Training Material (CD or unzipped directory)