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.
Step2: Now go to File> New Project. Click Standalone project and then next.
Step 3: Select your 8 bit PIC Microcontroller. I have PIC16F18446. Click Next
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.
Step 5:Select XC8 compiler and then click next. Give suitable name to your project and click finish.
Step6: Now you will see your project name containing different folders. Image shown below.
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.
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.
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.
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
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.
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.