Introduction

  • Timer0

(45 minutes)


Timer0

Interrupt is to stop execution of the microcontroller's program flow in order to execute a block of code called an interrupt service routine



Timers are some 8-bit or 16-bit registers whose content is incremented by a specific time interval.

After the value 111 ... 111 the timer takes the value 000 ... 000 (overflow). In this transition we can program an interrupt to occur.

Question:  Where do the pulses that increment the Timer value come from?

Answer: They can come from an external source and be applied to a specific pin of the microcontroller

Or come from a circuit inside the microcontroller called an internal oscillator (Oscillator)

In our program with a command we declare the source of the pulses that we want to be used




Timer0 is an 8 bit or 16 bit. If we want it to be used as an 8-bit timer, we should fill in the relevant parameter in the timer0 setup command.






Prescaler is a configurable clock-divider circuit. It can be used to divide the clock frequency input to the timer module. Prescaler’s values: 1, 2, 4, 8, 16, 32, 64, 128, 256


---------------------------------------------------------------------------------------------------------------------

enable_interrupts(INT_TIMER0);

// Enable interrupt from timer0

enable_interrupts(GLOBAL);

// enables (if set) all un-masked interrupts or disables (if cleared) all interrupts. 

----------------------------------------------------------------------------------------------------------------------


Calculation so that interrupts occur at a specific time interval, for example every 50 ms





This is the initial value that should be set to the Timer  so that we have interrupts every 50ms

   set_timer0(28035);