Getting started with MPLAB X

Microchip Technology Inc. (usually referred to as just Microchip on this website) manufactures the mid-range, 8-bit PIC® microcontrollers used in mirobo projects. Microchip also makes the MPLAB® IDE software used to create, edit, and debug programs for them, as well as the MPLAB® XC C language compilers that convert program source code into machine code for the microcontroller. If you are planning on learning PIC microcontroller programming, the easiest way to start is by using one of the versions of MPLAB.

MPLAB X, or MPLAB Xpress?

Microchip’s MPLAB® IDE software is available in two different versions: the one is the long-standing MPLAB X IDE computer program, available for computers running the Windows, macOS, and Linux operating systems; the second is the newer MPLAB Xpress cloud-based IDE.

MPLAB X is the latest version of Microchip’s original and fully-featured MPLAB IDE, and fully supports all of Microchip’s compilers, add-in software tools, and hardware programmers. The MPLAB X package includes both the IDE as well as MPLAB X IPE, a stand-alone programming tool, and must be paired with one or more separately-downloaded MPLAB XC compilers to generate program code for each of the major families of Microchip microcontrollers.

The cloud-based MPLAB Xpress runs in any modern web browser, including the browser in ChromeOS. While more limited in features and functionality, MPLAB Xpress enables users to compile programs using the latest compilers hosted in Microchip’s cloud service without needing to install or update any software. Click here to find out more about MPLAB Xpress.

Both the MPLAB X and MPLAB Xpress IDEs can easily create and compile programs for CHRP4 and UBMP4, so the IDE you choose to use for their programming activities will not make much difference. After learning the basics, moving on to developing and programming microcontrollers for your own circuit designs is currently easier to do using MPLAB X rather than MPLAB Xpress.

MPLAB X IDE

Advantages

  • MPLAB X is a stand-alone application – no internet connection is required during its use

  • programming project files are stored on your local computer, and cloud storage or version management using GitHub and other cloud-based systems is available

  • MPLAB X manages multiple programming projects with different architectures and compilers concurrently

  • many configurable options and customization settings

  • MPLAB X supports all of Microchip’s simulators and hardware programming/debugging tools

Disadvantages

  • one or more MPLAB XC compiler packs must be installed to build programs in the IDE, and both the MPLAB X IDE application and the XC compilers must be managed and periodically updated

  • MPLAB X is a large, complex program that takes a while to learn and can tax systems with limited storage and slower or older processors

  • MPLAB X updates have been out of step with system updates in the past (specifically on macOS), breaking MPLAB X or some of its features until MPLAB X was updated to support the new OS

MPLAB X is Microchip’s fully-configurable, do-it-all IDE. MPLAB X offers full support for all of Microchip’s hardware programming tools, a variety of software coding tools and simulation options, and rich support for hardware and software debugging. Many of these features and capabilities are either immature or currently unavailable in MPLAB Xpress.

Choose MPLAB X if you primarily code on a computer or need enhanced control of programming add-ons, support for multiple compilers, or if you want to be able to edit and update microcontroller-based devices in locations without a connection to the internet.

Programming Terms

IDE (Integrated Development Environment) - software used to manage all the files in programming projects, compile programs, and download the programs into microcontrollers.

Source code files - one or more human-written files making up a computer program.

Project - a collection of source code files, IDE configuration files, and output files making up a program.

Compiler - a computer program that converts program source code into processor-specific machine code, or an intermediate machine readable format.

Assembler - a computer program that converts low-level assembly language source code into processor-specific machine code.

Machine code - the processor-specific instructions that make up a program, encoded as binary data in the memory of a computer.

Object code - compiled source code in the form of machine-readable instructions representing all, or just parts, of a program.

Linker - a computer program that combines one or more object code files into a complete program.

Hex file - a file format representing the machine code instructions and their memory locations used by a hardware programmer to write the program into the memory of a microcontroller.

Programmer - a hardware device that can read and write the memory of a microcontroller to write and verify a program’s machine code instructions into its memory.

Bootloader - a software program running in a microcontroller that is capable of writing a user program into the memory of the microcontroller without over-writing itself.

Getting started

If you are ready to get started with MPLAB X, there are typically three ways you can proceed: 1 - open an already existing MPLAB X project, 2 - clone (or fork) an existing MPLAB X project from GitHub, or 3 - create a new MPLAB X project, either from scratch or from pre-existing source code files. Each method will be described below.

In programming-speak, a project is a more than just a program – it not only contains the project’s source code, but also all of the microcontroller configuration settings, compiler settings, debug settings, and programmer settings necessary for your program to be compiled and programmed into a microcontroller. So, users typically work within projects, rather than in individual programs, when programming microcontrollers.

Option 1 - Open an existing project

MPLAB X projects typically consist of a folder containing source code files, a makefile, and additional folders with information related to the project. MPLAB X project folders have a .X folder name extension. The contents of a sample MPLAB X project folder are shown here:

To open a project, start MPLAB X and choose the Open Project icon in the toolbar (it looks like an open folder containing a file and folder, third icon from left), or select Open Project from the File menu.

Choose the project folder from the Open Project dialogue box and click the Open Project button.

After the project opens, double-click the Header Files and Source Files organizers in the Projects panel at the upper left (or click the right facing arrows beside them) to open these and reveal the project source files inside them.

Double-click any of the source files to open them in a tab in the code editing window.

Option 2 - Clone an MPLAB X project from GitHub

Github is a cloud repository that many developers use to manage and share updates to their programs. GitHub repositories typically contain the newest versions of public programming projects, and make it easy to distribute these programs to other hobbyists and end users.

A GitHub account is not necessary to clone public projects, but is required to save projects back into GitHub. While learning GitHub to effectively use all of its features is beyond the scope of this activity, it’s relatively easy to clone an MPLAB X project from the mirobotech GitHub Repository.

Click the button for a step-by-step tutorial demonstrating how to clone a GitHub repository into MPLAB X.

Option 3 - Creating a new MPLAB X project

Developing a program for a new microcontroller circuit usually requires creating a new MPLAB X project. Occasionally, some part of an existing project can become corrupted, preventing the project from building properly. In both cases, a new MPLAB X project can be created either by using the existing files from a failed project build, or by copying files from a similar project to use as a starting point for making a new project.

You can download the source files to create a MPLAB X project for any mirobo circuit from the mirobotech GitHub Repository.

Click the button for a step-by-step tutorial demonstrating how create a new MPLAB X project.

Next steps…

Build the project

Compiling the program is referred to as building the project. Click the downward-facing arrow beside the Clean and Build icon (the hammer and broom) in the toolbar and select the Clean and Build Main Project option.

MPLAB X will start to compile the current program. After the build process completes successfully, the program’s compiled object file – with a filename ending in a .hex file extension – will be located in the project’s /dist/default/production/ folder along with other debug files.

Program your circuit

The easiest way to program CHRP4 and UBMP4 circuits is through the bootloader. See the uploading programs using a bootloader page on this site for more information on how to use the bootloader.

Save your MPLAB Xpress project to GitHub

Storing your project in a GitHub repository isn’t as easy as hitting a save button. The steps involved are commonly referred to as committing the changes, and then pushing the changes to GitHub. Git tools can be found in the Team menu in MPLAB X.

MPLAB® and PIC® are registered trademarks of Microchip Technology Inc. in the USA and other countries.