Step 5: Add Application Code to the Project

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

This example application is implemented on the PIC32CM LS00 Curiosity Nano board to study the behavior of different clock sources using the SysTick timer. An LED is toggled at a fixed interval, and the toggle behavior is monitored using the Data Analyzer. This setup allows you to observe and compare the system's behavior under different clock sources.

Add the following application code to the generated project for both the internal and external clock configurations.

Note: This code is used for both internal and external clock configurations. Add the code to your project, then proceed to Step 6: Build, Program, and Observe the Output.

Application Code for the Project

Open the main.c file in the non-secure project. Within the int main(void) function, add the function call SYSTICK_TimerStart(); immediately after SYS_Initialize(NULL);.

Code:
SYSTICK_TimerStart();

                           main.c file

The SYSTICK_TimerStart(); function starts the SysTick timer, which is used to generate delays in the application. Using this delay, the LED is toggled at a fixed interval.

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.

Add LED_Toggle(); and SYSTICK_DelayUs(100); sequentially inside the while(true) loop in the main.c file.

Code:
LED_Toggle();
SYSTICK_DelayUs(100);

                          main.c file

The LED_Toggle() function changes the state of the LED: if the LED is currently ON, it turns OFF, and vice versa. The SYSTICK_DelayUs(100) function generates a 100-μs delay using the SysTick timer, ensuring a controlled interval between each LED toggle.