Programming 8 bit PIC: MPLAB X IDE Guide for beginners

What is MPLAB X IDE?

MPLAB X IDE is a software program that runs on a PC (Windows®, Mac OS®, Linux®) to develop applications for Microchip microcontrollers and digital signal controllers. It is called an Integrated Development Environment (IDE), because it provides a single integrated “environment” to develop code for embedded microcontrollers.—BY MICROCHIP

Download and get started

Hence, to program and generate hex files for the PIC controllers this software is used. It can be downloaded from the Microchip website. Download the latest version here: MPLAB X IDE download.

We also need to download a 8bit compiler to compile our C program and generate a hex file. Its also known as XC compiler. Download 8 bit compiler from the microchip website. Link: XC8 compiler link. Note: You have to download MPLAB XC8 compiler which supports 8 bit microcontrollers.

Once downloaded all MPLAB X IDE and MPLAB XC8 compiler install it and get ready to program.

Steps to program and generate Hex file.

Note: I’ll be using PIC16F18446 8bit microcontroller. You can use any steps to generate hex file is almost same for PIC microcontrollers. 

We will write a simple LED blinking program.

Step1: Open MPLAB X IDE and download a plugin/ extension named as MCC Code Configurator. It helps us to generate configurations and header files. To download go to Tools>Plugins>Available Plugins> search and install MCC Code configurator. I have already installed and hence you see a green tick in Active.

Plugin mplabx
Plugin mplabx

Step2: Now go to File> New Project. Click Standalone project and then next.

New Project
New Project

Step 3: Select your 8 bit PIC Microcontroller. I have PIC16F18446. Click Next

Select Device
Select Device

Step 4: Select Simulator if you are using Xpress board or PICKIT3 if you are using this kit for programming. I am using Xpress board hence, selecting simulator.

Step4
Step4

Step 5:Select XC8 compiler and then click next. Give suitable name to your project and click finish.

Step5
Step5

Step6: Now you will see your project name containing different folders. Image shown below.

Step6
Step6

Step 7: Now you need a header file which will contain all initialization files and configuration files. To create the necessary files automatically go to blue MCC icon in the top bar. You will get a resource mcc window.

Click to the pin manager which is somewhere at the bottom left of the screen. You will see a below image on your screen. In my xpress board led is connected to the 2nd pin of Port A hence I have locked it to the OUTPUT. It changes colour to green.

Step7
Step7

Step8: Go to  project resources which will be on the left of your screen and click on generate to create your files. Check below image.

Step8
Step8

Step 9: After clicking generate give it some time to generate your files and then again check your project files. You can see files generated for your project.

Step9
Step9

Step10: Go to source files> main.c and write your code. See pin manager.h in MCC generated files to get some details about your pin configurations.

In my code IO_RA2_toggle() is used to toggle RA2 pin. __delay_ms(500) to give 500 milisecond delay. You can get this function from pinmanager.h

Step9
Step10

Step 11: After writing the code click the hammer icon which is to build the project and create .hex file. Check the build log to get the hex file path.

Step11
Step11

Now burn/ flash your microcontroller. I have created a guide to how to load the hex file to your PIC Xpress board. Also I have included the .hex file. Check the link below.

Load your hex file into PIC microcontroller

 

 

2 COMMENTS

  1. Hi
    When I complete step 6 and click on the blue MCC icon I get an error screen saying that I do not have the device library installed! and I can get the library from http://www.microchip.com/mcc. This is a very large website.
    Can you please point me to the correct library and where or how is it to be installed.
    The device selected in step 3 is a PIC12F675.

  2. Hello, I am getting your concern, currently for 8 bit MCUs there is already a pre loaded library named as pic10_pic12_pic16_pic18 something. You can download it from http://www.microchip.com/mcc > scroll down and click on current downloads. Unfortunately, your device is not supported by MCC. Check out the supported devices in the pdf given in this link. Go to section 10 in the pdf. http://ww1.microchip.com/downloads/en/DeviceDoc/release_notes_pic10_pic12_pic16_pic18_v1_65_2.pdf

LEAVE A REPLY

Please enter your comment!
Please enter your name here