You are on page 1of 12

Overview

Timers

TIMERS
PIC16F877A has 3 Timers Timer 0 - 8 bit can be used as a Timer/counter Timer 1 16 bit can be used as a Timer/counter Timer 2 8 bit Timer can be used as the PWM time-base for the PWM mode of the CCP module.

Timer 1
The data registers of Timer 1 are TMR1H and TMR1L. The 16 bit value to be loaded in the timer is given to Data registers The Control register is T1CON. The timer ON and oscillator enable operations are controlled through the control register. To determine if the timer has completed its operation, the timer overflow bit TMR1IF of the PIR1 register is checked continuously.

How to calculate data value

Data Value=65535-(time in micro second/PS) PS= Pre-scalar value Eg: for 1 milli second time

1msec=1000microsecond PS=8; DV= 65535-(1000/8)


=

0xFF82

Configuring timer1 for 1msec delay


GIE=PEIE=TMR1IE=1;// enabling interrupt T1CON=0x39;// configuring control bits 0b00111001 TMR1H=0xFF;// upper register data TMR1L=0x82//lower register data

TIMER2

Timer 2
The data register of Timer2 is TMR2. The 8 bit value to be loaded is loaded in Timer2 register. The control register is T2CON To determine if the timer has completed its operation, the timer overflow bit TMR2IF of the PIR1 register is checked continuously.

How to calculate data value

Data Value=255-(time in micro second/PS) PS= Pre-scalar value Eg: for 1 milli second time

1msec=1000microsecond PS=16; DV= 255-(1000/16) =193.

Configuring timer2 for 1msec delay


GIE=PEIE=TMR2IE=1; T2CON=0x07; TMR2=193;

Thank you

You might also like