Step 4: Add Application Code to the Project

Last modified by Microchip on 2026/06/26 07:36

This example application on the PIC32CM LS00 Curiosity Nano+ Touch Evaluation Kit demonstrates General Purpose Input/Output (GPIO) input handling. In this demo, application code is added to the created project to implement switch input handling with an LED as the output. Add the following code to perform the GPIO input handling operation.

Information

Tip: Press the CTRL key and left click on the SYS_Initialize function. The click will open the implementation for the SYS_Initialize function.

Application Code for the Project

Open the main.c file and add the EIC_CallbackRegister function call after SYS_Initialize(NULL); inside the int main(void) function. This callback registration enables the application to automatically execute a specified function when an external interrupt occurs, such as a button press.

​Code:

EIC_CallbackRegister(EIC_PIN_2, EIC_User_Handler, 0);

main.c file

EIC_CallbackRegister is the callback registration function, EIC_PIN_2 specifies the pin used to generate the interrupt, and EIC_User_Handler is the user-defined callback function. When an interrupt (switch press) is detected on EIC_PIN_2, the EIC peripheral automatically invokes the registered callback function to handle the event.

Note: The EIC_CallbackRegister registers an External Interrupt Controller (EIC) callback event handler with the EIC PLIB. The callback event handler is called by EIC PLIB when the switch is pressed.

Add the EIC_User_Handler function to the main.c file after the header files inclusions.

Code:

static void EIC_User_Handler(uintptr_t context)
{
    LED_Toggle();
}

main.c file

EIC_User_Handler is the callback function registered using EIC_CallbackRegister. When a switch press is detected, the external interrupt triggers this function, which toggles the LED state using the LED_Toggle() function. If the LED is OFF, it is turned ON, and if it is ON, it is turned OFF.

Back to Top