Step 4: Add Application Code to the Project
Add Application Code to the Project
Once the project is generated, open the main.c file and add the following lines of code (inside while loop) after SYS_Initialize(NULL); inside the int main(void) function.

The LED1_Toggle() function changes the state of LED1. If LED1 is ON, it turns OFF and vice versa. This is how the LED is made to blink.
The value 1500000UL used in the for loop is selected to introduce a delay of approximately 500 ms when the microcontroller operates at a clock frequency of 48 MHz. The suffix UL denotes an Unsigned Long data type, which is capable of holding large integer values.
This value is chosen based on instruction execution analysis. The function LED1_Toggle() requires approximately six assembly instructions, while the loop for (int i = 0; i < 1500000UL; i++); requires approximately 11 to 12 assembly instructions. Together, this results in an estimated total of 18 assembly instructions per iteration.

The PIC32CM LS00 Curiosity Nano + Touch Evaluation Kit operates at a clock frequency of 48 MHz, meaning it executes 48 million instructions per second. For a 500 ms delay, approximately 24 million instructions are executed. Dividing this instruction count by the estimated number of assembly instructions per loop iteration (18) results in approximately 1,333,333 iterations. For simplicity and to ensure sufficient delay, this value is rounded up to 1,500,000.

