Unit 3.pptx
Unit 3.pptx
TH1 TL1
Timer1 Timer0
March 28, 2025 19
These are I/P signals to internal timer-0 / 1 circuit.
External clock pulses can be connected to
8051 Pin Diagram
timer-0 /1 through these I/P signals.
Port3 (Pin 10 to 17): Dual Functions
15 (T0):
Pin 14 (T1):
Timer/ Counter 01 external input
P3 Bit Function Pin
P3.0 RxD 10
P3.1 TxD 11
P3.2 INT0 12
P3.3 INT1 13
P3.4 T0 14
P3.5 T1 15
P3.6 WR 16
P3.7 RD 17
TMOD Registers
MSB LSB
GATE C/T M1 M0 GATE C/T M1 M0
Timer1 Timer0
Timer1 Timer0
M1 M0 Mode Operating Mode
0 0 0 13-bit timer mode
8-bit timer/counter THx with TLx as 5-bit prescaler
0 1 1 16-bit timer mode
16-bit timer/counter THx and TLx are cascaded; there is no prescaler
1 0 2 8-bit auto reload
8-bit auto reload timer/counter; THx holds a value which is to be
reloaded TLx each time it overflows
1 1 3 Split timer mode
March 28, 2025 22
March 28, 2025 23
Prescaler
• A prescaler is a divider circuit that reduces the frequency of the input
clock signal before passing it to the timer/counter.
• Function:
• It divides the clock frequency by a fixed factor (e.g., 2, 4, 8, 32, etc.).
• This allows the timer to count slower, which helps in generating
longer delays without needing an extremely high timer count.
•Since TLx counts 32 ticks before updating THx, the effective
timer input frequency becomes:
•1MHz/32=31.25kHz
•For 31.25 kHz:
•T=1/31.25 kHz=1/31250≈32 microseconds
•Every 32 microseconds, TLx overflows and increments THx by
1.
TMOD Registers
Indicate which mode and which timer are selected for each of the
following.
(a) MOV TMOD, #01H GATE C/T M1 M0 GATE C/T M1 M0
(b) MOV TMOD, #20H Timer1 Timer0
(c) MOV TMOD, #12H
Solution:
We convert the value from hex to binary.
a) TMOD = 00000001, mode 1 of timer 0, mode 0 of timer 1 is selected.
b) TMOD = 00100000, mode 0 of timer 0, mode 2 of timer 1 is selected.
c) TMOD = 00010010, mode 2 of timer 0, mode 1 of timer 1 is
selected
March 28, 2025 26
TMOD Registers
Find the timer’s clock frequency and its period for various
8051-based systems, with the crystal frequency 11.0592 MHz when
C/T bit of TMOD is 0.
If C/T = 0, it is used
as a timer for time
delay generation.
The clock source for
If C/T = 0, it is used XTAL
the time delay is the
as a timer for time
÷12
crystal frequency of oscillator
delay generation.
the 8051 1/12 × 11.0529 MHz = 921.6 MHz;
The clock source for
the time delay is the T = 1/921.6 kHz = 1.085 us
crystal frequency of
the 8051
XTAL TH TL TF
÷12
oscillator
TF goes high Overflow
TR
C/T = 0 when FFFF → 0 flag
XTAL TH TL TF
÷12
oscillator
TF goes high Overflow
TR
C/T = 0 when FFFF → 0 flag
March 28, 2025 36
Mode 1 Programming
❑ To generate a time delay
1. Load the TMOD value register indicating which timer (timer 0 or
timer 1) is to be used and which timer mode (0 or 1) is
selected
2. Load registers TL and TH with initial count value
3. Start the timer
4. Keep monitoring the timer flag (TF) with the JNB TFx,target
instruction to see if it is raised
▪ Get out of the loop when TF becomes high
5. Stop the timer
6. Clear the TF flag for the next round
7. Go back to Step 2 to load TH and TL again
March 28, 2025 37
Mode 0
•13 Bit timer mode
•8 bits THx
•5 bits of TLx
Mode 3
• Mode 3 (Split Mode) is only valid for Timer 0.
• When the Timer0 is working in mode 3.
• THO is controlled by TR1.
• TLO is controlled by TR0.
• The TH0 is used as an 8-bit timer but not the counter. This is
controlled by Timer1 Control bit TR1.
• When the TH0 overflows from FFH to 00H, then TF1 is set to 1.
• When TLO overflows , TF0 is set to 1.
SCON register