! OTHER CONSIDERATIONS > <! All links off our site should contain target="_blank" >
MPLAB: Some Notes for the Perplexed
Michael A. Covington
Last revised 1998 November 7
MPLAB is the full-featured PIC development environment that you can download from http://www.microchip.com (Microchip, Inc., the maker of PIC microcontrollers).
If you are not familiar with advanced software development tools, you may find MPLAB somewhat perplexing. These are some brief notes to help you get started. Please note that MPLAB is not my product and any further questions about it should be addressed to its manufacturer.
Please note also that you need to know PIC assembly language; you can learn it from many excellent books such as Easy PIC'n, available from Square One Press, and the online resources available from places such as DonTronics.
How to do without MPLABInstead of MPLAB, you can use MPASM, a standalone DOS-mode program. Download MPASM and install it. You'll see that it comes a lot of files with names like P16F84.INC, one for each kind of PIC. These are "include" files that define the names of the registers and the like; you only need the ones that correspond to the PICs you will be programming.
If you type
you'll be prompted to fill in lots of information. If you type
C:\MPASM> mpasm myprog
then MPASM will look for MYPROG.ASM and generate from it two files: MPASM.HEX, which contains your assembled code ready to put into the PIC, and MPASM.LST, which contains a source listing with error messages. If there are any fatal errors, MPASM.HEX will not be created.
How to create a project in MPLABOK, suppose you're using MPLAB instead. Everything in MPLAB revolves around the notion of a "project," which is a set of files that need to be processed to compile your program.
We'll assume you have just one file, MYPROG.ASM, and from it you want to generate MYPROG.HEX.
Choose Project, New Project.
Go to the directory where MYPROG.ASM resides, and create MYPROG.PJT there. The dialog box will say "*.pjt" and you type "myprog" in place of "*".
A diagram of the structure of the project will appear. It contains only one item, "myprog[.hex]". This is a "node," i.e., a file to be created by MPLAB.
Click once on "myprog[.hex]" and add the node "myprog.asm" under it. Then click OK a couple of times to get back to the main menu.
Choose Project, Save Project.
Then go to File, Open, and open the file MYPROG.ASM.
How to assemble (compile) your programNow it's time to tell MPLAB a bit more about what you're doing.
Go to Options, Development Mode, and choose MPSIM Simulator and tell it what kind of PIC you're using. Also go to Options, Processor Setup, and make sure everything is right.
Edit your file ad libitum, save it, and then go to Project, Build All. That means "do all the assembling and other things needed to get the .hex file into final form."
The assembler will run and some messages will appear on the screen:
You can double-click on any error message to go to the line it corresponds to.
- "Use of this instruction is not recommended" is normal for TRIS instructions.
- "Label found..." is serious: it means you misspelled an instruction. (The assembler may not think it's serious, but it is.)
- "MPLAB is unable to find the output file MYPROG.HEX" means the assembly failed due to errors. Correct the errors and try again.
You can also view the entire source listing (LST file), with messages in context, by choosing Window, Absolute Listing. Get into the habit of doing this.
Close the "Build Results" window when you are through with it.
How to step through your codeOnce you have the project successfully assembled, you can simulate execution of it. Be sure you're in MPSIM simulator mode (see above).
You will be using the Debug menu to run the program. But you must also set up some memory locations to be displayed, or you won't see anything.
Here is one of many things you can do.
The program will execute to the line you chose and then stop, displaying the state of memory.
- Choose Window, File Registers, to display a map of RAM.
- Choose Window, Special Function Registers, to display the registers.
- Go to any assembly instruction in the absolute listing window, right-click on it, and choose Run To Here.
From there, you can do another Run To Here, or step through the code, or reset the program, using the Debug, Run menu.
How to program your code into a PICFor NOPPP users, that's the easy part, at least in a backhanded sense of "easy."
If you had a Microchip programmer such as a PICstart Plus, you could turn it on from within MPLAB and do your programming. But NOPPP doesn't work that way. Exit MPLAB, find your .HEX file, and use the NOPPP software (in a DOS box) to do the programming.