Getting Started with MPLAB Software

Getting Started with MPLAB Software

Tags: Install mplab, how to install mplab, create a project in mplab,introduction to mplab,
Overall rating

The MPLAB X IDE is the new graphical, integrated debugging tool set for all of Microchip’s more than 800 8-bit, 16-bit and 32-bit MCUs and digital signal controllers, and memory devices.

It includes a feature-rich editor, source-level debugger, project manager, software simulator, and supports Microchip’s popular hardware tools, such as the MPLAB ICD 3 in-circuit debugger, PICkit™ 3, and MPLAB PM3 programmer.

MPLAB IDE is a Windows Operating System (OS) software program that runs on a PC to develop applications for Microchip microcontrollers and digital signal controllers. It is called an Integrated Development Environment, or IDE, because it provides a single integrated "environment" to develop code for embedded microcontrollers. Experienced embedded systems designers may want to skip ahead to Components of MPLAB IDE.


MPLAB IDE is a Windows Operating System (OS) based Integrated Development Environment for the PIC MCU families and the dsPIC Digital Signal Controllers. The MPLAB IDE provides the ability to:

  • Create and edit source code using the built-in editor.
  • Assemble, compile and link source code.
  • Debug the executable logic by watching program flow with the built-in simulator or in real time with in-circuit emulators or in-circuit debuggers.
  • Make timing measurements with the simulator or emulator.
  • View variables in Watch windows.
  • Program firmware into devices with device programmers.

MPLAB IDE supports the use of numerous assemblers and compilers for building code in programming languages.

Microchip provides free assemblers and linkers for PIC MCU and dsPIC DSC devices, as well as compilers (free student/academic/demo editions and for-purchase full versions). Third parties provide additional coverage with language tools for assembly, C and BASIC languages


The MPLAB IDE combines project management, make facilities, source code editing, program debugging, and complete simulation in one powerful environment. The MPLAB development platform is easy-to-use and helping you quickly create embedded programs that work.

The MPLAB editor and debugger are integrated in a single application that provides a seamless embedded project development environment.

The MPLAB IDE combines project management, a rich-featured editor with interactive error correction, option setup, make facility, and on-line help.

Use MPLAB to create your source files and organize them into a project that defines your target application. MPLAB automatically compiles, assembles, and links your embedded application and provides a single focal point for your development efforts.

When you use the MPLAB, the project development cycle is roughly the same as it is for any other software development project.

  • Create a project, select the target chip from the device database, and configure the tool settings.
  • Create source files in C or assembly.
  • Build your application with the project manager.
  • Correct errors in source files.
  • Test the linked application.
  • Debug the executable logic by watching program flow with the built-in simulator or in real time with in-circuit emulators or in-circuit debuggers.
  • Make timing measurements with the simulator or emulator.
  • View variables in Watch windows.
  • Program firmware into devices with device programmers.

Install / Uninstall the MPLAB IDE

To install MPLAB IDE on your system:

Note: For some Windows OS's, administrative access is required in order to install software on a PC.

  • If installing from a CD-ROM, place the disk into a CD drive. Follow the onscreen menu to install MPLAB IDE. If no on-screen menu appears, use Windows Explorer to find and execute the CD-ROM menu, menu.exe.
  • Downloading MPLAB IDE from the Microchip web site (, locate the download (.zip) file and click on it to save it to your PC. Then, unzip it and execute the resulting file to install.

First click on the exe file in the specified folder.


After clicking on the Install_xxx file then installation preparation will start, when prompted click on next.


Accept License agreement and Click on next.


Select complete and press next.


To install this folder click next or otherwise chose another location and press next.


Click next after accepting the license agreement.


Review setting before copying and if you want to change, you can by using back button.


Here you can the status base for installing


Now click on finish button,


After finish you can see and chose Mplab IDE document select.


We choose release note to view. Now installation is completed. You can now open the MPLAB IDE from Start > All Programs > Microchip > MPLAB.


Now you have successfully installed MPLAB. Now we can start to working with MPLAB IDE.

Before we can use MPLAB IDE, you must install specific compiler software.

To uninstall MPLAB IDE:

  • Select Start>Settings>Control Panel to open the Control Panel.
  • Double-click on Add/Remove Programs. Find MPLAB IDE on the list and click on it.
  • Click Change/Remove to remove the program from your system.

First we can Select Start>Settings>Control Panel.


Next Select the Add/Remove Programs. Find MPLAB IDE on the list and click on it.


Click Change/Remove to remove the program from your system.



The Mplab screen provides you with a menu bar for command entry, a tool bar where you can rapidly select command buttons, and windows for source files, dialog boxes, and information displays. Mplab lets you simultaneously open and view multiple source files.

Mplab has two operating modes:

  • Build Mode: Allows you to translate all the application files and to generate executable programs. The features of the Build Mode are described under Creating Applications.
  • Debug Mode: Provides you with a powerful debugger for testing your application. The Debug Mode is described in Testing Programs.

In both operating modes you may use the source editor of Mplab to modify your source code. The Debug mode adds additional windows and stores an own screen layout.

Setting up the Development Mode

The MPLAB IDE desktop contains the following major elements:

1. A menu across the top line

2. A toolbar below the menu

3. A workspace in which various files, windows, and dialogs can be displayed

4. A status bar at the bottom


The development mode sets which tool, if any, will execute code. For this tutorial we will use MPLAB-SIM, the software simulator. Later you may switch to one of the emulator operations if you have an emulator. Operation will be similar. “Editor Only” mode does not allow code execution, and is mainly useful if you have not installed the simulator, do not have an emulator, and are just creating code to program a PIC micro microcontroller (MCU).

Select the Options > Development Mode menu item and click the Tools tab to select the development tool and processor for your project.


MPLAB IDE is a constantly evolving product, so there may be subtle differences between what you see and the picture here. Select MPLAB-SIM Simulator and choose the dsPIC30F4011 from the pull down list of available processors supported by the simulator. Click OK. The simulator will initialize and you should see “dsPIC30F4011” and “Sim” in the status bar on the bottom of the MPLAB IDE desktop. You are now in simulator mode for the dsPIC30F4011 device.

Creating a Project

The next step is to create a project using the Project Wizard. A project is the way the files are organized to be compiled and assembled. We will use a single assembly file for this project and a linker script. Choose Project>Project Wizard.

The next dialog (Step One) allows you to select the device, which we’ve already done.


Now we can select Next button then the window shows as shown in below. Then we can select the device.


Select Language Tools

Step two of the Project Wizard sets up the language tools that are used with this project. Select Microchip C30 Tool suite in the top pull down. Then you should see C30, MPLINK and MPLIB show up in the Tool suite Contents box. You can click on each one to see its location. If you installed MPLAB IDE into the default directory, the C30 compiler executable will be:

C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe

The MPLINK linker executable will be:

C:\Program Files\Microchip\MPLAB C30\bin\pic30-ld.exe

And the MPLIB librarian executable will be:

C:\Program Files\Microchip\MPLAB C30\bin\pic30-ar.exe

If these do not show up correctly, use the browse button to set them to the proper files in the MPLAB IDE subfolders.


When you are finished, click Next >.

Naming the Project

Step Three of the wizard allows you to name the project and put it into a folder.

This sample project will be called Mplab. Using the Browse button, place the project in a folder named Mplab. Click Next>.


Adding files to Project

Step Four of the Project Wizard allows file selection for the project. A source file has not yet been selected, so we will use an MPLAB IDE template file. The template files are simple files that can be used to start a project. They have the essential sections for any source file, and contain information that will help you write and organize your code.

These files are in the MPLAB IDE folder, which by default is in the Program Files folder on the PC.

There is one template file for each Microchip PIC micro and dsPIC device.

Choose the file named led_delay.c. If MPLAB IDE is installed in the default location, the full path to the file will be:

C:\Documents and Settings\Administrator\Desktop\Mplab\led_delay.c


Press Add>> to move the file name to the right panel, and the file name to enable this file to be copied to our project directory.

Make sure that your dialog looks like the picture above, with both check boxes checked, then press Next> to finish the Project Wizard.


The final screen of the Project Wizard is a summary showing the selected device, the tool suite and the new project file name.

After pressing the Finish button, review the Project Window on the MPLAB IDE desktop. If the Project Window is not open, then select View>Project.



Files can be added and projects saved by using the right mouse button in the project window. In case of error, files can be manually deleted by selecting them and using the right mouse click menu.

Building the Project

From the Project menu, we can assemble and link the current files. They don’t have any of our code in them yet, but this assures that the project is set up correctly.


To build the project, select either:

  • Project>Build All
  • Right-click on the project name in the project window and select Build All
  • Click the Build All icon on the Project toolbar. However the mouse over icons to see pop-up text of what they represent.

The Output window shows the result of the build process. There should be no errors on any step.



If these do not assemble and link successfully, check the following items and then build the project again:

  • Check the spelling and format of the code entered in the editor window. Make sure the new variables and the special function registers, TRISC and PORTC, are in upper case. If the assembler reported errors in the Output window, double click on the error and MPLAB IDE will open the corresponding line in the source code with a green arrow in the left margin of the source code window.
  • Check that the correct compiler (Microchip C30 Compiler) and linker for PIC micro devices are being used. Select Project>Set Language Tool Locations. Click on the plus boxes to expand the Microchip C30 tool suite and its executables. Click Microchip C30 Compiler (pic30-gcc.exe) and review their location in the display. If the location is correct, click Cancel. If it is not, change it and then click OK. The default search paths can be empty.

Upon a successful build, the output file generated by the language tool will be loaded.

This file contains the object code that can be programmed into a PIC micro MCU and debugging information so that source code can be debugged and source variables can be viewed symbolically in Watch windows.

Testing Code with the Simulator

In order to test the code, software or hardware is needed that will execute the PIC micro instructions. A debug execution tool is a hardware or software tool that is used to inspect code as it executes a program (in this case led_delay.c). Hardware tools such as MPLAB ICE or MPLAB ICD 2 can execute code in real devices. If hardware is not available, the MPLAB simulator can be used to test the code. In this tutorial we can use MPLAB SIM simulator.

The simulator is a software program that runs on the PC to simulate the instructions of the PIC micro MCU.

It does not run in “real time,” since the simulator program is dependent upon the speed of the PC, the complexity of the code, overhead from the operating system and how many other tasks are running. However, the simulator accurately measures the time it would take to execute the code if it were operating in real time in an application.


Other debug execution tools include MPLAB ICE 2000, MPLAB ICE 4000 and MPLAB ICD 2. These are optional hardware tools to test code on the application PC board. Most of the MPLAB IDE debugging operations are the same as the simulator, but unlike the simulator, these tools allow the target PIC micro MCU to run at full speed in the actual target application.

The status bar on the bottom of the MPLAB IDE window should change to “MPLAB SIM”.

Additional menu items should now appear in the Debugger menu. Additional toolbar icons should appear in the Debug Tool Bar.


MPLAB SIM is one of the debug engines that can be used with MPLAB. The other debug engines are hardware devices, while MPLAB SIM is a software program that runs on your PC. MPLAB SIM provides many of the same features as in-circuit emulators and in-circuit debuggers. The difference is that both in-circuit emulators and in-circuit debuggers allow the code to be run on actual silicon, and also allow target application hardware to be functional while being debugged.

MPLAB SIM has features to simulate hardware interaction with other signals and devices, and since it is running as software on the PC, it has complete information about the internal state of the simulated chip at each instruction. This is a little different from the hardware debuggers because, while they are running code at full speed, they typically cannot monitor all registers and all memory in real time.

Both MPLAB SIM and the hardware debuggers can do the traditional functions of debuggers, but due to their differences, they can have unique features of their own. This presentation will identify the functions and features of MPLAB SIM.

The debugger is a part of MPLAB IDE, and whether you are using MPLAB SIM, MPLAB ICE or MPLAB ICD 2, most operations are exactly the same. This allows you to develop code using the simulator, and then when your hardware is ready, you can use a hardware debugger to further test your code in practice without having to learn how to use a new tool.

Debugger Menu

Toolbar Buttons

Hot Key










Step Into



Step Over



Step Out Of







These are the basic debug functions:

  • Reset the target, in order to restart the application.
  • Execute the code so the program can be tested to verify it functions as designed.
  • Halt the code at breakpoints
  • While halted at breakpoints examine and modify memory and variables to analyze and debug the application code.
  • Single Step through code to closely inspect how it executes. This allows the engineer to go through code one instruction (or one C statement) at a time while monitoring affected variables, registers and flags. Single stepping essentially “zooms in” on code to ensure that it operates correctly in complex and critical sections with ranges of variable values and under various test conditions.

Most debuggers also have additional features to help analyze and debug the application.

Some of these are listed here:

  • Watch points group and monitor selected variables and memory locations into a convenient, custom readout.
  • Trace buffers capture the streams of instructions executed and reveal the contents of changing register values.
  • A Stopwatch can time a section of code. Routines can be optimized, and critical code timing can be accurately measured and adjusted.
  • Complex breakpoints offer a method for establishing breakpoints or for gathering data in the trace buffer based upon multiple conditions. Simple breakpoints allow setting breakpoints in the source code or anywhere in program memory. Complex breakpoints allow getting a breakpoint on a condition such as,
       -  After the main routine called “Refresh Display” executes then
       -  wait for subroutine “Read Temp” to execute. Then
       -  break if the variable named “Temperature” is greater than 20.

Complex events can be constructed to count events, so that a subroutine would have to be executed, for example, 15 times before it starts looking for a value on a pin or in a register. This kind of breakpoint allows you to describe the condition where your code misbehaves, to halt at a breakpoint or to trace code when that condition occurs. This is usually a faster way of finding bugs than simply setting simple breakpoints and stepping through your code.

MPLAB SIM is a simulator, and as a result it has certain characteristics that make it a unique debug engine. So the speed of the simulation is determined by,

  • How fast your PC executes,
  • The complexity of the current simulation, and
  • The number of other tasks executing on your PC.

Currently the maximum speed of MPLAB SIM is on the order of 10 MIPS, or 10 million instructions per second. This will be affected by how many other things are being done by your PC, by the code the simulator is running, and by the other tasks that the simulator is performing. The simulator simulates the operation of,

  • The core CPU and its internal registers,
  • Memory, and
  • Many of it peripherals.

In order to test the application on the simulator, stimulus signals can be applied to pins and registers.

To evaluate performance, the simulator can log changing registers to files for further analysis.

Starting Up MPLAB SIM

Select the simulator as the debug execution tool. This is done from the Debugger>Select Tool pull down menu.


MPLAB SIM is selected as the debug engine from the Debugger menu. Note the other functions on the debug menu, such as Run, Step, and Breakpoints.

Once a debug engine is selected, the toolbar is appended with some new icons for running, halting, single stepping, and resetting the target.

The Status bar now shows some additional information.

  • MPLAB SIM shows as the current debug engine.
  • The simulated processor is listed, in this case the dsPIC30F4011,
  • Then the program counters,
  • The W register,
  • The current state of the internal CPU flags and
  • The current selected file register bank.


The toolbar icons, the menus, or the hot keys listed on the menus can be used to execute the debug functions. Note that some are a little more complex, such as Reset, which actually has four types of reset actions.


Once MPLAB SIM is established as the debug engine, whenever a project is built, it is automatically loaded into the simulator’s program memory to be run and tested.

One debug window is the source code window. This is actually the editor window, and breakpoints can be set by clicking on a line with the right mouse button. Single stepping with the source code window in focus will single step through the C source lines. Since you are in the editor, changes can be done quickly, and the project can be rebuilt.


The Program Memory window shows the machine code that will be executed by the simulator. Single stepping with this window in focus will allow you to step through each machine instruction.


Another window, called the Disassembly Listing window shows high level source code interspersed with machine code generated by each C statement.


You can also open up a watch window and drag the variables from your program to them to see the contents.

In order to see if the code is operating as intended, sending incrementing values out PORTC, watch the values being sent to PORTC.

Below are the menu items in the Disassembly window right mouse button menu.

  • Set or remove a breakpoint at the currently-selected line.
  • Enable/Disable a breakpoint at the currently- selected line.
  • Run the program to the current cursor location.
  • Set PC at Cursor Set the program counter (PC) to the cursor location.
  • Copy selected text to clipboard. Select text by (1) clicking and dragging mouse over text or (2) clicking at the beginning of text and shift-clicking at the end of text.
  • Select all text in the window.
  • Output to File.

Select View > Watch to bring up an empty Watch Window.

There are two pull downs on the top of the Watch Window. The one on the left labeled “Add SFR” can be used to add the Special Function Register, PORTC, into the watch. Select PORTC from the list and then click Add SFR to add it to the window.


While debugging, other windows are available to view,

  • register memory,
  • stack memory, and
  • Non-volatile data memory areas.

Simulator Stopwatch

The Stopwatch dialog can time a section of code as it run in the simulator.

The Stopwatch calculations are based upon the instructions executed and the setting entered for the Processor Frequency.

The processor frequency is set to 20 MHz in this example. From the number of instruction cycles executed, the total time is calculated.

This is the time it would take to run on a real chip.


The stopwatch has two pairs of readouts, one displays the total simulated clock cycles and the corresponding execution time, and the other can be zeroed out, to make a measurement from one breakpoint to the next. The stopwatch is one way to measure time in the simulator, but there is another:

Simulator Trace Analyzer

The trace buffer records instructions when they execute and puts a time stamp on each instruction. After events are captured in the trace buffer, the time stamp can be used to measure time between instructions.

The trace buffer has the advantage that it can capture large amounts of data selectively and each instruction has a time stamp. You can capture just the interrupt routine, for instance, and then easily calculate the time between interrupts and the total time each interrupt took to execute.

Simulator I/O

MPLAB SIM simulates the CPU core with the various microcontroller program, file and data memory areas.


Simulation includes pin inputs and outputs as well as many of the other peripherals.

The peripherals communicate to the application through special function registers.

A complex Stimulus Generator simulates signals that can be applied to the device under simulation.

The stimulus generator can send signals to pins or to registers in the simulator.

The activity of the simulator can be sent to a Log file for later analysis. This is done by using either the USART as a communication device for inputs and outputs, or by using the register log feature. Both stimulus and logging activity can be driven either by execution at a specified program counter address or by sequencing “on demand.”

“On demand” means that whenever that register is read by an instruction, a value is read or written to a list, then the next position in the list is queued up to be used for the next read or write operation.

Join the World's Largest Technical Community

we respect your privacy.