Lecture-6 (Microprocessors and Microcontrollers)
Lecture-6 (Microprocessors and Microcontrollers)
Microcontrollers
(EE-231)
Main Objectives
Using a Look-up-Table for ASCII
Check-Sum Byte
8051 Timers
Timer 0 & 1 Modes
Mode 1 Programming
Mode 2 Programming
1.
2.
1.
2.
3.
To ensure the integrity of the ROM contents, every system must perform
the checksum calculation
The process of checksum will detect any corruption of the contents of
ROM
The checksum process uses what is called a checksum byte
The checksum byte is an extra byte that is tagged to the end of series of
bytes of data.
To calculate the checksum byte of a series of bytes of data
Add the bytes together and drop the carries
Take the 2s complement of the total sum, and it becomes the last byte of
the series
To perform the checksum operation,
add all the bytes, including the checksum byte
The result must be zero
If it is not zero, one or more bytes of data have been changed
8051 Timers
TMOD Register
Both timers 0 and 1 use the same register, called TMOD (timer mode),
to set the various timer operation modes
TMOD is an 8-bit register
The lower 4 bits are for Timer 0
The upper 4 bits are for Timer 1
In each case,
The lower 2 bits are used to set the timer mode
The upper 2 bits to specify the operation
TMOD Register
TMOD Register
Example
a)
T0 mode 1 T1 mode 0
b)
c)
Gate Control
Timers of 8051 do starting and stopping by either software or hardware
control
when GATE=0, We use software (instructions) to start and stop the
timer
The start and stop of the timer are controlled by way of software by the
TR (timer start) bits TR0 and TR1
The SETB instruction starts it, and it is stopped by the CLR instruction
These instructions start and stop the timers as long as GATE=0 in the
TMOD register
The hardware way of starting and stopping the timer by an external
source is achieved by making GATE=1 in the TMOD register
Gate = 0
Gate = 1
TMOD Register
Example
Find the value for TMOD if we want to program timer 0 in mode 2, use
8051 XTAL for the clock source, and use instructions to start and stop
the timer.
Ans:-
Mode 1 Programming
1.
Mode 1 Programming
Example
Mode 1 Programming
Example
Mode 1 Programming
Example
Mode 1 Programming
Example
Mode 1 Programming
Example
Mode 1 Programming
Example
1.
2.
3.
4.