Professional Documents
Culture Documents
Lab 1
Lab 1
Lab 1
The targeted processor (processor being used) must be selected before continuing. This can be done be selecting from the main menu Configure>Select Device. Select the appropriate device, in this case, the 18F452, then press OK.
Output Directory: - This is the final destination for files that result only from a complete build of the project i.e. The *.cod, *.cof and *.hex files. Leave Output Directory blank. This results in the output file (*.cof) being placed in the project directory. Intermediates Directory: - This is where the object files produced by the compiler will be placed. Leave this directory blank as well, resulting in the object file (*.o) being placed in the same directory as the source file. Linker-Script Path: - The MPLINK linker will search the directory specified in this path for the linker scripts. This entry can also be left blank, it will be added later in the project tree
By default, when the MPLINK linker is run from the MPLAB IDE, it will not generate a map (example1.map) file. To change this, select Generate map file on the MPLINK Linker tab then press OK.
Prepared by: Document Version: Date: Feisal Mohammed 0.1 9/29/2005
The required startup module, standard library and processor library are specified in the linker script, and so no file needs to be added to Object Files or Library Files in the project tree. If there were other object files or library files to link in the project, they would be added under these branches. LINKER SCRIPTS: The MPLINK linker requires a linker script to be specified. Right click on Linker Scripts in the project window, and select Add Files. Use the linker script 18f452.lkr in the lkr subdirectory of the MPLAB C18 installation directory. This script is for the PIC18F452 device. BUILDING THE PROJECT: Select Project>Build All or ctrl F10 to compile and link the project. If there are any error or warning messages, they will appear in the output window.
Open the source file by double clicking on it in the project tree. In the source file, place the cursor over the line where the breakpoint is desired to be set, and right click. Select Set Breakpoint. Or double clicking on the line will also place and remove the break point. The red dot in the gutter along the side of the source window indicates that the breakpoint has been set and is enabled. Breakpoints can be set and removed this way.
5.1 WATCH WINDOWS To open a watch window on the variable counter, select View>Watch. Select the data to be observed from the menu next to Add symbol, then press Add symbol. Then press the run button on the toolbar to run the program
The program halts just before the statement at the breakpoint is executed. The green arrow in the gutter of the source window points to the next statement to be executed. What is the value of counter in the watch window? Click run again to continue the program and write down the value of counter after this action.
Different data can be observed by choosing Watch 1-4 on the tab. Different registers can also be viewed by using Add SFR to select. 5.2 STEPPING To step through the source code one statement at a time, use Step Into on the toolbar. As each statement executes, the green arrow in the gutter of the source window moves to the next statement to be executed. The Animate button halted by using the Halt button . runs the program automatically and can be
When first using the step into button a window opens what is the name of the window and what does it contain?
The reset button allows the user to start from the beginning of the code, write down the line of code that the arrow points too when this button is used and describe what does this piece of code does.
5.3 MAP AND LISTING FILES The map file (example1.map) and the list file (example1.lst) are present in the project directory and can be view using File>Open, then browse to the project directory allocating the file type as *.map or *.lst, to locate the file. These files provide additional information that may be useful debugging, such as details of allocation of variables and the correspondence between machine code and source code.
Open the listing file for the project *.lst and copy the part of the code that is in the main under the headings Address, value, Disassembly and Source. Open also the *.map file and copy the line which shows the counter, the address and location and also the storage type.
6.1 PROGRAMMING THE DEVICE To program the device select Debugger>Program. The programming window should show the programming operation succeeded.
7 STIMULUS CONTROLLER
This option is useful for debugging, in that it substitutes the actual circuit with a virtual one. If an input is expected from PIC to carry out an operation it can be done with out programming it. Simply select Debugger>Stimulus Controller> New Scenario, the dialog box as show in the diagram should appear. Choose from the drop down box the desired pin to be simulated, in action choose the value setting for the pin.
If a continuous cyclic action is desired, select pulse, and the width of the pulse as well as the units that it should take. During the running of the program the pin/s can be fired using the fire option. On simulation the output would give an indication in the MPLAB SIM tab of the status of the pin.
Configure RB1 as an input and use stimulus to simulate the high and low setting of a switch that controls the lighting of a light emitting diode on RB0. Show the code for this operation below.
Observe the output window and write down its contents when using stimulus.