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

IO Port Programming

The document provides an overview of I/O interfacing for the BEC405A microcontroller, detailing the configuration and usage of its four 8-bit I/O ports (P0, P1, P2, P3). It explains how to set these ports as input or output, their internal configurations, and specific functionalities like dual roles for certain ports. Additionally, it covers bit addressability and instructions for single-bit operations within the I/O ports.

Uploaded by

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

IO Port Programming

The document provides an overview of I/O interfacing for the BEC405A microcontroller, detailing the configuration and usage of its four 8-bit I/O ports (P0, P1, P2, P3). It explains how to set these ports as input or output, their internal configurations, and specific functionalities like dual roles for certain ports. Additionally, it covers bit addressability and instructions for single-bit operations within the I/O ports.

Uploaded by

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

MICROCONTROLLER

BEC405A
MODULE 5
IO INTERFACING
I/O Port Pins

•The four 8-bit I/O ports P0, P1, P2, and P3 each use 8
pins.
•All the ports upon RESET are configured as input, ready to
be used as input ports.
•When the first 0 is written to a port, it becomes an output.
•To reconfigure it as an input, a 1 must be sent to the port.
•To use any of these ports as an input port, it must be
programmed.
8051 Pin
Diagram
Pin Configuration of 8051
• ALE/PROG: It is used for demultiplexing
address and data. It is valid only for
External memory accesses.
• EA/VPP:
– EA/Vpp = 0: Execute program on external
memory.
– EA/Vpp = 1: Execute program on internal
memory.
– Receives 21V for programming of the on-chip
EPROM.
• Pin 29 (PSEN): This pin is used to enable
external program memory.
• If we use an external ROM for storing the
program, then logic 0 appears on it, which
indicates Microcontroller to read data from
the memory.
Port 0
•It can be used for input or
output.
•Each pin must be connected
externally to a 10K ohm pull-up
resistor.
•This is due to the fact that P0 is
an open drain, unlike P1, P2, and
P3.
•Open drain is a term used for
MOS chips in the same way that
open collector is used for TTL
chips.
Port 0 Example

•; Toggle all bits of P0

BACK:MOV A, #55H
MOV P0, A
ACALL DELAY
MOV A, #0AAH
MOV P0, A
ACALL DELAY
SJMP BACK
Port 0 as Input

In order to make port 0 an input, the port must be


programmed by writing 1 to all the bits.

•.
Dual Role of Port 0

•Port 0 is also designated as AD0-AD7.


•Allowing it to be used for both address and data.
•When connecting an 8051/31 to an external memory, port
0 provides both address and data.
Port 1
• Port 1 can be used as input or output.
• In contrast to port 0, this port does not need any pull-up
resistors since it already has pull-up resistors internally.
• Upon reset, port 1 is configured as an input port.
Port 1 as Input

• To make port 1 an input port, it must be programmed as such


by writing 1 to all its bits.
Port 2
• Port 2 can be used as input or output
• Just like port 1, port 2 does not need any pull-up resistors since
it already has pull-up resistors internally.
• Upon reset, port 2 is configured as an input port.
Port 2 as Input or Dual Role

• ✔ Making Port 2 an Input:


• Port 2 can be used as an input by writing 1s to all its bits in the code.
• This configures it for input mode since 8051 ports are quasi-bidirectional by
default.
• ✔ In 8051-based systems:
• Port 2 (P2) is typically used as general-purpose I/O (Input/Output).
• You can use it freely for reading from or writing to devices like sensors or LEDs.
• ✔ In 8031-based systems:
• Port 2 has a dual role:
– It helps in external memory interfacing.
– It works with Port 0 to provide a 16-bit address bus.
• P2 (Port 2): carries the high byte of the address (A8–A15).
• P0 (Port 0): carries the low byte (A0–A7).
Port 3
• Port 3 can be used as input or
output
◦ Port 3 does not need any pull-
up resistors
◦ Port 3 is configured as an
input port upon reset
▪ This is not the way it is most
commonly used
• Port 3 has the additional
function of providing some
extremely important signals
IO PORTS and BIT addressability
• The instructions that are used for single bit operations are as
follows
Checking an Input Bit
• The JNB and JB instructions are widely used single-bit
operations
◦ They allow you to monitor a bit and make a decision
depending on whether it’s 0 or 1
◦ These two instructions can be used for any bits of I/O ports 0,
1, 2, and 3
◦ Port 3 is typically not used for any I/O, either single-bit or
byte-wise

You might also like