8051 2018 Lec6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

1

Microprocessor 2021
Timer0 & Timer1

TH0 TL0 TF0


Timer0

TH1 TL1 TF1


Timer1

8 bits 8 bits bit


Utilities of Timer0 & Timer1

Timer0
• Making delay times (counting
Timer1 internal machine cycles)
• Counting external clock pulses (via
pins T0 & T1)

Timer1 • Adjusting the generated Baud rates


for the serial communication
Operation Modes of Timers
Timer0 • Mode0 (oldest mode - counting up to 𝟐𝟏𝟑 )
• Mode1 (counting up to 𝟐𝟏𝟔 )
Timer1 • Mode2 (counting up to 𝟐𝟖 with Reloading)

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/𝐓)

External Internal oscillator


pulses
Clock divider (/12) Machine
cycles

Pin T(0 or 1) C/𝐓=0


C/𝐓=1

TIMER (0 or 1)
The structure of Timer1 in Mode1

‘0’ for stop


counting

4/11/2024 7
The structure of Timer1 in Mode2

‘0’ for stop


counting

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)

initial value for timer = (FFFFh+ 1) – Needed value


Example of counting external Pulses
A module designed to count the instantaneous number
of cars during enter a park. If the counted number of
cares equal 500, the system makes alarm and closes
the gates. Write assembly code to perform the
mentioned task (without interrupt) based on T0 of
AT89C51.

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

UART- USB converter


Interfacing with IR Transceiver module
Interfacing with GSM module
Interfacing with GPRS & GPS module

𝐆𝐏𝐒 𝑮𝑙𝑜𝑏𝑎𝑙 𝑷𝑜𝑠𝑖𝑡𝑖𝑜𝑛 𝑺𝑦𝑠𝑡𝑒𝑚


𝐆𝐏𝐑𝐒 General Packet Radio Services (internet communication)
Interfacing with IMU module

𝐈𝐌𝐔 inertial measurement unit


(include: Accelerometers, Gyroscopes and magnetometers)
The serial protocol for sending/receiving
(UART) in serial MODE 1
One Frame

LSB MSB

NOTE: The LSB is sent & received firstly

UART universal asynchronous receive/transmit

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)

The LSB is sent & received


firstly
4/11/2024 25
The data stream & control in serial port
Any register or Any register or
memory location memory location

Serial Buffer Serial Buffer

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

The Half and full duplex


See the lecture book

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy