The purpose of this tutorial is to get you familiar with the MPLabX programming environment to program the PIC18F47Q10 microcontroller to flash a LED.
Item | Description |
---|---|
PIC18F47Q10 | |
Snap Programmer | A standalone programmer |
Breadboard | A breadboard set up for programming with the Snap Programmer (see this tutorial) |
LED | |
Resistor | Selected to limit current going through the LED |
3.3V Power Supply | Required to power the PIC |
Go to Microchip.com, and download MPLabX and the MPLab XC8 Compiler.
Follow all instructions and accept all defaults
Click Next |
Accept The License |
Accept Default Settings |
Select MPLabX and 8-bit MCUs |
Click Next |
Wait for the install to finish |
Say yes to install all device drivers |
Select MPLab XC8 Compiler |
Proceed through the XC8 Installer |
Accept the License Agreement |
Select the Free License |
Select Defaults |
You will want to make sure you check the “Add to Path” Option at this step:
Check the “Add to Path” Option |
Allow network access |
When you open MPLabX, you may see a notification to update plugins. Click the link.
Click on the notification to update your install |
If you want to manually initiate an update, go to “Tools” –> “Plugins”.
Select all updates and hit “update” |
In the first tab (“Updates”), select all available updates and then click the “update” button.
Walk through the dialog boxes
Restart the application if it asks. It will take a moment.
MPLabX Will restart |
Note: The MPLab Code Configurator is installed by default. The following steps detail how to install the plugin if it was not automatically installed.
After finish installing the MPLABX IDE, you can plug the USB mini cable into your programmer’s debugging port. Once you plug the USB to your PC, a green LED will light up. This indicates the programmer has been powered up.
To create a new project, go to “File” - “New Project” - select “Application Project” - and click “Next”
Create a New Project |
Select Microchip Embedded and “Application Project(s)” |
From “Family” select Advanced 8-bit MCUs (PIC 18) to filter the available list.
Select Device as “PIC18F47Q10” and click “Next”
If you have your Snap Programmer connected to your PC, the device will show up.
Select the Snap Programmer and click “Next”
Select the PIC and the Programmer |
Select the “XC8” as the compiler for this project.
Select the XC8 Compiler |
Next give a name to your first project as well as the location where you want to put your project.
Name your Project |
When your new project opens, the Microchip Code Configurator (MCC for short) should open. You will be asked whether to use MCC “Classic” or “Melody” (Melody is default, with “classic” offered at the bottom)
Select Melody |
Note: As of 2025, we recommend melody, as it is the more modern version of MCC, with more support planned going forward.
You will also be asked to install any missing packages. Go ahead and accept any and all suggestions when this screen pops up.
Update Content |
Content is downloading |
Content is downloaded |
Allow Netowrk Access |
<!-- ![caption](VirtualBox_Win11.2024_21_01_2025_09_27_05.png) -->
<!-- ![caption](VirtualBox_Win11.2024_21_01_2025_09_28_03.png) -->
MCC Layout |
To open MCC, select the blue MCC icon on the top ribbon of MPLabX’s IDE.
MCC Layout(colored) |
Application Builder (Center Area, magenta)
Graphical block diagram of all the system blocks that are available for configuration.
Pin Manager (Bottom Right Area, yellow)
Configure the direction (Input/Output), external interrupt, and PWM of GPIO pins in this area.
Pin Package View (Bottom Left Area, blue)
Indicates the pinout of the selected package type. Ensure you have selected the right package. (PDIP in our case)
Device Resources (Mid Left Area, red)
Peripherals (UART, PWM, I2C, SPI, etc) that available to the microcontroller.
Project Resources (Top Left Area, green)
The peripherals have been added/used in the microcontroller.
Resources Setups/ Register Setup (Top Right Area, cyan)
The detailed register set up for the selected peripheral.
Code Generate Button (Next to “Project Resources”, in the green area)
You will next turn on and off an external LED by using a GPIO pin on the Curiosity.
We are going to select pin RD1 for our LED’s digital output.
Double Click Pin Module under Project Resources.
Pin RD1 Configured |
Lock the Port A - Pin 2 to GPIO - Output.
Click the Generate button to generate code for the GPIO module.
Generate |
Configuration Complete |
The Code Configurator setup for Lab 4.1 should look like this, with the message of “Generation Complete”
Go back to Projects, you will see two subfolders called MCC Generated Files under both Header Files and Source Files. These folders contain the generated code, functions, and macros by MCC (Microchip Code Configurator).
The list of MCC generated functions or macro could be found at the header files. (A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files.)
pin.h functions |
Since we only use GPIO as our peripheral, we can double click the “pins.h” and see all the macros that MCC generated for us.
To enable the onboard LED, we can use the following macros (also highlighted at the screenshot below):
Macros | Purpose of the Macro |
---|---|
IO_RD1_SetHigh() | Set pin RD1 as logic High |
IO_RD1_SetLow() | Set pin RD1 as logic Low |
IO_RD1_Toggle() | Set pin RD1 opposite to the previous logic state |
Go back to the “main.c” and use the macros inside the main function.
main.c |
You can also add a delay function in order to see the on and off transition of the LED.
IO_RD1_SetHigh(); //Set RD1 (LED0) to logic high, turn on
__delay_ms(1000); //delay
IO_RD1_SetLow(); //Set RD1 (LED0) to logic low, turn off
__delay_ms(1000); //delay
Click the Hammer button to compile the project. If you see “Build Successful”, then you can flash the program to the microcontroller by clicking the Run or download button in the top ribbon.
Note: Another tutorial provides more detail regarding setting up an external programmer.