Mplab X IDE Tutorial For blinking an LED and Comparison with Mplab IDE

Mplab X IDE Tutorial with XC8 Compiler







Mplab X IDE and XC8 C Compiler

Mplab X IDE is the latest avatar of Mplab IDE which is provided by microchip. It is launched with better features, interfaces and is quiet advanced IDE then the old version of Mplab which were introduced in the past.

In this tutorial we will see some basic and advanced features and benefits while coding with Mplab X over the traditional Mplab IDE. With a Sample source code at the end of this post I will also show a comparison of the output hex files generated with Mplab IDE and Mplab X IDE.

Now a days developer IDE for any programming language are Hi-end, like visual studio or Eclipse which provides better interface and features, but Microchips older versions of IDE never had these features of autocomplete and suggestions while writing the codes. Hence this new avatar as MPLAB X settles these problems and the way it looks.

The Mplab X IDE uses its platform as Netbeans from oracle, Hence while coding with it might make you feel as if you are working on Netbeans IDE, because lots of Mplab X features are taken from Netbeans.

Features of Mplab X IDE Over Mplab IDE

MPLAB X IDE and XC8 Compiler tutorial

Before installing you might want to update java for the installation to run smooth.  Since its java based IDE now, so Mplab X is not limited to windows.

As a long awaited feature, Mplab X IDE is now available on Linux and Mac OS versions also, which can be easily downloaded from microchip’s website for free. So the programmer does not have to be confined to a windows computer only, as it was the case with old versions of Mplab IDE. Apart from better looks and interface, one of the most amazing thing which can be noticed is the size of output after compilation (the hex file).

After coding and compiling the sample codes from my previous tutorials, I found that the compiled output hex files by XC8 were way smaller in size than that of the output from old Mplab IDE and C18 compiler. Hence compiling with Mplab X can save a lot of space.

In traditional Mplab IDE you had to be selective about the type of the compiler, for the family of microcontroller you are coding. For Example: To code a PIC18F family microcontroller you needed C18 Compiler and for PIC16F microcontroller it was required to install a different Compiler Toolsuite. Hence now microchip integrated most of its different compiler toolsuite into one XC8 compiler for Mplab x which support all 8, 16 and 32 bit microcontroller family. Hence all you need is just to download the Mplab X and XC8 Compiler.

The older version of Mplab projects can still be imported into the latest Mplab X without any difficulty with project wizard.

Note: I will try to attach an Mplab X version of project file for download with each of my old tutorials which were done on Mplab IDE. Lot of programmer who have the habit of programming with old versions of IDE sometimes find it little difficult to work with latest Mplab X versions, But it is really not so hard, once you get to know it more.  In this tutorial we are going to use Mplab X IDE and XC8 Compiler to code our microcontroller.


PIC18F4550 Programming with MPLAB X IDE

Programming a PIC18f4550 with Mplab X IDE and XC8 Compiler , project

Before we start coding on PIC18F4550 with mplab X , we need to create a new project just like Mplab IDE.

Creating a project is easy in Mplab X, just open the IDE and proceed to project wizard from file menu. Select the microcontroller family or directly type the name of the microcontroller in the device name.

Then select the hardware tool from the list, if you have any programmer like pickit2 connected then select pickit2 or go with the defaults and click next.

Select XC8 C compiler from the list of compiler which I assume you must have installed after installing Mplab X IDE and finally type a project name – and you are ready for coding.

It will open a blank project, Now you can create a new source file from the project explorer by right clicking on Source File > New > C main File.

Select your desired Name, the extension must be C and then finally click finish. It will open a default source code template; you are ready for coding with Mplab X.

Start mplab X IDE from Linux Mplab x IDE C8 - Create new Project for PIC18F4550

Select the PIC18F4550 Microcontroller

Mplab X xc8 Simulator select Tool

XC8 Compiler select from the list of available Compilers for mplab x IDE

Project name for PIC18F4550 Blink led with mplabX ide and XC8 Compiler

Blinking LED with PIC18F4550 on Mplab X IDE and XC8 Compiler for beginners


Blinking an LED with Mplab X IDE and PIC18F4550

For testing the Mplab X IDE we are going to use the same source code from one of my previous tutorial where we coded a pic18f4550 with Mplab ide for blinking an led. We are just going to replicate our previous tutorial with a different IDE.

  -Create a New project and select device as "PIC18F4550" from drop down menu, and proceed with creating a new project with XC8 Compiler.

  -Create a New Source C file. And clean it up.

  -Copy the source code from previous post– Blinking an LED using pic18f4550.

  -Run > Build project.

If everything goes right then the output windows below will display a Build Successful message. The output window at the bottom will also show the location of .hex files which were just created. If you have a pickit2 attached then you directly burn the firmware into the microcontroller or  Navigate to the .hex file location which is usually,

            MplabProjectFoler/Projectname.X/Dist/Default/Production Folder

Search for the file with .hex in the production folder. If you have a pickit already attached then you can program directly or you can use other programmers to burn the output .hex file in to pic18f4550 microcontroller. The source code above should blink RB-0 and RB-1 alternatively with a dealy inbetween the two LED. The schematics are same as shown in my previous post.

Comparison of HEX files compiled with


Now as I have mentioned before that you will notice that the size of the .hex file be much more shorter when you compile with Mplab X then that of Mplab IDE. Hence here we are going to do a small practical Observation.

Project for blinking led with same source code, I first compiled it with traditional MPLAB IDE and the .hex file came out something like this for just blinking two led.

.HEX file compiled With Mplab IDE ( C18 )

















Now here is the .Hex file compiled with Mplab X ide with same source code for blinking two LED.

HEX file compiled With Mplab X IDE -XC8 Compiler











I hope you noticed the difference between the both .hex files. Hence Mplab X can really save a lot of space when you are dealing with really lengthy and complex codes where programmers have to take the size of the program into serious consideration.


Thanks for reading
Rakesh Mondal