Unit-6 8051 Timer Counter and Programming Technical
Unit-6 8051 Timer Counter and Programming Technical
and Programming
Syllabus
Use of counter as timer,
Timer/Counters
operations, Time delay programs
and associated
in Assembly language/registers, Various modes of timer/counter
Embedded C.
Contents
9.1 Timers /Counters and
Associated Registers Winter-15,17,18, 19,
9.2 Various Modes of Timers/ Counter Summer-16, Marks 7
Operations
Winter-11, 15, 17, 18,
9.3 Programming Examples. Summer-16, Marks 7
Winter-08,10,11, 12,13,14,17,
9.4 Short Questions and Summer-08,10, 12,18,19, Marks 4
Answers
(9- 1)
Microprocessors and Microcontrollers 9-2 8051 Timer / Counter and Programming
8051 has two timers, timer 0 and timer 1. Basically both, timer 0 and timer 1are
16-bit registers. Since 8051 is an 8-bit microcontroller, each 16-bit register can be accessed
as low-byte register (TL) and high-byte register (TH). Fig. 9.1.1 shows the timer 0 and
in
timer 1registers. These registers can be accessed like other registers (A, B, RO, R1 etc.)
8051.
Timer 1 register Timer 0 register
THO TLO
TH1 TL1
(8 - bit) (8 - bit) (8 - bit) (8- bit)
Timer 1 Timer 0
Fig. 9.1.2 TMOD register
The TMOD register is responsible for configuring the timers for the following
operations :
Select Timer 0 to operate as a counter or timer
Select Timer 1 to operate as a counter or timer
Select the mode in which timer should operate.
MI, MO : These bits select the timer mode. There are four different modes of timer,
mode 0, mode 1, mode 2 and mode 3. All these modes are discussed in the further
section.
M1 MO
Operating mode
8-bit Tiner/Counter "THx" with "TLX's 5-bit prescaler.
1
16-bit Timer/Counter "THY" with "TLX" are cascaded;
there is no prescaler.
1
8-bit auto-reload Timer/Counter "THX" holds a value
which is to be reloaded into "TLx" each time it
overflows.
1
(Timer 0) TLO is an 8-bit Timer/Counter controlled by
the standard Timer 0 control bits. THO is an 8-bit
timer ony controlled by Timer 1 control bits.
(Timer 1) Timer/Counter 1 stopped.
C/T: This bit is cleared (C/T =0) for selecting 'timer operation and is
set (C/T= 1)
for selecting 'counter' operation.
GATE : Gating control when set. Timer/Counter "x" is enabled only while
is high and "TRx" control bit is set. When cleared Timer "x" is "INTX" pin
enabled whenever "IRX"
control bit is set.
b. Stop Timer 0
Solution : a) SETB TR1 ; starts timer 1 by setting TCON.6 = 1
b) CLR TRO ; stops timer 0 by clearing TCON.4 = 0
Review Questions
OSC +12
TR1
GATE Control
INT1 PIN
Both Timers in Mode 1 are 16-bit Counters As the count rolls over from all 1s to all
Os, it sets the Timer interrupt flag TF. The counted input is enabled to the Timer when
TR = 1and either GATE = 0 or INTÍ = 1. (Setting GATE = 1allows the Timer to be
controlled by extermal input NTI, to facilitate pulse width measurements.)
Timer 0 Mode 1 Programming
The Fig. 9.2.2 shows the timer control logic for timer 0 in mode 1.
THO TLO
OSC 12 (8 Bits) (8 Bits) TFO Interrupt
cT=0
TRO
GATE(TMOD.3) Control
INTO PIN
A time delay can be generated using mode 1 of the timer 0 using following steps :
1. Load TMOD register indicating timer 0 is used and mode 1 is selected.
7 6 5 4 3 2
TMOD X X X X = 01
OSC
2 cT=0
THO
(8 Bits)
TLO
(8 Bits) TFO Interrupt
TRO
Timer0 control logic when GATE = 0 and INTO =1
Fig. 9.2.3 Timer 0 in mode 1, no external hardware is used to start and stop timer
Timer 1Mode 1Programming
The Fig. 9.2.4 shows the timer control logic for timer 1 in mode 1.
TR1
GATE(TMOD.7) Control
NTTPIN
Timer1 control logic
Fig. 9.2.4 Timer 1 in mode 1
timer 1 using following steps :
A time delay can be generated using mode 1 of the
TMOD register indicating timer 1 is used and mode 1 is selected.
I. Load
3 1
6 5 4
7
= 10H
X
TMOD
count values.
2. Load TL1 and THIregisters with
3. Start the timer by setting TR1 bit= 1. target address instruction. When it
the JNB TF1,
flag (TF1) with
* Monitor the timer
is raised, get out of the loop.
0 with CLR TR1l instruction.
bit =
Stop the timer by clearing TR1
instruction.
6.
Clear TF1 flag with CLR TF1 external hardware is needed
software, no
of timer is done using
When start and stop
for same. It is illustrated in the Fig. 9.2.5.
the for knowledge
Microprocessors and Microcontrollers 9-8 8051 Timer / Counter and
Programming
TR1
Timer1 control logic when GATE 0 and INT1 =1
Fig. 9.2.5 Timer 1in mode 1, no external hardware is used to start and stop timer
Mode 2
Mode 2 configures the Timer register as an 8-bit Counter (TL) with automatic reload.
as shown in Fig. 9.2.6. Overflow from TL only sets TF, but also reloads TL with the
contents of TH, which is preset by software. The reload leaves TH unchanged.
Advantages and disadvantages of Mode 2
The disadvantage of mode 2 operation of 8051 timer is that it has only &-bit timer.
However, it has an auto-reloading capacity. It is an advantage of mode 2
8051 timer. This mode has many applications such as operation of
setting the baud rate in serial communication and so on.
generating periodic waveforms,
OSC TLO
(8 Bits) TFO Interrupt
CT=0
TRO
GATE(TMOD.3) THO
Control (8 Bits)
INTO PIN
TECHNICAL PUBLICATIONS - An up
thrust for knowledge
Microprocessors and Microcontrollers 9-9 8051 Timer / Counter and Programming
2. Load THO register with count value.
3. Start the timer by setting TRO bit =
1.
4. Monitor the timer flag (TFO) with the
JNB TFO. target address instruction. When it
is raised, get out of the loop.
5. Clear the TFO0 flag, with
CLR TFO instruction.
6. Go back to step 4. There is no
need to load THO register again since
auto-reload. Mode 2 1s
When start and stop of timer is done using
for the same. It is illustrated in the Fig. 9.2.7. software, no external hardware is needed
OSC
2 CT=0
TLO
(8 Bits) TFO Interrupt
TRO
Timer0 control logic when GATE = 0 and INT0 =1
THO
(8 Bits)
Fig. 9.2.7 Timer 0 in mode 2, no
external hardware is used to start and stop timer
Timer 1Mode 2 Programming
The Fig. 9.2.8 shows the timer control logic for
timer 1in mode 2.
TR1
GATE(TMOD.7) Control TH1
(8 Bits)
INTT PIN
TMOD X X X X = 20H
When start and stop of timer is done using software, no external hardware is needed
for the same. It is illustrated in the Fig. 9.2.9.
Osc 12 TLI
(8 Bits) Interrupt
TR
Timer1 control logic when GATE =0 and INT1 =1 THI
8 Bits)
Fig. 9.2.9 Timer 1 in mode 2, no external hardware is used to start and stop timer
Mode 3
Timer 1 in Mode 3 simply holds its count. The effect is the same as setting TRI = 0.
Timer 0 in Mode 3 establishes TLO and THO as two separate counters. The logic for
Mode 3 on Timer 0 is shown in Fig. 9.2.10. TLO uses the Timer 0 control bits : C/I,
GATE, TRO, INTO, and TFO. THO is locked into a timer mode (counting machine cycles)
and takes over the use of TRI and TF1 from Timer 1. Thus, THO now controls
the: Timer 1 interrupt.
The Table 9.2.1 summarizes the modes of timers.
OSC 12
1/12f osc
TLO
TF O Interrupt
cr+=1 (8 Bits)
TOPIN
TRO
GATE Control
INTO PIN
THO
1/12f osc (8 Bits) TF 1 Interrupt
Control
TR1
THO TLO
TFO
TOP3.4) (8 Bits) (8 Bits) Interrupt
cT=1
TRO
Control
GATE(TMOD.3)
INTO PIN
Counter0 control logic
Fig. 9.2.11 (a)
THO TLO
TOP3.4) (8 Bits) TFO Interrupt
CT=t (8 Bits)
TRO
4. When Gate bit (Bit 3) in TMOD register is set to 1, counter will run only if TRO is
set to 1 and the logic signal on external interrupt pin INTO is high.
7 5 4 3 2 1
TMOD
1 =05H
7 6 5 4 3 2 1
TCON = 10H
TR1
GATE(TMOD.7)
Control
NTI PIN
TR1
Counter1 control logic when GATE=0and INT1 =1
Fig. 9.2.13 (b)
7 6 5 3 2 1
TMOD X =50H
7 5 4 3 2
TCON
1 = 40H
Fig. 9.2.13 (c) Counter 1 control register settings for mode 1 operation
ounter in Mode 2
this mnode, counter is used in auto-reload mode instead of 16-bit counter. Rest of
Peraion is exactly same as that of Mode 1. The Fig. 9.2.14 (a) shows the block
agram of counter 0in Mode 2 and the Fig. 9.2.14 (b) shows the block diagram of
Dunter O0 in Mode 2 when GATE = 0and INTO =1
TECHNICAL PUBLICATIONS - An up thrust for knowledge
8051 Timer / Counter and Programming
9-14
MicroprOcessors and Microcontrollers
TLO TFO
(8Bits) Interrupt
TO(P3.4)
cT=0
TRO THO
Control (8 Bits)
GATE(TMOD.3)
NTOPIN
CounterOcontrol logic
Fig. 9.2.14 (a)
TRO
Solution:
MOVTMOD, #01100000B Initialize counter 1 in
Mode 2, O/T=1
MOV TH1, #0 Clear TH1
SETB P3.5 Make T1 input
START : SETB TR1 Start the counter
BACK : MOV A, TL1 Get the count from TL1
MOVP2, A Sent it to port 2
JNB TF1, BACK If TF1 =0repeat
CLR TR1 Otherwise stop counter 1
CLR TF1 Make TF1=0
SJMP START Repeat
Note When 8051 is powered up ports are configured as input ports. To make them
as
work as output port we have to send high output on it. Therefore, to behave T1
input P 3.5 is set.
Example 9.2.2 Wite a progtam to display counter Oon 7-segment LEDs Assume thut clock
input is connected to pin (P 3.4).
Solution :
MOV TMOD, #00000110
Initialize counter 0in
Mode 2, CT=1
MOVTHO, #00H Reset counter value
SETB P3.4
Make T0 as input
START SETB TRO Start counter 0
BACK: MOVA, TLO Get the count value
ACALL CONVBCD
MOV P2, A Send count value in BCD on port 2
JNB TFO, BACK If TFO =0repeat
CLR TRO
Otherwise stop counter 0
CLR TFO Make TFO=0
SJMP START
Repeat
CONVBCD :ADD A, #00H [Use DAA for
DA A BCD conversion]
RET Return to main program
"/
PO=0x00; / Make PO bits all zero
/ Wait for 1 sec /
DELAY():
thrust tor knowledge
TECHNICAL PUBLICATIONS An up
Microprocessors and Microcontrollers 9- 16 8051 Timer /Counter and Programming
void DELAY()
unsigned char i;
for(i=0; i<20; i++)
{
TMOD = 0x01; /* Configure timer 0 in mode 1 /
TLO = Ox28; /* Load count in TLO */
THO = Ox29; * load count in THO */
TRO = 1; /* Turn on TO */
while(TFO == 0); * Wait for TFO to rollover */
TRO = 0; /* tum off TO */
TF0 = 0; /* clear TFO */
void Delay(void)
25 x 1.0 us = 25 us
Total delay = 25 us x500x40 = 500 ms
Note Due to inclusion of for loop of Cin delay generation, the delay may be slightly
more than expected. To get a correct delay we can adjust delay loop count by
observing frequency of port 1.0 on oscilloscope.
Example 9.2.5 Write an 8051 C program to create a frequency of 2 kHz on pin P2.0.
Solution : Let us use mode 2 of timer1 to create the delay. Mode 2 is an &-bit auto
reload mode.
#include <reg51.b>
void Delay(void):
sbit portbit=P2^0;
void main(void)
{
while(1)
voÀd Delay(void)
auto-reload) */
TMOD= 0x20; * Timer 1, mode 2(8-bit
Th1(auto-reload value) */
/* load
TH1=-250;
TR1=1; /* turn on T1 */
up thrust for knowledge
TECHNICAL PUBLICA TIONS-An
Microprocessors and Microcontrollers 9- 18 8051 Timer / Counter and
Programming
whille(TF1==0); /* wait for TF1 to roll over */
TR1=0; /* turn off T1 */
TF1=0; /* clear TF1 */
Example 9.2.6 Two switches are connected to pin P1.0 and P1.1, respectively. Write an 8051
Cprogram to monitor switches and create the following frequencies on pin P2.0 according
switch positions.
SWi SWO Frequency
100 HHz
1 200 Hz
1 0 300 Hz
1 1 400 Hz
1f(sw1==1&sw0==1)
Delay(4);
}
}
yoid Delay(unsigned char c)
TMOD=0x01;
do
TL0=0x78;
THO=0xEC;
TRO=1;
whíle(TFO==0);
TRO=0;
TFO=0;
C=C-1;
whle(cl=0);
}
EC78H= 60536
Example 9.2.8 Assume that a 1 Hz external clock is being fed into pin TO. Write a C
program for counter 0 in mode 1 (16 bit) to count the pulses and display the THO and
TLO registers on Pl and PO, respectively.
Solution :
#Include <reg51.h>
void main(void)
Solution: To display the TLI count we must convert 8 bit binary data to ASCI.
##include <reg51.h>
void BinToASCII(unsigned char);
void main()
do
TRO=1;
value=TL0;
BinToASCII(value);
while(TFO= =0);
TRO=0;
TF0=0;
}
void BinToASCII (unsigned char value)
unsigned char Abyte, i,Q;
unsigned char RÊ31;
Abyte = 0XFB;
i=0;
do
Q=Abyte/10; /* divide by 10 *I
R[i]=Abyte%10; /* find remainder and save it */
Abyte=Q; /* save quotient as a number */
i= i+1;
}
void Time(unsigned char value)
{
unsigned char sec,min;
min=value/60;
sec=value % 60;
P0=sec;
P1=min;
Example 9.2.11 WNrite an 8051 Cprogram to generate a rectangula wave of 2 kHz with
60 % duty cyce in pin P1.2. Assume crystal frequency as 11.0592 MHz Use Timer 0
in mode-1 operation. Show delay calculations. GTU: Winter-11
0.5 msx 40
TOFF = 0.2 ms
100
12
Time for 1 T-state = = 1.085 us
11.0592 x106
0.3 ms
Count for ToN = = 276
1.085us
Count for ToFF = 184
Count to be loaded for TON = 65536 - 276 = 65260 = FEECH
THO = FEH, TLO = ECH
Count to be loaded for TOFE = 65536 -184= 65352 = FF48H
THO = FFH, TLO = 48H
#include <reg51.h>
sbit mybit = P2^1
void TOM1D (unsigned char) ;
void main (void)
while (1)
Review Questions
8. Explain mode-2 programming with neat sketch and specify the program steps.
9. In what way timer/counter mode 2 programming is different from mode and mode 1?
counter, also write the
10. Write the block diagram to show mode 2 operation of timer 1, as a
programming steps to perform the same.
0 in mode
11. Write an ALP or C program to generate a frequency of 100 Hz square wave, using timer
1. Assume crystal frequency = 11.0592 MHz.
12. What is advantages and disadvantages of mode-2 operation of 8051 timer when compared mode-1
operation ?
13. With regard to timers of 8051,
) Explain briefly the difference between the timer and counter operation modes.
iü) Indicate how to start/stop the timer if GATE Control is also used.
ii) Explain mode - 2 operation.
14 Explain the working of timer in 8051 using the configuration of TCON and TMOD registers.
Explain the difference between timer operation in mode 0 and mode 1.
GTU : Winter- 15, Marks 7
15. Explain all the bits of TMOD register and hence find the control word for selecting timer
mode 2. GTU : Summer- l6, Marks 7
16. Draw timer-1 hardware and explain mode-2 operation of timer-1. GTU : Summer-16, Marks 7
17. Explain mode 2 operation of timers in 8051 microcontroller. GTU : Winter- 17, Marks 3
18. List different modes of timers. GTU : Winter-18, Marks 3
Microprocessors and Microcontrollers 9-25 8051 Timer /Counter and Programming
T of clock = 12
11.0592>x 106
1.085 us
Example 9.3.4 Write an,ALPto generatesquare wave on pin P1.5 of 500 Hz(approximately)
with asubroutine toprovide utime delay of30.38 us using timer 0. Assume that crystul
frequency of 8051 is11.0592 Hz. GTU : Winter-10. Summer-10
Solution :
12 12
1.085 us
Crystal frequency 11.0592x 10
Number of counts for roll over = 30.38 us = 28
1.085 us
65536 28 = 65508 = FFE4H
.:. To get a delay of 30.38 we have to load TH0 = FFH and TLO = E4H
1
For square wave T = = 2 ms
500
TON = TOFF = T/2 = 1 ms
Thus we have call delay routine (1 ms/30.38 us) = 33 = 21H times
Program
MOV TMOD, #01 :Timer0, mode1
HERE : MOV TLO, #E4H :Load TLO = E4H
MOV TH0, #FFH ;Load THO = FFH
CPL P1.5 ;toggle P1.5
MOVRO, #21H ;Load count in R0
BACK: ACALL Delay ;wait for 30.38 us x 33 = 1ms
DJNZ RO, BACK
SJMP HERE
DELAY: SETBTRO ;start timer 0
AGAIN: JNB TF0,AGAIN :Wait for TFO to roll over
TECHNICAL PUBLICATIONS- An up thrust for knowledge
Microprocessors and Microcontrollers 9-27 8051 Timer / Counter and Programming
CLR TRO istop timer 0
CLR TFO ;Clear TFO
RET ; Retum
Example 9.3.5 Firnd the delay generated by timer 0 in the following code, Calculate the delay
generated excluaing the instruction overhead. What count has to be loaded in TLO and
THO if elay has to be increased to 25 msec ?
CLR P2.3
HERE : MOV TMOD, #01
MOV TLO, #3Eh
MOV THO, #0B8h
SETB 1EO,
AGAN: JNB TF0, AGAIN
CLR TFO
GLR TRO
CLR P2,3
Solution :
Timer count = B83E
(A5FE)H=(42494),10
65536 - 42494 = 23092
23092 x 1.085 us = 25 ms
500 ms = 25 ms x 20
750 ms = 25 ms × 30
void Delay ()
unsigned char i;
for(i=0; i<20; i++)
TMOD = 0X01: /* Timer 0 in mode 1 */
TLO = 0X28: /* Load count in TLO */
THO = 0X29 * Load count in THO */
TRO = 1; * Tun on TRO /
while (TF0==0); /* Wait for TFO to rollover*/
TR0=0; /* Tum off TO *|
TF0=0; * Clear TFO */
}
Assume crystal frequency= 12 MHz
12
T = = 1us
12x10-6
50 ms
Count to get a delay of 50 ms = = 50000 clocks
1 us
Count = 65536 - 50000 10536 = 2928 H.
To get a delay of 1 sec we have to repeat delay of timer., 20 times (1/50 msec = 20).
Example 9.3.8 Find out Hex. number to be loaded in THO, to produce delay of 4.096 msec in
mode 0 operation. Assume clock frequency of 12 MHz.
Solution : Timer clock frequency Crystal frequency + 12 = 12 MHz + 12
1MHz
Maximuum count in mode 0 is 1FFFH (8191) and we have to count for 4096 counts to
get a delay of 4.096 ms
Count to be loaded in timer is 1FFFH
(8191 in decimal) - 4096 = FFFH (4095 in decimal)
FFH in TLO.
Therefore, We have to load OFHin TH0 and
frequency of 10 kHz on
ple 9.3.9 Using autoreload mode of timer 0in 8051, generate a
pin P1.0. Write assembly language program for it.
for knowledge
TECHNICAL PUBLICATIONS- An up thrust
Microprocessors and Microcontrollers 9-30 8051 Timer / Counter and Programming
of 10 kHz, one
Solution:Assume XTAL frequency = 12 MHz. To generate a frequency
MHz we have cycle
half of the cycle is of period 0.05 ms. Since XTAL frequencyto =50.12Thus the initial value
period is lus. Therefore, we have to decrement count equal
to be loaded in THO = (256 - 50) = 206.
Program
MOV TMOD,#2H :Timer 0, mode 2 (8-bit auto reload)
MOV THO,#206 ;THO = 206
SETB TRO ;Start timer 0
BACK: JNBTF1, BACK ;Stay till timer rollsover
CPL P1.0 :Complement P1.0
CLR TFO ;Clear timer flag 0
SJMP BACK :Continue
and OFF connected
Example 9.3.10 Nrite an assembly anguage program to make LED ON
to P 1.0 continuously with ON tine 20 msec and off time 40 msec.
*******88
Solution:
12
= 1.085 m sec
11.0592x106
Count to be loaded in THO: TLO = 7msec
= 6452 (Decimal)
1.085 sec
65536 - 6452 = 59084= E6CCH
ORG 0000H ;Starting address
START: MOV TMOD, #01H : Timer 0, mode 1
MOV TH0, #OE6H:Load timer count
MOV TLO, #0CCH
SETB P0.5 ;Make P0.5 HIGH
ACALL DELAY7MS :Wait for 7 msec (ON period)
CLR PO.5 ;Make PO.5 LOW
ACALL DELAYZMS ;Wait for 21 msec (OFF period)
ACALL DELAY7MS
ACALL DELAY7MS
SJMP START ;Repeat
DELAYMS: SETB TRO ;Start Timer 0
HERE : JNB TF0, HERE ;Wait for timer roll over
CLR TRO Tum OFF Timer 0
CLR TFO ;Clear TFO
RET :Retum
Example 9.3.12 Wite an assembly nguage progrm to generate a squrewave of frequency
JkHz on pin P30 using auto reload modeoftimer 0 in 8051.
Solution : For 5 kHz T = 1/5 kHz = 200us and T/2 = 100 us
Assume clock frequency 12 MHz so time for one cycle is 1 us. So the value of THO
and TLO is 255 - 100 = 155
ORG 0000H
MOV TMOD, #02H Timer 0 in mode 2
MOV TH0,#155 THO = 155
SETB TRO Start timer 0
HERE: JNB TFO, HERE
CPL P3.0
ORG 001BH
CLR TFO
SJMP HERE
Show
Example 9.3.13 Write program to generate delay of 0.25 ms sing timer-1 în mode 2.
GTU : Winter-12, Marks 7
necessary calculation.
knowledge
TECHNICAL PUBLICATIONS An up thrust for
9-32 8051 Timerr/ Counter and
Microprocessors and Microcontrolers
Programming
Solution :
MOV TMOD,#20H
MOV TH1,#-06H
SETB TR1
HERE : JNB TF1, HERE
Delay calculations : Assume XTAL frequency = 12MFiz
T = 12/12 MHz = 1us
256 - 250 = 06
Example 9.3.15 Write program to count external pulses and save t in register R6 and RI.
User timer 1, 16-bit mode, GTU : Winter-13, Marks 7
Solution:
MOV TMOD, #01010000B ;Counter 1, mode 1; C/T =1 extemal pulses
MOV TH1, #0 ; Clear TH1
MØV TL1, #0 :Clear TL1
SETB P3.5 ;Make T1 input
AGAIN: SETB TR1 : Start the counter 1
Void T1M1Delay(void)
TMOD=0x10
TL1=0X FE;
/*Timer1,mode1*/
/*Load TL1*/
TH1=0x A5; /*Load TH1*/
TR1=1; *Tum ON Timer1*/
while(TF1==0); /*wait for TF1 to roll over*/
TR1=0; /*Tun OFF Timer 1*/
TF1=0; /*Clear TF1/
TECHNICAL PUBLICATIONS -An up thrust for knowledge
Microprocessors And Microcontrollers 9- 35 8051 Timer /Counter and Programming
Time delay given by one roll over =65536x 5.4545x 10- = 0.0358 sec
1sec
:. Multiplier count = = 28
0.0358 sec
Example 9.3.21 What is the minimum and maximum frequency of square
wave that can be
generated at any port of 8051 microcontroller using crystal frequency of 12 MHz ?
GTU: Winter-17, Marks 3
12
Solution : T = = 1us
12x10-6
For maximum frequency : Use mode 2 and
load count = 255
256 - 255 = 1 and
To generate delay of 10 us
Count 10s = 10
lus
Count to be loaded = 65536 - 10 = 65526 = FFF6H
THO = FFH and TL0 = F6H
Example 9.3.23 Find control word to be
loaded in timer registers THO and TLO to generate
time delay of 25 ms Assume clock frequency as 11.0592 MHz.
GTU: Summer-19. Marks 4
Solution : Given : 11.0592 MHz clock
12
T= = 1.085 us
11.0592x106
To generate delay of 25 ms
25 ms
Count = = 23041
1.085us
Count to be loaded = 65536 - 23041 = 42495 = A5FFH
THO = A5H and TL0 = FFH