Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
Скачиваний:
476
Добавлен:
12.08.2013
Размер:
4.99 Mб
Скачать

170

Chapter 9

program in order to generate the files shown in Figure 9-4 and any others that result from a particular project or IDE configuration.

The build process is initiated by selecting the <Build All> command in the Project menu. Once the building concludes, a screen labeled Output is displayed showing the results of the build operation. If the build succeeded, the last line of the Output screen shows this result. Figure 9-7 shows the output screen after a successful build.

Figure 9-7 Output Window showing the Build Command Result

9.2 Simulators and Debuggers

In the context of MPLAB documentation the term debugger is reserved for hardware debuggers while the software versions are called simulators. Although this distinction is not always enforceable, we will abide by this terminology (whenever possible) in order to avoid confusion. The reader should note that there are MPLAB functions in which the IDE considers a simulator as a debugger.

The MPLAB standard simulator is called MPLAB SIM. SIM is part of the Integrated Development Environment and can be selected at any time. The hardware debuggers currently offered by Microchip are named ICD 2, ICE 2000, and ICE 4000. A simulator, as the term implies, allows simulating the execution of a program one instruction at a time and viewing file registers and symbols defined in the code. Debuggers, on the other hand, allow executing a program one step at a time or to a predefined breakpoint while the PIC is installed in the target system. This makes

PIC Programming: Tools and Techniques

171

possible realtime viewing of the processor’s internals, and also the state of circuit components.

In the sections that follow we present an overview of PIC simulators and debuggers and their use.

9.2.1 MPLAB SIM

Microchip documentation describes the SIM program as a discrete-event simulator. SIM is part of the MPLAB IDE and is selected by clicking on the <Select Tool> command in the Debugger menu. The command offers several options, one of them being MPLAB SIM. Once the SIM program is selected, a special debug toolbar is displayed. The toolbar and its functions is shown in Figure 9-8.

Reset

Step out (of subroutine)

Step over (subroutine)

Step into (subroutine)

Animate

Halt

Run (to breakpoint)

Figure 9-8 SIM Toolbar

In order for the simulator to work the program must first be successfully built.

The most commonly used simulator methods are single-stepping through the code and breakpoints. A breakpoint is a mark at a program line at which the simulator stops and waits for user actions.

Breakpoints provide a way of inspecting program results at a particular place in the code. Single-stepping is executing the program one instruction at a time. The three buttons labeled <Step...> are used in single-stepping. The first one allows breaking out of a subroutine or procedure. The second one is for bypassing a procedure or subroutine while in step mode. The third one single steps into whatever line follows.

Breakpoints are set by double-clicking at the desired line while using the editor. The same action removes an existing breakpoint. Lines in which breakpoints have been placed are marked, on the left document margin, by a letter “B” enclosed in a red circle. Right-clicking while the cursor is on the program editor screen provides a context menu with several simulator-related commands. These include commands to set and clear breakpoints, to run to the cursor, and to set the program counter to the code location at the cursor.

172

Chapter 9

The View menu contains several commands that provide useful features during program simulation and debugging. These include commands to program memory, file registers, EEPROM, and special function registers. One command in particular, named <Watch>, provides a way of inspecting the contents of FSRs and GPRs on the same screen. The <Watch> command displays a program window that contains references to all file registers used by the program. The user then selects which registers to view and these are shown in the Watch window. The Watch window is shown in Figure 9-9.

Figure 9-9 Use of Watch Window in MPLAB SIM

When the program is in the single-step mode or breakpoint modes, the contents of the various registers can be observed in the Watch window. Those that have changed since the last step or breakpoint are displayed in red. The user can click the corresponding arrows on the Watch window to display all the symbols or registers. The <Add Symbol> or <Add FSR> button is then used to display the item on the Watch screen. Four different Watch windows can be enabled, labeled Watch 1 to Watch 4 at the bottom of the screen in Figure 9-9.

Another valuable tool available from the View menu is the one labeled <Simulator Trace>. The Simulator Trace window provides a view of the machine instruction combined with a window that displays the source code. The Simulator Trace window is shown in Figure 9-10.

9.2.2 MPLAB Hardware Debuggers

A more powerful and versatile debugging tool is a hardware or in-circuit debugger. Hardware debuggers allow tracing, breakpointing, and single-stepping through code while the PIC is installed in the target circuit. The typical in-circuit debugger requires several hardware components, as shown in Figure 9-11.

PIC Programming: Tools and Techniques

173

Figure 9-10 MPLAB SIM Simulator Trace Window

Power cable

Communications cable

Emulator pod

Processor

module

Cable to Logic circuit probe

connector

Adapter

Transition

socket

Figure 9-11 Components of a Typical Hardware Debugger