Beruflich Dokumente
Kultur Dokumente
2
Course Outline
Week Topic
1 Introduction
8051Microcontroller
2
Architecture
3 Assembly Language
4 Assembly Language Contd.
Timers and Counters
5, 6 Serial Port
Interrupt
7 Design and Interface Examples
8086 / 8088 Microprocessor
8
Introduction and Architecture
9 Midterm Exam
10 Hardware and Design
11 Programming in Assembly
PIC 18 F Microcontroller
12
Introduction, Architecture, I/O Pins
13 Programming
14 Timers
15, 16 Peripherals of PIC 18F Microcontrollers
17 Revision
3
Organization
Introduction
Timers
Delay Generation
Measuring Time
Counters
4
Timers and Counters
2 Timers in 8051
T0
T1
5
Timers and Counters
Modes of operation are
2 Timers
Serial
Timers Counters
Port
Measure Generate
Time Time
6
Timers and Counters
Always counts up in any operational mode
Timer
Counter
Timer
Timer increments by 1 every machine cycle
Counter
Increments at every input pulse
9
Timers and Counters
Timer SFRs
10
Timers and Counters
Separate Registers TH and TL
High and Low byte of Timer
Timer 0:
TH0 TL0
(1 Byte) (1 Byte)
TIMER 0
Timer 1:
TH1 TL1
(1 Byte) (1 Byte)
TIMER 1
11
Timers and Counters
Bit Name Explanation of Function Timer
Configuring = 1 Timer will only run when INT1 is
Timers high. (Calculate Time between
7 GATE1 1
events)
= 0 for Timer1
13
Timers
14
Timers and Counters
Modes of operation are
2 Timers
Serial
Timers Counters
Port
Measure Generate
Time Time
15
Timers
Timer Operation
1. Configure timers (TMOD)
2. Initialize values (TH and TL)
3. Start and Stop Timer (TCON)
16
Timers
Using 8051 Timers TH0 TL0
(1 Byte) (1 Byte)
TH and TL contain the TIMER 0
value of timer
TH1 TL1
Timers count UP. This value (1 Byte) (1 Byte)
will be incremented by 1 every TIMER 1
machine cycle
When TH and TL have maximum value, next machine cycle would set
them both to ZERO.
Practice
What is the maximum value TH and TL (1 Byte each) can have?
17
Timers
Using 8051 Timers
TH0 TL0
(1 Byte) (1 Byte)
What is the maximum value TIMER 0
TH and TL (1 Byte each) can have?
TH TL
= FF FF = 65,535
18
Timers
Using 8051 / 8052 Timers
Maximum value of Timer TH0 TL0
(1 Byte) (1 Byte)
Registers= FF FF = 65,535 TIMER 0
Timer
Operation Timer
Value
(TH , TL)
Time
19
Timers
Timer Modes
20
Timers
Timer Modes
21
Timers
Timer Modes
65,535d
Mode 1 16 Bit Timer FF FFh
Commonly used
Counts up to FF FF and resets to zero
22
Timers
Timer Modes
Mode 2 8 Bit Timer
8 Bit Auto-Reload Mode
TH = Reload value
TL = Time Value Reset
Reload
Timer
Value
Value
23 Time
Timers
Timer Modes
24
Timers
Bit Name Explanation of Function Timer
Configuring = 1 Timer will only run when INT1 is
high. (Calculate Time between
Timers 7 GATE1
events)
1
Timer Mode
26
Bit Name Explanation of Function Timer
Timers = 1 for External Time
7 GATE1 Measurement 1
Configuring Timers = 0 for Timer 1
TMOD =1 Counter
6 C/T1 1
= 0 Timer
5 T1M1 Timer mode bit 1
Practice 4 T1M0 Timer mode bit 1
Timer 0 in Mode 1 = 1 for External Time
3 GATE0 Measurement 0
Timer 1 in Mode 2 = 0 for Timer 0
Timer Description =1 Counter
TxM1 TxM0 2 C/T0 0
Mode of Mode = 0 Timer
0 0 0 13-bit Timer. 1 T0M1 Timer mode bit 0
0 1 1 16-bit Timer 0 T0M0 Timer mode bit 0
8-bit auto-
1 0 2
reload
Split timer
1 1 3
27 mode
Timers
Configuring Timers
TMOD
Timer0 in Mode1
Timer1 in Mode3
MOV tmod,#00100001b
OR
MOV tmod,#21h
28
Timers
Controlling Timers
TCON
Bit Name Explanation of Function Timer
Timer 1 Overflow.
7 TF1 1
= 1 when T1 Overflows
Timer 1 Run.
6 TR1 = 1 Timer1 Runs 1
= 0 Timer 1 Stops
Timer 0 Overflow.
5 TF0 0
= 1 when T0 Overflows
Timer 0 Run.
4 TR0 = 1 Timer0 Runs 0
= 0 Timer 0 Stops
30
Timers
31
Timers
Using 8051 / 8052 Timers
How to run timers for a given time?
2 Timers
Serial
Timers Counters
Port
Measure Generate
Time Time
32
Timers
Using 8051 / 8052 Timers
How to run timers for a given time?
1. Select Timer Mode TMOD
2. Store a Value in Timer Register TH and TL
3. Wait for Timer to Over-flow or Reset TCON
33
Timers
Using 8051 / 8052 Timers
How to run timers for a given time?
1. Select Timer Mode
2. Set an appropriate Value in Timer Register
34 Time
Timers
Practice
Set P3.0 high for 0.05 seconds using Timer 0
35
Timers
Set P3.0 high for 0.05 seconds using Timer 0
36
Timers
Using 8051 / 8052 Timers
Set P3.0 high for 0.05 seconds using Timer 0
TH = 4Ch ; TL = 00h
37
Timers
Using 8051 / 8052 Timers
Set P3.0 high for 0.05 seconds using Timer 0
Timer Mode
Mode 1 = 16 Bit timer Mode can be used
TMOD = 0000 0001b
T1 T0
38
Timers
Using 8051 / 8052 Timers
Set P3.0 high for 0.05 seconds using Timer 0
MOV TMOD,#00000001b;
MOV TH0,#4Ch;
MOV TL0,#00h;
setb P3^0
setb TR0
39
Timers
40
Timers
Using 8051 / 8052 Timers
How to measure time between 2 events?
2 Timers
Serial
Timers Counters
Port
Measure Generate
Time Time
41
Timers
How to measure time between 2 events?
42
Timers
How to measure time between 2 events?
43
Timers
How to measure time between 2 events?
44
Timers
How to measure time between 2 events?
45
Counters
46
Counters
47
Counter
Counter
Frequency consideration
48
Counter
Counter
49
Acknowledgement
50