Hello World - Light an LED


Hello World - MPLAB® Xpress Example

In this project, an LED (Light Emitting Diode) is turned on by the PIC16F18855 microcontroller using the Xpress development board platform. This is a great starting point for getting your Xpress board running.



Hardware Tools (Optional)

Tool About Purchase
MPLAB® Xpress
Development Board

Software Tools

Tool About Installers
Windows Linux Mac OSX
MPLAB® Xpress
Cloud Integrated Development Environment

Exercise Files

File Download
Windows Linux Mac OSX
Project and Source Files


The PIC16F18855 GPIO pin RA0, connected to LED D2 on the Xpress board, is setup as an output to control the LED.

The project uses:

  • PIC16F18855 Microcontroller: www.microchip.com/pic16f18855

To follow along with these steps, MPLAB® Xpress should be open and the user should be logged in so that the MPLAB Code Configurator plug-in can be used. The setup is described in the steps of this training module. You should see a screen similar to the one shown here to start.



Task 1

The MPLAB Xpress Development board should be connected to an available USB port on the host computer through a USB cable to the micro B connector on the board. Drivers should install successfully the first time the board is connected and may take a minute or so. The connection is shown in the picture. No other components are required.



Task 2

Create a new project in MPLAB® Xpress for a PIC16F18855 using the MPLAB Xpress Development Board. Instructions are below if this is your first project.


Task 3

Open the MPLAB® Code Configurator (MCC) under the Tools>Embedded>MPLAB Xpress Code Configurator menu of MPLAB Xpress.


A window will appear showing three steps. If you need the latest version of Java you can click on step one, otherwise click on the step two button to open the MPLAB® Xpress Code Configurator.


A file will automatically download in your browser similar to the picture shown. Click on that file to open it. This is a java application that will launch the MCC.


The process can take several seconds depending on your internet connection speed. Several windows may appear asking if you want to run the program. When the process is complete you will see a new screen appear, separate from the MPLAB Xpress IDE, that is the MCC control screen. In this screen you can select peripherals for your project, system setup for oscillator and other configuration settings, input and output selections for your device. When all of these are completed you can generate project code including a main.c file by clicking on the Generate button near the center top of the screen. All these generated files will be included in your MPLAB Xpress project.



Task 4

There are three default Project Resources associated with any MPLAB® Xpress project as shown here.
For this project we only need to setup the System Module and the Pin Manager. The Interrupt Manager will not be used so they can be left in their default state.

Let's start with the System Module settings.

  • System Module
  • Interrupt Manager
  • Pin Manager

When the System Module selection is highlighted in the Project Resources area the System Module settings will appear in the center of the MCC screen.


For this project select the following:
Internal Oscillator

  • Oscillator Select: HFINTOSC (1MHz)
  • HF Internal Clock: 4MHz
  • Clock Divider: 4


  • WDT Disabled, SWDTEN is ignored


Task 5

In the Pin Manager section select the pin RA0 Output by clicking on the blue unlock button, turning it to a green locked symbol.

  • System Module
  • Interrupt Manager
  • Pin Manager

The Xpress Board has RA0 connected to the LED D2. By making RA0 an output, the pin will control the LED.
Under the Easy Setup tab of the Pin Module section, you will see the output box already properly checked for the RA0 pin. It also allows you to change the name of the pin from IO_RA0 to a custom name such as "led".
At this step also check the box "Start High". This will drive the RA0 output pin high and light the LED.



Task 6

Click the Generate button in MCC to create the appropriate header and source files for this configuration.


Upon successful code generation the “Generation Completed” notification should appear. Select “OK” to close the window.

New MCC Generated header and source files should now be present in the Project window of the MPLAB Xpress IDE including a new main.c source file



Task 7

Click on the main.c source file in the Project pane to open the file and scroll through the code to locate the //Add your application code comment inside of the while(1) loop.


This is highlighted to show you where you can modify the code to create a custom application. Fortunately, in this example we don't need to add any code to control the LED because the MCC already set the pin high in the Pin Manager setup of Step 5. We had it initialize the RA0 pin to "Start High". This will keep it HIGH to light the LED. The initialization code generated by the MCC is in the pin_manager.c file. The LATA = 0x01; line highlighted in the code block shows that the Least Significant Bit (LSB) of the LATCH A (LATA) register is set to a 1. This will drive the corresponding pin HIGH which is the RA0 pin connected to the LED D2. This is how the LED will continually be driven to an on state.


Task 8

Compile and download the project .hex file by clicking on the Make and Program Device button at the top of the MPLAB Xpress IDE.



Task 9

Program the MPLAB Xpress board by dragging the project .hex file from the downloads section of the browser and dropping the file on to the Xpress drive.


The Programmer LED on the Xpress board should quickly flash from green to red and then back to green indicating that the .hex file was successfully programmed to the PIC16F18855.


The D2 LED will now be lit on the Xpress board.



The example shows how to control an I/O pin as an output to drive an LED on. The code shows how the MCC can generate initialization code so no additional code was required within the main.c file. Additional control of the LED can be performed by adding code to main.c under the while(1) loop. There are many I/O control macros established in the pin_manager.h file to make it easier to create that code.


This project can be the basis for building any project that requires an I/O pin to control a digital output signal. This can include various circuits such as transistor controlled relay or LED displays. This will form the basis of just about any microcontroller based project.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.