You are on page 1of 5

UNIT

IV
TIMERS IN INTEL 8051 MICRO
CONTROLLER
Timers are used to generate time delays and to count events in real time
applications executing on customized micro controller or micro processor based
hardware. By Interpreting the count value of a timer properly, many timer
applications can be realized in embedded and telecom domain. A basic timer
consists of a register that can be read from or write to by the processor/controller
and is driven by some freuency source.
Timer Operations of 8051
The !"#$ has two timers/counters, the can be used as either as
Timer to generate a time delay or as
%vent count to count events happening outside micro controller.
!"#& has a third timer' T&
(sed as interval timer )fosc/$&* or event counter )T"+,-.., T$+,-.# pins*
. operation modes for T", T$
(p+counting timer/counter
(se T/01 )!23*, and T405 )!!3* to set/control timer modes and operation
T6" )!A3*, T3" )!43*, T6$ )!B3*, T3$ )!13* contain timer current count
Both Timer " and Timer $ are $7 bit wide as shown in the 8gure $.
9ince !"#$ has an !+bit architecture each $7 bits timer is accessed as two separate
registers of lower byte and higher byte.
The lower byte register is called T6"/T6$ and higher byte register is called T3"/T3$
and accessed li:e any other register.
/.;a<endra ,rasad, Assoc. ,rofessor, %4% 1ept, =>IT
?igure $
Both timer " and $ use the same register, called T/01 )timer mode*, to set the
various timer operation modes. T/01 is a !+bit register as shown in the 8gure &.
The lower . bits are for Timer " and upper . bits are for Timer $. In each case the
lower & bits are used to set the timer mode and upper & bits to specify the
operation as shown in the 8gure &.
/.;a<endra ,rasad, Assoc. ,rofessor, %4% 1ept, =>IT

?igure &
/.;a<endra ,rasad, Assoc. ,rofessor, %4% 1ept, =>IT
Programming Intel 8051 timers
?or example the !"#$ based instruction /0= T/01, @&"h indicates that
mode & of timer & is selected.
Timers of !"#$ do starting and stopping by either software or hardware
control.
In using software to start and stop the timer when AAT% B ".
The start and stop of timer are controlled by way of software by the T;
)timer start* bits T;" and T;$.
The 9%TB instruction starts it and it is stopped by 46; instruction.
These instructions start and stop the timers as long as AAT% B " in the T/01
register.
The hardware way of starting and stopping the timer by an external source is
achieved by ma:ing AAT% B$ in the T/01 register.
/.;a<endra ,rasad, Assoc. ,rofessor, %4% 1ept, =>IT
E!MPLE" 1 #rite a s$% ro$tine to &reate a time 'ela( of )0 ms %(
ass$ming an os&illator r$nning at 1) M*+ &ontrols an Intel 8051 mi&ro
&ontroller,
Sol$tion"
STEP1' If 4/T B", then cloc: source to the timer $ B osc fre/$& B $& /3C/$& B $
/3C
STEP)' ?or &" ms delay the Timer register )T3$, T6$* value B $/$us D &" ms B
&","""
STEP-" Timer register )T3$ ET6$* value B7#,#-7+&","""B.#,#-7)d* BB$%" )3*
!L.ORIT*M"
STEP /" 4on8gure timer $ to operate in mode $ and choose the oscillator /$& as
cloc: i/p.
4/TB", AAT% B", T?$B"
STEP 5" ,lace value B$%"h into the timer $ register and wait until the overFow Fag
is set to $
Intel 8051 S$%ro$tine"
1%6AG' /0= T/01, @$"3 ///01% $, $7BIT TI/%;
46; T?$ // 46%A; TI/%; $ 0=%;?60H ?6AA
46; %T$ //46%A; TI/%; $ I5T%;;(,T ?6AA
64A66 1%6AG' /0= T3$, @B$3 // 9T0;% (,,%; BGT% 0? 40(5T
/0= T6$, @%"3 // 9T0;% 60H%; BGT% 0? 40(5T
9%TB T;$ // %5AB6% TI/%; $
HAIT' >5B T?$, HAIT //HAIT (5TI6 T?$ I9 9%T T0 $
;%T
/.;a<endra ,rasad, Assoc. ,rofessor, %4% 1ept, =>IT

You might also like