Port 0
Port 0
Functionality: Port 0 is a dual-purpose port and can be used for general I/O or as a multiplexed
address/data bus when interfacing with external memory.
Configuration:
o When configured as output, the pin latch controls the output state.
o A logic 0 on the latch turns on the lower FET, grounding the pin.
o A logic 1 requires an external pull-up resistor to output a high state.
Special Use:
o When used for external memory interfacing, it carries the lower-order address during the first
clock cycle and switches to data transfer mode in subsequent cycles.
o Address Latch Enable (ALE) signal is used to demultiplex address and data.
Port 1
Functionality: Port 1 is a dedicated general-purpose I/O port with no alternate functions.
Configuration:
o Each pin has an internal pull-up resistor.
o When used as an input, writing a logic 1 to the latch turns off the lower FET, and the pin is
pulled high by the pull-up resistor.
o External circuitry can override the pull-up resistor to drive the pin low.
o As output, the state of the latch directly controls the pin.
Port 2
Functionality: Similar to Port 1, Port 2 can also function as a general-purpose I/O port but has an
additional feature to serve as the high-order address bus for external memory interfacing.
Configuration:
o For external memory, the address remains stable without the need for turnaround.
o The control signals temporarily alter the state of Port 2 during external memory addressing.
o Internal pull-up resistors allow for input and output capabilities like Port 1.
Port 3
Functionality: Port 3 serves dual functions:
o General-purpose I/O.
o Alternate functions controlled by specific Special Function Registers (SFRs).
Alternate Functions:
o P3.0 (RXD): Serial data input (SBUF register).
o P3.1 (TXD): Serial data output (SBUF register).
o P3.2 (INT0): External interrupt 0 input (TCON.1).
o P3.3 (INT1): External interrupt 1 input (TCON.3).
o P3.4 (T0): External Timer 0 input (TMOD).
o P3.5 (T1): External Timer 1 input (TMOD).
o P3.6 (WR): External memory write signal.
o P3.7 (RD): External memory read signal.
Configuration:
o Each pin can independently function either as an I/O pin or in its alternate role.
o Pull-up resistors and internal FET circuitry are used for input/output transitions
1. Control Signals:
o These signals determine the mode of operation for Port 0 (data or address bus, or general I/O).
2. Port SFR Latch:
o This is a D-type flip-flop that stores the output value for the port pin.
o Write to Latch: The internal bus writes data to the latch when the control logic allows it.
o Read Latch Bit: Data can also be read back from the latch.
3. Control Logic:
o It governs whether the pin is configured as an input, output, or part of the multiplexed
address/data bus.
o The logic switches the pin state based on control inputs.
4. Internal FET Pull-Up Circuit:
o Depletion-Mode FET: Always on unless overridden by control signals. Provides a weak pull-
up to Vcc for idle states.
o Enhancement-Mode FET: Actively drives the pin high (to Vcc) when required.
o These FETs manage the pin voltage for output operation.
5. Two Oscillator Periods:
o A delay mechanism is introduced to ensure proper stabilization of the pin state during
transitions.
6. Pin 0.x:
o Represents any specific pin of Port 0. For example, Pin 0.0, Pin 0.1, etc.
o This pin is connected externally for I/O or bus operations.
7. Ground Connection:
o The pin can be grounded by control signals when driving a low output state
Operation Modes
1. As a General-Purpose Output:
o Output High:
The D flip-flop latch stores a 1.
The enhancement-mode FET is activated, pulling the pin to Vcc.
o Output Low:
The latch stores a 0.
The lower transistor in the control logic is activated, pulling the pin to ground.
2. As a General-Purpose Input:
o The latch is set to 1, turning off the pull-down transistor.
o The depletion-mode FET provides a weak pull-up.
o External signals can drive the pin high or low.
3. As an Address/Data Bus:
o Port 0 serves as a multiplexed address/data bus during external memory access.
o Address Mode:
During the first clock cycle, the address is latched onto Port 0.
o Data Mode:
During subsequent cycles, the port switches to data transfer mode.
Special Characteristics of Port 0
Requires External Pull-Up Resistors:
o Unlike Ports 1, 2, and 3, Port 0 does not have internal pull-up resistors.
o External resistors are needed to stabilize high-output states during I/O operations.
Multiplexed Address/Data Bus:
o The control logic enables switching between address and data, essential for external memory
interfacing.
Port 1
Key Components in the Diagram
1. Port SFR Latch (D Flip-Flop):
o This is a storage element that holds the output data for the pin.
o The D flip-flop has the following:
D (Data): Input data written to the latch.
CL (Clock): Used to trigger the latch to store the input value.
Q / Q̅ (Outputs): Represents the latched data (Q) and its complement (Q̅ ).
2. Control Signals:
o Write to Latch: Enables the internal bus to write data into the latch.
o Read Latch Bit: Used to read the value stored in the latch.
o Read Pin Data: Used to read the current logic state of the external pin.
3. Internal FET Pull-Up:
o Pull-Up Resistor: Ensures that the pin is pulled to Vcc (logic high) by default when not driven
by an external signal.
o FET (Field-Effect Transistor): Acts as a switch to pull the pin high when required.
4. Pin 1.x:
o Represents an individual pin of Port 1 (e.g., 1.0, 1.1, etc.).
o This pin serves as a general-purpose I/O line.
Operation of Port 1
Port 1 is a general-purpose I/O port with an internal pull-up resistor. Unlike Port 0, it does not require external
pull-up resistors. Here’s how Port 1 operates:
1. As an Output Port:
o When data is written to the latch:
Logic High (1): The internal pull-up resistor ensures the pin is at Vcc (logic high).
Logic Low (0): The FET connects the pin to ground, setting it to logic low.
2. As an Input Port:
o The latch is set to logic high (1), turning off the pull-down transistor.
o The pull-up resistor pulls the pin to Vcc unless an external device drives it low.
o The input signal can be read through the Read Pin Data line.
Port 2
Key Components in the Diagram
1. Port SFR Latch (D Flip-Flop):
o Stores the data for output or latches the data for reading input.
o Components:
D (Data): Input to the latch.
CL (Clock): Triggers the latch to capture input data.
Q / Q̅ (Outputs): Represent the stored data and its complement.
2. Control Logic:
o Adds additional functionality to Port 2 as it is multiplexed for use as both I/O and higher-order
address lines.
o Works with the control signals to configure the port appropriately.
3. Control Signals:
o Address: When external memory is accessed, Port 2 provides the higher-order address bits
(A8–A15).
o Read Latch Bit: Allows reading of the stored data in the SFR latch.
o Write to Latch: Writes data from the internal bus to the SFR latch.
4. Internal FET Pull-Up:
o Provides an internal pull-up resistor to ensure the pin defaults to logic high (Vcc) when not
driven externally.
o A FET is used to connect or disconnect the pull-up resistor as needed.
5. Pin 2.x:
o Represents an individual pin of Port 2 (e.g., 2.0, 2.1, etc.).
o Each pin can function as general-purpose I/O or a higher-order address line.
Operation of Port 2
As an I/O Port:
Output Mode:
o Data is written to the SFR latch via the internal bus.
o Logic High: The pull-up resistor ensures the pin is at Vcc.
o Logic Low: The FET switches the pin to ground.
Input Mode:
o The latch is set to logic high, and the pin can accept external signals.
o External devices drive the pin, and the value is read through the Read Pin Data line.
As an Address Port:
When accessing external memory, Port 2 provides the upper 8 bits (A8–A15) of the address bus.
The Control Logic handles the multiplexing between I/O and address functionality, depending on
whether the microcontroller is using internal or external memory.
Applications of Port 2
1. External Memory Access:
o Provides the higher-order address bits when interfacing with external program or data memory.
2. General-Purpose I/O:
o Can be used for input or output operations like other ports when external memory access is not
needed.
Port 3
Components in the Diagram
1. Port SFR Latch (D Flip-Flop):
o Functions as a latch to store data for output or capture data for input.
o Components:
D (Data): The input data line to the latch.
CL (Clock): Activates the latch to capture or store data.
Q / Q̅ (Outputs): The stored data and its complement.
2. Alternate Input/Output:
o Port 3 has additional functionality with alternate functions for each pin (e.g., serial
communication, interrupts, timers).
o Examples:
P3.0: RXD (Serial Input)
P3.1: TXD (Serial Output)
P3.2: INT0 (External Interrupt 0)
P3.3: INT1 (External Interrupt 1)
P3.4: T0 (Timer 0 Input)
P3.5: T1 (Timer 1 Input)
P3.6: WR (External Memory Write Strobe)
P3.7: RD (External Memory Read Strobe)
3. Control Signals:
o Read Pin Data: Captures the current logic level on the pin.
o Alternate Input: Handles the alternate functions (e.g., INT0, RXD).
4. Internal FET Pull-Up:
o Ensures the pin defaults to a high logic state (Vcc) when not actively driven low.
o The pull-up can be overridden when the pin is used as an input or driven externally.
5. Pin 3.x:
o Represents individual pins of Port 3 (e.g., 3.0, 3.1, etc.).
o Each pin can function as general-purpose I/O or serve its alternate function.
Operation of Port 3
As General-Purpose I/O:
Output Mode:
o Data written to the SFR latch is driven to the pin.
o The internal FET pull-up ensures a logic high when set.
Input Mode:
o The pin can accept external signals, and its state is read via the Read Pin Data line.
As a Functional Port:
Port 3 pins are multiplexed with alternate functions for specialized tasks:
o Serial Communication: RXD/TXD for UART.
o External Interrupts: INT0/INT1 for handling interrupts.
o Timer Inputs: T0/T1 for timer counting.
o External Memory Control: WR/RD for memory read/write operations.
The Alternate Output and Alternate Input signals manage these functions.
Applications of Port 3
1. Serial Communication:
o RXD/TXD are used for interfacing with UART for serial data transmission/reception.
2. Interrupts:
o External interrupts (INT0, INT1) for priority-based program execution.
3. Timers:
o Timer inputs (T0, T1) for precise timing and event counting.
4. External Memory Access:
o WR/RD control signals are essential for interfacing with external RAM/ROM.
Key Notes:
1. P0: Primarily used for data transfer during external memory access. Requires pull-up resistors.
2. P1: General-purpose I/O with no alternate functions, straightforward to use.
3. P2: Often used for addressing external memory (higher-order address bits).
4. P3: Most feature-rich port with multiple alternate functions like serial communication, timers, and
interrupt handling.
Key Points to Remember
1. Port 0 (P0):
o Used as a multiplexed address/data bus in external memory mode.
o Requires external pull-up resistors when used as I/O.
2. Port 1 (P1):
o Simple I/O port with no alternate functions.
o Does not require external pull-ups.
3. Port 2 (P2):
o Provides high-order address bus lines in external memory interfacing.
o Has internal pull-ups for I/O operations.
4. Port 3 (P3):
o Versatile port with both general-purpose I/O and alternate control/communication
functions.
o Commonly used for interrupts, serial communication, timers, and external memory control
signals.
5. port Pins Primary Function Alternate Functions Special Features
General- - Used for multiplexed low-order address and
Address/Data Bus
P0 P0.0-P0.7 purpose I/O data bus in external memory interfacing.
(AD0-AD7)
(bidirectional) - Requires external pull-ups for I/O.
- Purely for I/O, no alternate functions.
P1 P1.0-P1.7 General-purpose I/O (bidirectional) None
- Does not require external pull-ups.
Connection Details
1. Port 0 (P0) Multiplexed Address/Data Bus (AD0–AD7):
o Port 0 is used to carry both low-order addresses (A0–A7) and data.
o The ALE signal distinguishes between the address and data phases.
o During the address phase, the low-order address is latched into the 74HC373 latch.
o During the data phase, Port 0 operates as a data bus (D0–D7).
2. Port 2 (P2) High-Order Address Lines (A8–A15):
o Port 2 provides the higher-order address bits directly to the memory devices.
3. Address Latch Enable (ALE):
o ALE is a clock signal generated by the microcontroller to latch the low-order address from Port
0 into the latch (74HC373).
o The latched address is then used to access the external memory devices.
4. PSEN (Program Store Enable):
o Used to access the EPROM during code fetch operations.
o Active low signal that enables the external program memory.
5. RD (Read) and WR (Write):
o RD: Active low signal used to read data from the external RAM.
o WR: Active low signal used to write data into the external RAM.
6. External EPROM (27128):
o Address lines (A0–A13) are connected to the address bus from the microcontroller.
o The PSEN signal enables the EPROM for code fetch operations.
o Data lines (D0–D7) are connected to Port 0 for data transfer.
7. External RAM (6264):
o Address lines (A0–A12) are connected to the address bus from the microcontroller.
o Data lines (D0–D7) are connected to Port 0 for data transfer.
o The RD and WR signals control read and write operations on the RAM.
Key Notes
Dashed Lines: Indicate shared connections between the EPROM and RAM, such as data lines and
address lines.
Vcc and GND: Power and ground connections are not shown in the diagram.
Latch Importance: The 74HC373 ensures that address and data signals on Port 0 are properly
separated to avoid conflict.
This configuration allows the microcontroller to execute code from the external EPROM and store/retrieve
data from the external RAM.
This calculation determines the number of address lines (denoted as nnn) required for a memory chip of a
given size, specifically for a 16 KB ROM in this case.
Understanding the Calculation:
1. Formula for Memory Size:
o The total number of addressable locations in a memory chip is given by 2n2^n2n, where nnn is
the number of address lines.
o Each address line doubles the addressable memory.
Conclusion:
A 16 KB ROM requires 14 address lines to address all 16384 memory locations. Each combination of
the 14 address lines represents one memory location.
This calculation determines the number of address lines required for different RAM sizes (4 KB and 8 KB).
Let’s break it down:
Conclusion:
4 KB RAM requires 12 address lines.
8 KB RAM requires 13 address lines. This calculation shows how the memory size relates to the
number of address lines needed for full addressability.