0% found this document useful (0 votes)
6 views28 pages

Understanding 8051 Microcontroller Ports

The document discusses the functionality and operation of microcontroller parallel ports, specifically focusing on the 8051 microcontroller's four I/O ports and their dual functions. It also covers the timers in the 8051, detailing their modes of operation, control registers, and how to initialize and use them for various applications. Additionally, it explains the significance of timer modes, including timing, counting, and auto-reload functionalities.

Uploaded by

Prarthana Sai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views28 pages

Understanding 8051 Microcontroller Ports

The document discusses the functionality and operation of microcontroller parallel ports, specifically focusing on the 8051 microcontroller's four I/O ports and their dual functions. It also covers the timers in the 8051, detailing their modes of operation, control registers, and how to initialize and use them for various applications. Additionally, it explains the significance of timer modes, including timing, counting, and auto-reload functionalities.

Uploaded by

Prarthana Sai
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Introduction

• The major benefit of microcontrollers lies in their built-in


parallel ports. The parallel ports can be used to interface all
data converters (ADCs, DACs, etc.) and display devices (LEDs,
LCDs, etc.).
• Any microcontroller-based system needs to transfer data
between the external peripherals and the microcontroller.
The microcontroller needs to read data fed by the user from
the external interface, process it, and give the output to the
peripherals or to the user again. To communicate data with
the external world, the microcontroller needs ports. The ports
may support either parallel or serial data transfer.
Parallel Ports of 8051
• 8051 has 4 I/O ports namely Port0, Port1, Port2 and Port3.
The major constraint -the number of pin count. to reduce -
number of pins of the microcontroller ICs, the pins allotted for
the parallel ports -alternate functions also.
• Out of the available four parallel ports of 8051, Port 1 is used
exclusively for input and output functions alone.
Parallel Ports of 8051
• The other port pins have -distinct function in addition to -
used for input and output functions. So, all the 24 pins of Port
0, port 2, port 3 -two different functions based on the
commands or programs running.

• All the four ports are bi-directional -programmed to have


input or output operation. All the 8 port pins -connected
through 8 D type port latches. One D type latch connects the
data in it to a port pin when the port is used as output port.
Parallel Ports of 8051
• The user can access all the four ports using -addresses
mapped in the special function register area.

• Note that it is possible to address individual bits of all the


four ports by - bit addresses. Using this bit address, individual
bits can be read in or changed.
Parallel Ports and Port Pins of 8051
8051 Timers
• Basically the timers are the digital counters which are
incremented at the pulses given to it. The timers can be
controlled to -function through four SFRs namely, TMOD,
TCON, TH0/TL0 and TH1/TL1.
• The timers will have overflow when it counts to full value and
resets to 0 upon next count.
• The overflow in the timers will set the two bits in the TCON
SFR. This overflow can be programmed to interrupt the
microcontroller execution and execute a predefined
subroutine.
8051 Timers
• If the timer registers are incremented by the internal clock
pulses from the microcontroller, then the operation is termed
as ‘Timing’ operation.
• Meanwhile if the timer registers get their clock pulses from
an external device through the port 3 pins of 8051, then the
operation is termed as ‘Counting’.
• Timer 0 external input pin P3.4 (T0) is used give clock input to
timer 0 to act as counter.
• Timer 1 external input pin P3.5 (T1) is used give clock input to
timer 1.
Operating Modes of 8051
Mode 0 - 13-bit Timer Mode
• Timer mode "0" is a 13-bit timer. Out of 16 bits of Timers, only 13bits
are used. The 5 bits of lower order byte is used and 8 bits of the
higher order byte of the timers are used in Mode0. Lower order byte
TL0/1 will count from 0 to 31.
• When TL0/1 is incremented from 31, it will "reset" to 0 and
increment TH0/1. So, the timer can only contain 8192 values from 0
to 8192.
• The timer can be operated as timer with internal clock pulses or as a
counter with external clock pulses.
• This selection is done by D2 bits of TMOD for Timer 0 and D6 bit of
TMOD for Timer1
TCON SFR
• The clock pulses selected by D2 and D6 bits of TMOD is then
controlled by programmer setting and connected to the Timer
registers. The control is by three different means.

• First is the Timer Run control bits D4 and D6 of TCON register.


The timer will run only when Timer run control bits are set to 1.
TCON SFR
• The other controls for the timers are through the GATE control
bits D4 and D7 of TMOD and the External inputs for timer.
Setting GATE to 1 allows the timer to count only if the external
control input INT0 or INT1 is set to 1. Setting Gate to 0 will
disable the corresponding external timer control inputs INT0
and INT1.

• Setting Timer to mode 0 will overflow back to zero after 8192


counts. This will set the TF1 and TF0 bits for timer 1 and timer
0 respectively.
Mode 0 Operation of Timer 1 of
8051
Mode 1 – 16-bit Timer Mode
• In timer Mode 1 of 8051, each timer is operated as a 16-bit
timer. It functions just like mode 0 except that all 16 bits are
used.
• TL0/1 bits are incremented from 0 to 255. When TL0/1 is
incremented from 255, it resets to 0 and causes TH0/1 to be
incremented by 1. Since this is a full 16-bit timer, the timer
may contain -65536 distinct values.
• The control of gating and running the timer in mode 1 is similar
to that of mode 0
Mode 1 Operation of Timer 1 of
8051
Mode 2 – 8-bit Timer Auto Reload
Mode
• Only 4 of the 8 bits of the TCON SFR is defined. the other 4 bits
of the SFR don’t have anything to do with timers. They are
related with Interrupts and they will be discussed in the
chapter that addresses interrupts.

• Note that the individual bits of TCON register can be addressed


separately by their bit addresses. This allows the programmer
to run the timers using bit addressable instructions and check
the overflow independently.
Mode 2 – 8-bit Timer Auto Reload
Mode
• For example, let’s say TH0 holds the value FDh and TL0 holds
the value FEh. Then at the next counting pulse, TL0 will be
incremented to FFh. Then for the next pulse, the TL0 will
overflow and should have become 00.

• But, as it is reload mode, the TL0 will be loaded with TH0 i.e.,
FDh. The value of TH0 will never be changed. TH0/1 is set to a
known value and TL0/1 is the SFR that is constantly
incremented.
Mode 2 – 8-bit Timer Auto
Reload Mode
• The auto-reload mode is very commonly used for
establishing a baud rate for Serial Communications.

• The control of gating and running the timer in mode 2


is similar to that of mode 0
Mode 2 Operating of Timer 1 of
8051
Mode 3 – Split Timer Mode
• Mode "3" of 8051 timer is a split-timer mode and is applicable
only for Timer 0. When Timer 0 is placed in mode 3, it
essentially becomes two separate 8-bit timers. That is, Timer 0
is TL0 and Timer 1 is TH0.

• Both timers count from 0 to 255 and overflow back to 0.

• In mode 3, all the bits that are related to Real Timer 1 will
simply hold its count and will not run and the situation is
similar to keeping TR1=0.
Mode 3 – Split Timer Mode
• In Split Timer mode of Timer 0, the real Timer 1 (i.e. TH1
and TL1) can not be started or stopped since the bits that
do that are now linked to TH0. The real timer 1, in this
case, will be incremented every machine cycle no matter
what.

• When two separate timers in addition to a baud rate


generator is required in an application, then real Timer 1
can be used as a baud rate generator and TH0/TL0 can be
used as two separate timers in mode 3.
Mode 3 Operation of Timer 0 of
8051
Timer Control and Operation
• For timer operation (C/T = 0 in TMOD), the timer register
counts the divided-down clock. The timer register is
incremented once every (FOSC / 12) in standard mode. If the
clock frequency is 11,059,000KHz, then the counter will be
incremented at the rate of (11,059,000KHz/12) = 921,583 KHz.

• This means the counter will be incremented 921,583 times in a


second. Thus to have delay of say 0.1 seconds, then the
counter must be initialized to the count value of (0.1*921,583)
= 92158.
Timer Control and Operation
Following steps are the program steps to initialize and use a
timer in 8051
•Decide what mode the timer to be in.
•Initialize the TMOD SFR.
•Write the timer value to Timer register
•Start the timer running by setting the TR0/1 bit in TCON
register
•Check for TF0/1 bit or program to handle timer overflow as
interrupt and execute interrupt subroutine.
Steps in Timer Control
Write TMOD

Write TCON

Write timer register

Start timer

Program Required Operation

Continue
Timer Control and Operation

• To set the bit TR1 of TCON (D6 bit), any one of the following
two commands can be used -MOV TCON, #40h OR SETB TR1

• As, TR1 is a bit addressable location, SETB instruction is used


and this has the benefit of setting the TR1 bit of TCON without
changing the value of any of the other bits of the SFR.

You might also like