Update and Configure an Existing MHC-based MPLAB® Harmony v3 Project to MCC-based Project: Step 5
Step 5: Extend the application code in the project
The application is already developed (partially) and is available in the main_pic32mz.c file under <your_unzip_solution_folder>/getting_started_ext/dev_files/pic32mz_ef_curiosity_v2. The main_pic32mz.c file contains the application logic. It also contains placeholders that you will populate with the necessary code in the next step.
- Go to the getting_started_ext/dev_files/pic32mz_ef_curiosity_v2 folder and copy the pre-developed main_pic32mz.c file.
- Replace (over-write) the main_pic32mz.c file of your project available at <Your project folder>/pic32mzef_getting_started/firmware/src with the copied file.
Open main_pic32mz.c in MPLAB® X IDE and add the application code by following the steps below:
Under the main_pic32mz.c file, in function main, notice the call to function SYS_Initialize. The generated function SYS_Initialize initializes all the peripheral modules used in the application (configured through the MPLAB Harmony Configurator (MHC)).
Open the plib_gpio.h under Header Files > config > pic32mz_ef_curiosity_v2 > peripheral > gpio > plib_gpio.h and check the MCC-generated macros for LED3 and SW3 pins. The changes are shown in this image.
In the main_pic32mz.c function, after SYS_Initialize(), add the following code to register callback SW3 event handler.
GPIO_PinInterruptEnable(SW3_PIN);
Replace the SW1 registered callback event handler and add the SW3 registered event handler by adding the following code before the main() function in main_pic32mz.c
{
if(SW1_Get() == SWITCH_PRESSED_STATE)
{
currSwitchPressedState = SWITCH_1;
if (prevSwitchPressedState == currSwitchPressedState)
{
changeTempSamplingRate = true;
}
prevSwitchPressedState = SWITCH_1;
}
}
static void SW3_User_Handler(GPIO_PIN pin, uintptr_t context)
{
if(SW3_Get() == SWITCH_PRESSED_STATE)
{
currSwitchPressedState = SWITCH_3;
if (prevSwitchPressedState == currSwitchPressedState)
{
changeTempSamplingRate = true;
}
prevSwitchPressedState = SWITCH_3;
}
}
Add the below code to toggle the LED based on the Switch press event before the main() function.
{
if (currSwitchPressedState == SWITCH_1)
{
LED3_Set();
LED1_Toggle();
}
else
{
LED1_Set();
LED3_Toggle();
}
}
Replace the code LED1_Toggle(); with the below code to toggle the LED based on the Switch press event.
You are now ready to build the code.