Using the debugger

uVision5 provides a debugger that allows us to suspend execution (by inserting a breakpoint), and examine/change values of variables used in our program.

How to do it…

  1. Download and run the previous project, debug_ADC.
  2. Use the debug menu to insert a breakpoint on line 96 of our program (that is, at the statement ADC_StartConversion ( );.
    How to do it…
  3. Select debugStart/Stop Debug session to start a debug session.
  4. Observe that execution stops at main. This is because the default project debug options are set to "Run to main".
    How to do it…
  5. Selecting Run (F5) will execute the statements up until the breakpoint.
  6. Use Step (F11) to execute the statements in the program one after the other, and observe the values of variables. For example, when we reach line 39 (after stepping), the local variable ADCvalue is assigned to 10 (0x0000000A). This value is shown in the Call Stack + Locals window.
    How to do it…

See also

This chapter has introduced many more programming concepts than would normally be covered in the first few chapters of a programming textbook, and the text is really aimed at those readers with experience of other languages. Those who are new to programming will need to fill some of the gaps by reading an introductory programming text. Because C has been around for more than 30 years, there are plenty to choose from! However, most novices will find recently published or revised editions of standard texts, more accessible than books written in the 1980s and 90s. You may find it easier to learn C by writing programs for your PC rather than the evaluation board. In fact, some of my students develop and test their embedded algorithms using a PC before porting them to uVision5. This is perfectly feasible for programs (or parts of programs) that do not need to access peripherals such as the ADC, and the like. You will need to install a C compiler to enable you to do this; free options include Visual Studio Express, Open Watcom, and GCC. The graphical user environments available with most of these compilers provide a user interface very similar to that of uVision5.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.27.202