8051 2018 Lec6
8051 2018 Lec6
8051 2018 Lec6
Microprocessor 2021
Timer0 & Timer1
Timer0
• Making delay times (counting
Timer1 internal machine cycles)
• Counting external clock pulses (via
pins T0 & T1)
TL0
• Mode3 (split mode - counting up to 𝟐𝟖 )
TH0
Timers overflow bits
(TF0 & TF1)
Leads to
Max value of timer0 + 1 TF0 =1
Leads to
Max value of timer1 + 1 TF1 =1
Controlling Timer/Counter operations
using the counter/timer bit (C/𝐓)
TIMER (0 or 1)
The structure of Timer1 in Mode1
4/11/2024 7
The structure of Timer1 in Mode2
4/11/2024 8
▪ TF1 … Overflow flag of timer1 (maximum value +1).
▪ TR1 … T1-run (to start/stop running).
▪ TF0 … Overflow flag of timer0 (maximum value +1).
▪ TR0 … T0-run (to start/stop running).
4/11/2024 9
The counting value of any timer is measured from the max value
(not Min value)
4/11/2024 11
Controlling
P0.0 alarm
AT89C51
Controlling
Sensor T0 P0.1 Open/Close
Gates
Directive
4/11/2024 13
The Serial communications based on
8051
Interfacing between two
microcontroller
Microcontroller1 Microcontroller2
Interfacing between microcontroller &
digital modules
Module
(like GPS, GSM,
IMU, SD, GPRS)
Interfacing with Wi Fi module
Interfacing with USB module
LSB MSB
4/11/2024 23
Example
Draw the general Bit-stream of the UART (Universal
Asynchronous Receiver/Transmitter) of MCS-51 in Mode1.
Also draw the Bit-stream for sending character “A” (41H
from ASCII).
LSB
41h=
0100 0001
4/11/2024 24
The UART communication in AT89C51
For interfacing between the microcontroller and
either a computer device or other microcontroller
via serial port (TXD & RXD)
RXD
TXD
register (SBUF) register (SBUF)
Ti Serial Ri Serial
control control
Baud & Baud &
rate modes rate modes
clock clock
Gen. Timer1 Gen. Timer1
Transmitter Receiver
Microprocessor 2017-18 26
8051’s UART interfacing with computer
Via the microchip “MAX-232” or “MAX-233”
See the lecture book