Upload
chanchal-rawat
View
216
Download
0
Embed Size (px)
Citation preview
8/12/2019 WB_RP
1/5
UNITIV
TIMERS IN INTEL 8051 MICROCONTROLLER
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 8051The !"#$ 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 T01 )!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.
.;aIT
8/12/2019 WB_RP
2/5
?igure $
Both timer " and $ use the same register, called T01 )timer mode*, to set the
various timer operation modes. T01 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 &.
.;aIT
8/12/2019 WB_RP
3/5
?igure &
.;aIT
8/12/2019 WB_RP
4/5
Programming Intel 8051 timers
?or example the !"#$ based instruction 0= T01, @&"h indicates thatmode & 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 AT% ".
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 AT% " in the T01
register.
The hardware way of starting and stopping the timer by an external source is
achieved by ma:ing AT% $ in the T01 register.
.;aIT
8/12/2019 WB_RP
5/5
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 ", then cloc: source to the timer $ osc fre/$& $& 3C/$& $
3C
STEP)' ?or &" ms delay the Timer register )T3$, T6$* value $/$us D &" ms
&","""
STEP-" Timer register )T3$ ET6$* value 7#,#-7+&","""#,#-7)d* B$%" )3*
!L.ORIT*M"
STEP /"4on8gure timer $ to operate in mode $ and choose the oscillator /$& as
cloc: i/p.
4/T", AT% ", T?$"
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= T01, @$"3 //01% $, $7BIT TI%;
46; T?$ // 46%A; TI%; $ 0=%;?60H ?6A
46; %T$ //46%A; TI%; $ I5T%;;(T ?6A
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
.;aIT