3 Using and Operating TMR0 in 16-bit Mode while the Microcontroller is in Sleep

This example describes how to configure TMR0 in 16-bit mode and generate an overflow interrupt every ten seconds, using LFINTOSC as clock source. TMR0 will run while the microcontroller is in Sleep mode. A GPIO pin (the development board’s on-board LED) will be configured as output. When the interrupt occurs, the microcontroller is woken up and the LED is lit for 100 ms and then the microcontroller is put back to Sleep.

To achieve the functionality described by the use case, the following actions will have to be performed:

  • System clock initialization
  • Port initialization
  • Timer0 initialization
  • Interrupts initialization
  • Timer0 interrupt handling