Setup PIC Timer with Interrupt Example (18F Family, MikroC)

software development on PIC microcontroler

Setting up a PIC timer to the correct frequency can be a tricky business for the uninitiated Software Engineer (i.e. Me). So I was pretty happy when I came across this great on-line tool whereby you just type in your oscillator frequency and desired interrupt rate and it generates the setup code for you!

For example I have an 8Mhz clock and wanted a 1KHz interrupt on Timer0, I punched that in and the tool said I should use this set-up code:

Happy days!

Now there is a little more to defining the software interrupt handler and enabling the interrupt so I have included the code for a slightly more verbose example that configures and enables Timer0 via mikroC on the PIC18F25K22: