



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1.1 To perform C programming using MPLAB C18 C Compiler
This document provides information for a quick start. The MPLAB IDE software contains extensive help manuals under Help menu.
3.1 Personal Computer 3.2 MPLAB C18 C Compiler (Student Edition)
It is best to contain all the files related to a project in a folder. Create a directory D:\ENT373\LAB1 for example.
4.1 STARTING MPLAB IDE
To launch MPLAB IDE click the MPLAB IDE icon on the desktop.
MPLAB IDE v8.10.lnk
The Microchip splash screen will appear while MPLAB IDE is loading.
4.2 CREATE SOURCE CODE
Select File>New to open a new file for edit. Enter the C code as in the Appendix I.
Once you have completed entering the code, select File>Save AS and save the file in the project directory D:\ENT373\LAB1 as Example1.c.
The editor is context sensitive. As soon as the file extension is known, it shows different colors and emphasis for reserved words.
You need a project to build the program. Follow the steps below to create a new project.
4.4 BUILD THE PROJECT
Select Project>Build All to build your project. Alternatively or more conveniently, you may use the make or the build all buttons.
If your file did not compile successfully, error messages will appear in the output window. Always scroll back to the beginning of the output window to be sure that you did not miss any messages.
Double click on the error message in the Output window will bring you to the error in the source file. A green arrow in the gutter on the left of the source file window points to the line where the error was found (It may not be the location where error occurs).
If the errors were found after compilation, it may not be able to link the error to a specific location in the source. Correct all the syntax errors and rebuild the project. Warnings are errors that were deemed not critical to produce a product. It is advised that you always read the warning messages and attempt to clean them up.
4.5 COMPILER OUTPUT FILES
Upon a successful build, the compiler and the IDE create a list of output files. The following are the ones that might interest you.
4.5.1 THE .LST FILE
The listing file shows the source file that the compiler sees along with the assembly code produced by the compiler.
You can see the values of variables when the simulation is halted by putting the mouse cursor over the name of the variable in the source file. A tool tip like display will show the current value of the variable (this is called mouse over ).
Rather than mouse over the name each time you want to see the value of a variable, you can open a Watch window by Select View>Watch
The Watch window will remain on the screen and show the current variable values when the program execution halts.
Add variables: i , counter and PORTB in the Watch window. You may click in the blank area just under the last “ Symbol Name ” and type in the name of the variable, or you may use the pull-down menu selection on the top of the window to choose the variable then click “ Add ” button. Both i and counter are variables in C program and you will find them to the right of Add Symbol button. PORTB is a special function register; you have to find it next to Add SFR button. After the variable is added, the display format may be modified by right click on the line and select “ Properties …”. Here, you may change the displayed format to decimal from hexadecimal. The values in the watch window do not get updated when the program is running. Only when the program execution halts will they get refreshed. The values are displayed in red when its content changed. Since i is an autovariable in function delay, you need to step into delay before the value becomes valid. Otherwise, “Out of Scope” is shown as its value.
4.6.4 BREAKPOINT
By double clicking on a line of code, a stop sign with a ‘ B ’ appears in the gutter to indicate the breakpoint. If you run the program, the execution halts when encountering a breakpoint. The green arrow will rest on the stop sign. (When the execution halts, the line with the stop sign is NOT executed yet.)
APPENDIX I
EXAMPLE
Write the following C program using the MPLAB C18. Compile your project and animate your program by Debugger>>Animate. Observe the program flows.
EXAMPLE 3
Write the following C program using the MPLAB C18. Compile your project and animate your program by Debugger>>Animate. Observe the program flows. Select Debugger>>Stopwatch. Put a BREAK between the delay programs and observe the time calculated.