Module 4: Creating and Building a New Project With MPLAB® Code Configurator (MCC) Harmony

Last modified by Microchip on 2026/10/12 13:10

Overview

In this lesson, you will create a new embedded C project as in the previous module, but this time you will develop firmware using MPLAB® Code Configurator (MCC) Harmony.

Learning Objectives

Understand and apply the core embedded development workflow:

  • Creating a new embedded C project
  • Selecting device, toolchain and hardware
  • Using MCC to develop, build and run project code

Activity

Build and flash an MCC firmware project to the Curiosity Nano board.

Creating a New Profile

You may want to create a new profile for this MCC Harmony project. To do this:

Select File > Close Folder to close the current project.


Click the Manage gear button and then hover over Profile (name). To the right, you should see a list of existing profiles and, at the bottom, a link to the Profiles window. Click this link.

Profiles menu


In the Profiles window, click on New Profile. The new profile will be named "Untitled 1". On the right, change the Name to "mcc-harmony". Then view the options below and determine if you want to make any selections. Finally, close and save the changes.

New Profile name


Return to Module 2 to install MPLAB for VS Code® extensions for this profile.

Back to Top

Creating a New Project: Getting Started

Click on the Explorer icon Explorer Icon on the Activity bar.


When no project is open in VS Code, you will see buttons under Explorer. Click on Create MPLAB Project.

Explorer view


Other options to create an MPLAB X IDE project are:

  • In the Command Palette (Ctrl + Shift + P), enter MPLAB:Create Project
  • In the Command Palette (Ctrl + Shift + P), enter MPLAB: Welcome to open the Get Started with MPLAB walkthrough tab. Then under Welcome, click on Create or Import MPLAB Project and in the drop-down, click on Create New Project.

Back to Top

Creating a New Project: Setting up the Project

Once the request for a new project is made, a Quick Pick UI (drop-down menus) will open over the search/command palette requesting information that will be used to create the new project. Information about the PIC32CM MC00 Curiosity Nano board will be used here.

Give the project a name. Select a name that will identify the project, for example, "pic32cm-mc00-cnano-flash-led" instead of "Project1".


Select the Project Location. Choose the default location for this example.


Choose a device. For the PIC32CM MC00 Curiosity Nano board, the project device is the PIC32CM1216MC00032.


Select the Project Type. Application is the most common and will be used in this example.


Select the compiler. Choose the latest version of the MPLAB XC32 C/C++ Compiler.

Warning

Note: If you have not installed this compiler, go to Module 2.

Information

Note: The new project and related files will be displayed in the Explorer view.

Give the project time to download the correct Device Family Pak (DFP) and load all project files before proceeding.

New Project

Back to Top

Create Code Using MCC Harmony

The MPLAB Code Configurator (MCC) will be used to generate project code. In VS Code, MCC supports two content libraries:

  1. MCC Melody for:
    • 8-bit PIC® and AVR® microcontrollers (MCUs), and
    • 16-bit dsPIC® digital signal controllers
  2. MCC Harmony for:
    • All 32-bit Microchip MCUs and microprocessors (MPUs)

Since the project device is 32 bits, MCC will automatically select MPLAB Harmony for code development.

In the Command Palette (Ctrl + Shift + P), enter MPLAB MCC: Launch.


Then, use the Quick Pick UI to complete the MCC setup:

Select Create New MCC Config.

This creates a new MCC configuration file for the project. 

Select MPLAB Project.

The project name and path should already be displayed. 

Select Proceed With Default Values.

This uses the default MCC configuration settings.

MCC Harmony interface will open for developing the project configuration.

MCC Harmony interface

Back to Top

Set up a Timer to Flash the User LED

To flash the LED on the cnano board at a given rate will require:

  • A timer for a flash rate of 100 ms
  • Access to the LED to toggle on/off

Begin by clicking on Device Resource to display this section.

Device Resource section


Look in the MCC Harmony Libraries for a timer peripheral. For the project device, this would be a timer/counter (TC).

Click on the help button help for TC0 to open documentation that explains how to set up the TC.

TC0 setup


In the MPLAB Harmony Peripheral Libraries documentation:

Under the "Basic Timer/Counter" section, see the different operating modes available. Notice that there are also code examples for each.

Timer Mode will be used with the callback method so as not to have to poll continuously.


Click on the (+) next to TC0 to add it to the Project Graph. Then click on Expand All to see all the TC0 options.

The current timer is 1 ms. To get to 100 ms, a prescaler of GCLK_TC/256 will be used. Ensure that Enable Timer Period Interrupt is selected. Then click the Generate button Generate Icon.

TC options

View the project for added content.

Under config.mcc > src > config/default > peripheral, related peripherals are now added.

added related peripherals

In the config.mcc > src directory, a new main file generated by Harmony has been added.

Note that Harmony does not automatically delete previous main files. The original main file does not have any content that needs to be moved to the new file, so this file can be deleted.


Click on the new main file to open it in an editor window.

Return to the timer/counter documentation. If you closed it, click on the (?) for TC0 to open it again. Under the "Basic Timer/Counter (TC)" section, find the example code for the Callback method and copy it.

Callback method

In the editor window, select the code for the main() function, int main (void), and replace it with what you copied. The copied code is for TC3, not TC0, so change it by selecting Edit > Replace and Replace All.

timer setup

Back to Top

Specify How to Access the LED

To toggle the user LED, its connection on the Curiosity Nano board needs to be determined.

Go to the "PIC32CM MC00 Curiosity Nano Evaluation Kit" webpage. In the "Documentation" section, click on the "PIC32CM MC00 Curiosity Nano Users Guide" to download it.

Go to the "Schematics" section of the document. Find the pin associated with the User LED.

User LED pin


Now set up the pin for LED0 by selecting Plugins > Pin Configuration.

Plugins dropdown


In the Harmony Configurators window under Pin Settings, find pin PA23. Select the Function as GPIO and the Direction as Out.

Pin Settings tab


You can also enter a Custom Name (but don't use spaces). This name will be used to generate pin macros in plib-port.h.

For this example, the name LED was used. But if User_LED was used, it would produce #define User_LED_Toggle().

macros for LED pin


Close the window and then click the Generate button Generate Icon.


Now the editor no longer marks LED_Toggle() as an error.

LED_Toggle() in the editor

Back to Top

Build the Project

Ensure that the PIC32CM MC00 Curiosity Nano board is connected to the PC via a USB cable. See Module 2 for details.


In the Command Palette (Ctrl + Shift + P), enter "MPLAB CMake: Build" or click the build hammer icon Build Hammer. If you want details on the CMake Runner, in the Command Palette enter "Preferences: Open Settings (UI)".

Back to Top

Dev Tool Bits | Start Building (and Debugging) With MPLAB® Tools for VS Code®

This video has been cropped to discuss the building portion. To see the portion on debugging, go to Module 5.

Back to Top