When I was reading the timer interrupt, the question came up, why do you need timer interrupt?
I am looking reason why should we use timer interrupts in project
Suppose we can bake a bread in a microwave oven for five minutes. If you bake bread more than five minutes, it will start burn.
Is it useful to use timer interrupt in this requirement?
It's useful because you can easily create an RTC (Real Time Clock) using timer interrupts - if you use a 32KHz crystal (often an option on TMR1) you can generate an interrupt every second, you then count those, and every 60 seconds increment the minute counter and zero the seconds, then do the same for hours, days, months etc.
For the 5 minute oven timer you just set a countdown clock - just like my code above - except you're counting down in seconds and minutes, not milliseconds.
If you're not using a 32Khz crystal, then it's often difficult (if not impossible) to get a direct one second interrupt - the section of my code above runs at 64MHz, and the ISR is driven by one millisecond interrupts from a timer - it does at least three things -
one it keeps a running count of milliseconds in a large variable,
two it runs the countdown code above,
three it increments another millisecond counter that it resets every thousand counts (so only an unsigned int) and creates a one second clock, which in turn creates a one minute clock etc. for an RTC.
Because there's a 'one second' section in the ISR, that's a good place to put an alarm test - so your RTC could be compared to an alarm time and date, and trigger an action when it happens (by setting a flag that's tested for in the main code).