AN2039-Adding a Timer

Using MPLAB® Code Configurator (MCC) to add Timer1 function to an application

With the project opened in MPLAB X, from the main menu, selectTools > Microchip Embedded > MPLAB Code Configurator.

pic1.png

After MCC opens, from theDevice Resources menu, selectTimer1 to bring it into theProject Resources window:

pic2.png

Click onTMR1 to edit and enter values to configure TMR1:

pic3.png

To configure the TMR1 for a 1-millisecond (mS) interrupt using the 16 MHz internal clock, edit the Time Period to1.0 mS, check theEnable Timer Interrupt box, and edit the Callback Function Rate to1.

pic4.png

Click theGenerate Code button for MCC to create code for TMR1.

pic5.png

Using the MCC, this method can be used to initialize and create functions for the Analog-to-Digital Converter (ADC), Pulse Width Modulation (PWM), GPIO, Flash Memory, and I²C.