Hands-On Technical Training (hott) Workshop: Introduction to Microcontroller Programming in C

Debug Tools: Monitoring, I/O, Breakpoints, and Other Neat Stuff

Download 110.29 Kb.
Size110.29 Kb.
1   2   3   4   5

Debug Tools: Monitoring, I/O, Breakpoints, and Other Neat Stuff

Monitoring the Program & I/O

  1. Press F5 to download and debug the latest version of your Hello World test program.

  2. In the Debugger window, notice the upper left panel is labeled Source and currently contains the main.c program source code.

  3. 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.

  4. Press F11 again and notice how the Source and Procedure panels both change. The uC is now executing the MCU_init function.

  5. 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.

  6. Press Shift + F11 to step out of the current function (MCU_init) and back to the calling function (main).

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

Using Breakpoints

  1. Press F6 to stop the uC program execution, and then press Ctrl+R to reset the target (the development board).

  2. If the Source panel is not currently displaying the main.c file, right click that panel and select Open Source File, main.c, OK.

  3. 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.

  4. 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.

  5. 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).

  6. 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.

  7. 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.

  8. 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:

If one were to breadboard and test the above circuit, they would have to keep in mind the following key points:

  1. Input PTA1 MUST be set to pullup. This would be done by using the Device Initialization tool mentioned in the beginning of this lab.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  1. 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.

  1. Boolean Logic Demo

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.

  1. 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:

// look for user-requested cycle change

if(SIP1_KBI) {

  1. Array Size Testing

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.

  1. Enumeration Demo

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.

  1. Comparator Demo

This program will not work with the demo board because there is no variable

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.

  1. 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.

Additional Resources

Documents Provided with this Training Material (CD or unzipped directory)

Freescale RS08-related:

DEMO9RS08KA2 Development Board User’s Manual

DEMO9RS08KA2 Development Board Schematic

RS08KA1 & KA2 Microcontroller Data Sheet

RS08 Core Reference Manual (assembly language instruction set, etc.)

RS08 Assembly Language Demos & Quick Reference User's Guide

Application Note on RS Data Structures (not too intense)
C Language-related:

Freescale’s Learn_Programming_with_C

C Language Keywords: C Language Keywords.mht

Online Resources

Review of bits, bytes, etc.: http://www.learn-c.com/data_lines.htm

Tutorial on C programming with microcontrollers: http://www.learn-c.com/alltoget.htm

Online C language reference: http://ccs.ucsd.edu/c/

C Programming:


C Language FAQs: http://c-faq.com/index.html

Developing Embedded Software in C:


The GNU C Library - Table of Contents :


C Reference, Searchable and quite good: http://www.sysprog.net/cplus.html

Free IDE/C compiler for the mid-to-low end Freescale microcontrollers:

www.freescale.com and search for “CWX-HC08-SE”


CodeWarrior website: www.freescale.com/codewarrior

CodeWarrior email support: cw_support@freescale.com

General support for entire Freescale product line: www.freescale.com/support

Purchasing Your Own Demo Kits and Microcontrollers

Various vendors sell microcontrollers and demo kits. The best price ($10 + S&H) for the DEMO9RS08KA2 may be found here:

www.avnet.com and search for “DEMO9RS08KA2”.

Directory: people
people -> Math 4630/5630 Homework 4 Solutions Problem Solving ip
people -> Handling Indivisibilities
people -> San José State University Social Science/Psychology Psych 175, Management Psychology, Section 1, Spring 2014
people -> YiChang Shih
people -> Marios S. Pattichis image and video Processing and Communication Lab (ivpcl)
people -> Peoples Voice Café History
people -> Sa michelson, 2011: Impact of Sea-Spray on the Atmospheric Surface Layer. Bound. Layer Meteor., 140 ( 3 ), 361-381, doi: 10. 1007/s10546-011-9617-1, issn: Jun-14, ids: 807TW, sep 2011 Bao, jw, cw fairall, sa michelson
people -> Curriculum vitae sara a. Michelson
people -> Curriculum document state board of education howard n. Lee, C
people -> A hurricane track density function and empirical orthogonal function approach to predicting seasonal hurricane activity in the Atlantic Basin Elinor Keith April 17, 2007 Abstract

Download 110.29 Kb.

Share with your friends:
1   2   3   4   5

The database is protected by copyright ©ininet.org 2024
send message

    Main page