Académique Documents
Professionnel Documents
Culture Documents
SI
Port P0
T0 Timer Counter
WDT
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
A Timer
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Timer
A timer Example overflow
interrupt if
not
n-bit counter masked, an
ISR
executes
Example Overflows
after 2n
Clock Inputs period = 1 clock
µs inputs if
initial
for 12 MHz XTAL count bits
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
all 0s.
2005
A Counter
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Counter
A Counter Example overflow
interrupt if
not
n-bit counter masked, an
ISR
executes
Example Overflows
after 2n
Count Inputs from a count
source on the events inputs if
initial
count bits
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
set = all 0s.
2005
8051/8052 Timing/Counting Devices –
T1 and T0 and T2
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Outline
• Timers T1 and T0 and overflows,
masking and priorities of their
interrupts
• T2 (8052)
• Modes 0, 1, 2 and 3
• Timers Control and
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Timer-Counter T1/T0 SFRs Register
T1/T0 16-bit in SFRs T1/T0 16-bit in SFRs
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
TF1 and TF0 bit at
TCON.7 and
TCON.5 and a TF
T1/T0 Timer/Counter resets on an ISR
start
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Timer-Count T2 SFRs
T2 16-bit SFRs
TH2 TL2
CDH CCH
Write/Read upper bits
Write/Read lower
-ve edge inputs bits
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Six Timer2 Functions
RCLK
Timer Counter
16-bits TCLK 16-bits
Reload the Load
Input Capture
preset from
T2 16-bits at
value again SFRs
SFRs RCAP2H
on overflow RCAP2H
and RCAP2L on
and restart and
an external input
RCAP2L
edge
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
An Input Capture of Timer Timer
capture
Clock Inputs interrupt if
not
16-bit counter masked, an
ISR
executes
16-bit Capture
Register
An edge forcing coping of the
counter reading into Capture
Register if capture enabled
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
A Reload of Counter on an input
Count Inputs
Timer
reload
16-bit counter interrupt if
not
16-bit Load masked, an
Register ISR
executes
An edge forcing coping of the
into counter starting value from
Load Register if capture
enabled Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Reload-Capture T2 SFRs
T2 16-bit SFRs
RCAP2H RCAP2L
CBH CAH
Write/Read upper bits
Write/Read lower
-ve edge input bits
capture
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Outline
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Timer-counter T1 16- bits
timer-
8- bits counter
8- bits 8- bits
8- bits 8- bits
8- bits 8- bits
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
TMOD SFR at 89H T1 mode sets =
GT1 Gate C/T1 0, 1, 2 or 3 by
M1-M0
b7 b6 b5-b4 b3 b2 b1-b0
GT0 Gate C/T0
T0 mode sets = 0, 1, 2 or 3
by M1-M0
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
TCON: T1-T0 Control and status SFR
Flags TCON 8-bit SFR
TF1-TF0
at bit7- IT0-IE0 bit0-bit1
88H
bit5
Bit Addresses 88H-8FH bit5-bit4 set then
define the RCLK-
Write/Read
TCLK for SI baud
TR1-TR0 at bit 6-bit 4 rates using T2 else
run the T1-T0 T1 defines baud
IT1-IE1 bit2-bit3 rate
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Timer overflow Flags TF1-TF0 for
T1andT0 overflows
TCON.7 and TCON.5 show the flag
statuses
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Timer Run control TR1-TR0 for
T1andT0 run
TCON.6 and TCON.4 control the
running of T1-T0
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
IE0 bit = 1 at TCON.0 enable interrupt
and = 0 disables at INT0 (GT0) pin
IE1 bit = 1 at TCON.3 enable -ve edge
transition interrupt and = 0 enables level
0 interrupt at INT1 (GT1) pin
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Timer overflow Flag TF2 for T2
overflow
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
EXEN at T2CON.2 enables external input
capture or reload by -ve edge at P1.1
T2EX/INT2 pin
Timer Capture Flag EXF2 = 1 a -ve edge at
P1.1 causes input capture of T2 and T2 saves
at RCAP2H-RCAP2L provided EXEN control
bit is 1 and when CP/RL2 (T2CON.0) = 1
(defined for capture)
Timer Capture Flag EXF2 = 1 a -ve edge at
P1.1 pin forces the T2 reload from RCAP2H-
RCAP2L provided EXEN control bit is 1 and
when CP/RL2 (T2CON.0) = 0 (defined for
reload) Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005
Summary
Timer DevicesT0 andT1
• T0 functions in 4 modes
• T1 functions in 3 modes
Four modes are 8-bit mode with pre-
scaling by 32, 16-bit mode, 8-bit
auto reload mode and two
independent 8-bit timers mode
Timers T0, T1 and T2 Actions
• T0, T1 and T2 overflows and interrupts
• T2 captures 16-bit T2 in RCAP2H-
RCAP2L on a reload input
• T2 reloads 16-bit from RCAP2H-
RCAP2L on a reload input
• T2 controls RCLK-TCLK in place of T1
for SI device
End of Lesson 4 on
8051/52 Timing Devices –
T0, T1 and T2,
THANK YOU
Ch03L4-"Microcontrollers....", Raj
Kamal, from Pearson Education,
2005