Academic Program

Modify main.c

Modify main.c

Step 10 - Timer0 will run until it overflows and then it will set a Timer Overflow Bit (T0IF) and keep running. The software routine just has to monitor that T0IF bit and when it's set, toggle the LED from OFF to ON or ON to OFF. Then software must clear the T0IF bit so it can be set again on the next overflow.

Add the following code to the end of the main.c file:

 while (1)
    {
        // Add your application code
        if (TMR0_HasOverflowOccured()) //Has Timer0 Overflowed?
        {
            D5_LED_Toggle(); //Switch state of D5 LED when overflow occurs
            TMR0IF = 0;      //Clear the Timer0 overflow flag
        }
    }

 

Note: The TMR0_HasOverflowOccured() and D5_LED_Toggle() functions are generated by the MCC and their definitions are located in the pin_manager.h file.

This is a simple example of how the MCC generates a library of useful functions to make creating project code much easier and quicker.

Step 11 - Click on Build Project (hammer icon) to compile the code; you should see a "BUILD SUCCESSFUL" message in the Output window of MPLAB X IDE.

Main_Build_Project.png


BUILD SUCCESSFUL (total time: 274ms)