MPLAB is the main tool used to compile programs for PIC microcontrollers from PIC10F to dsPIC33F. The program can be written in Assembly, which the default MPLAB is set or can be plug-in from other compilers such as C18 and Hi-Tech C.
Setting up MPLAB
1. Project -> Project Wizard…
Starter to MPLAB

Figure 1: Main MPLAB interface

2. Click on Next

Starter to MPLABFigure 2: Project Wizard Interface

3. The device needed has to be selected and click Next.

Starter to MPLABFigure 3: Selecting device

Selecting language toolsuiteFigure 4: Selecting language toolsuite

4. Save the new project files.

Selecting language toolsuite mplapFigure 5: Creating a new project file

5. If previous codes or the codes have been saved in the computer, add the codes using Add or remove using Remove. Then, click Next.

Selecting language toolsuite mplapFigure 6: Add existing files to project

6. Click on Next after confirmed the device and toolsuite has been correctly selected. If not, click on Back to edit.


Selecting language toolsuite mplap

Figure 7: Summary of the project created

7. Click Save to save the workspace in the same directory with the same name.

Save workspace mplap

Figure 8: Save Workspace

Figure 9 shows you the interface you should get after performing the above steps.

PIC microcontrollers from PIC10F to dsPIC33FFigure 9: Project view

8. Source file is added by Right click on Source Files -> Add Files…

PIC microcontrollers from PIC10F to dsPIC33F

Figure 10: Adding source to project

9. If other compiler is used instead of Assembly, then the Linker- Script Search location has to be added. This can be done by Project -> Build Options.. -> Project. By doing so, this will bring up Figure 11.

PIC microcontrollers from PIC10F to dsPIC33FFigure 11: Linking the project to toolsuite linker file

10. Select the Show directories for: drop down and select Linker-Script Search Path -> New and redirect it to ..\..\MCC18\lkr depending on where you installed your MCC18. For this example, C18 compiler is chosen.

PIC microcontrollers from PIC10F to dsPIC33FFigure 12: Adding linker file to project

11. Before building the program, the linker file for the chosen device has to be added as well in Linker Script folder as shown above.

Instead of just building the hex file to program the device, MPLAB also includes a simulator to simulate the program. The simulator can be selected by: Debugger -> MPLAB Sim.

Using MPLAB Sim and BreakpointFigure 13: Using MPLAB Sim and Breakpoint

12. By clicking on the different line of the code, breakpoints can be insert. The breakpoints is used to halt the program so that the developer can view the content of the register through Watch. To bring out the watch window, View -> Watch.

Register view in Watch

Figure 14: Register View In watch

Figure 15 shows the execution of the codes until the for loop with the green arrow indicating the current executed line of codes.

TRISD and PORTD initialized to 0Figure 15: TRISD and PORTD initialized to 0

13. By stepping through the for loop, the register values in the watch window changes. This will ease the verification of the code.

TRISD and PORTD initialized to 0Figure 16: TRISD and PORTD values changes after step through

MPLAB is a great tool that in-cooperate the generation of hex for programming as well as debugging using virtual tool, MPLAB Sim or Proteus VSM plug-in. Additionally, MPLAB also provides an interface for programming using various microchip programmer from Pickit 2 to Real ICE.


Engineering Student

Leave a Reply

Your email address will not be published. Required fields are marked *