Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 8543
Скачиваний: 0
PIC Programming: Tools and Techniques |
165 |
5.Develop, load, and test the software. Loading software into a PIC is referred to as “burning” or “blowing” the PIC.
6.Implement the final system and test hardware and software.
9.1 Integrated Development Environment
The MPLAB development system consists of a system of programs that run on a PC. This software package is designed to help develop, edit, test, and debug PIC code.
Installing the MPLAB package is straightforward and simple. The package includes the following components:
1.MPLAB editor. This tool allows creating and editing the assembly language source code. It behaves like any Windows editor and contains the standard editor functions, including cut-and-paste, search-and-replace, and undo and redo functions.
2.MPLAB assembler. The assembler reads the source file produced in the editor and generates either absolute or relocatable code. Absolute code executes directly in the PIC.
Relocatable code can be linked with other separately assembled modules or with libraries.
3.MPLAB linker. This component combines modules generated by the assembler with libraries or other object files, into a single executable file in .hex format.
4.MPLAB debuggers. Several debuggers are compatible with the MPLAB development system. Debuggers are used to single-step through the code, breakpoint at critical places in the program, and watch variables and registers as the program executes. In addition to being a powerful tool for detecting and fixing program errors, debuggers provide an internal view of the processor; this is a valuable learning tool.
5.MPLAB In-circuit emulators. These are development tools that allow performing basic debugging functions while the processor is installed in the circuit.
Figure 9-1 (in the following page) is a screen image of the MPLAB program. The application on the editor window is one of the programs developed later in this book.
9.1.1 Installing MPLAB
In normal installation, the MPLAB executable is placed in the following path:
C:\Program Files\Microchip\MPASM Suite
Once the development environment is installed, the software is executed by clicking the MPLAB IDE icon. It is usually a good idea to drag and drop the icon onto the desktop so that the program can be easily activated.
With the MPLAB software installed, it may be a good idea to check that the applications were placed in the correct paths and folders. Failure to do so produces as- sembly-time failure errors with cryptic messages. To check the correct path for the software, open the Project menu and select the Select Language Toolsuite command. Figure 9-2 shows the command screen.
166 |
Chapter 9 |
Figure 9-1 Screen Image of the MPLAB IDE
In the toolsuite window make sure that the file location coincides with the actual installation path for the software. If in doubt, use the <Browse> button to navigate through the installation directories until the executable program is located. In this case, mpasmwin.exe. Follow the same process for all the executables in the
Toolsuite Contents window.
Figure 9-2 MPLAB Select Language Toolsuite Screen
PIC Programming: Tools and Techniques |
167 |
Figure 9-3 MPLAB Set Language Tools Locations Screen
A more detailed control over the location of the various individual tools is provided by the Set Language Tools Location command, also in the Project menu. This command allows setting the installation path not only to the major suites, but also to the individual tools. Figure 9-3 shows the display screen of this command.
9.1.2 Creating the Project
In MPLAB, a project is a group of files generated or recognized by the IDE. Figure 9-4 shows the structure of an assembly language project.
PxxFyy.inc |
||||||||||||
prog1.asm |
||||||||||||
MPASM |
||||||||||||
(assembler) |
||||||||||||
prog1.o |
||||||||||||
MPLIB |
||||||||||||
(librarian) |
||||||||||||
sup.lib |
MPLINK |
device.lkr |
||||||||||
(linker) |
||||||||||||
prog1.lst |
prog1.hex |
prog1.map |
prog1.err |
|||||||||
Figure 9-4 MPLAB Project Files
168 |
Chapter 9 |
Figure 9-4 shows an assembly language source file (prog1.asm) and an optional processor-specific include file which are used by the assembler program (MPASM) to produce an object file (prog1.o). Optionally, other sources and other include files may form part of the project. The resulting object file, as well as one or more optional libraries, and a device-specific script file (device.lkr) are then fed to the linker program (MPLINK). MPLINK generates a machine code file (prog1.hex) and several support files with listings, error reports, and map files. The .hex file is used to blow the PIC.
In addition to the files in Figure 9-4, others may also be produced by the development environment according to the selected tools and options. For example, the assembler or the linker can generate a file with the extension .cod that contains symbols and references used in debugging.
Projects can be created using the <New> command in the Project menu. The programmer then proceeds to configure the project manually and add to it the required files. An alternative option, much to be preferred when learning the environment, is using the <Project Wizard> command in the Project menu. The wizard prompts you for all the decisions and options that are required, as follows:
1.Device selection. Here the programmer selects the PIC hardware for the project, for example 16F84A.
2.Select language toolsuite. This screen is the same one shown in Figure 9-2. Its purpose is to make sure that the proper development tools and paths are active.
3.Next, the wizard prompts the user for a project name and directory. It is possible to create a new directory at this time.
4.In the next step, the user is given the option of adding existing files to the project and renaming these files if necessary. This can be a useful option, since most projects reuse a template, an include file, or other preexisting resources.
5.Finally, the wizard displays a summary of the project parameters. When the user clicks on the <Finish> button, the project is created and programming can begin.
Figure 9-5 Final Screen of the Project Creation Wizard
PIC Programming: Tools and Techniques |
169 |
9.1.3 Project Build Options
The <Build Options: Project> command in the Project menu allows the user to customize the development environment. Of the tabs available on the Build Options screen, the MPASM Assembler is probably the most used. The screen is shown in Figure 9-6.
Figure 9-6 MPASM Assembler Tab in the Build Options Screen
The MPASM Assembler tab allows performing the following customizations:
1.Disable/enable case sensitivity. Normally the assembler is case-sensitive. Enabling this option turns all variables and labels to upper case.
2.Select the default radix. Numbers without formatting codes are assumed to be hex, decimal, or octal according to the selected option.
3.The Macro Definition window allows adding macro directives. Macros are discussed later in this chapter.
4.The Use Alternate Settings text box is provided for command line commands in non-GUI environments.
5.The Restore Defaults box turns off all custom configurations.
9.1.4 Building the Project
Once all the options have been selected, the installation checked, and the assembly language source file written or imported, the development environment builds the project. Building consists of calling the assembler, the linker, and any other support
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.