Unit IV Notes
Unit IV Notes
Q1. What is the need of memory expansion and I/O expansion in microcontroller.
Ans. Memory expansion and I/O expansion in a microcontroller are needed when the on-chip
memory or input/output pins provided by the microcontroller itself are not sufficient for the
application's requirements, allowing developers to add more memory storage and external devices
by connecting additional chips to the microcontroller through dedicated interfaces like SPI or I2C,
without needing to switch to a more expensive or powerful microcontroller with more built-in
resources.
Memory expansion:
When an application needs to store a large amount of data, such as in complex sensor readings,
image processing, or large data buffers, the on-chip RAM might not be enough, requiring external
memory chips to be added for additional storage.
Depending on the application, different types of memory like flash memory for storing program
code or EEPROM for non-volatile data storage can be added through memory expansion.
I/O pins
Many applications require a large number of input and output pins to interact with various sensors,
actuators, and other peripherals, which might exceed the limited number of I/O pins available on
the microcontroller.
• Cost-effective design:
Using I/O expander chips allows developers to choose a microcontroller that meets the core
processing needs while adding additional I/O functionality only where necessary, thus optimizing
the overall system cost.
Q2. What are control signals. How memory wait states affect the system in microcontroller.
Ans, When expanding the memory of an 8051 microcontroller, the key control signals used
are "PSEN" (Program Store Enable) for accessing external program memory and "ALE" (Address
Latch Enable) for latching the memory address, while "memory wait states" are added to the clock
cycle to accommodate slower external memory access times compared to the internal memory.
This is the primary signal used to activate external program memory access; when asserted high,
it enables the external EPROM or flash memory to output data onto the data bus.
This signal is used to latch the address placed on the address bus onto the external memory chip
during a memory access cycle.
Depending on the memory type, additional signals like "RD" (Read) and "WR" (Write) might be
required to control data transfer direction.
• Function:
When accessing slower external memory, the 8051 can insert additional clock cycles (wait states)
into the memory access cycle to allow sufficient time for the external memory to respond.
• Implementation:
Wait states are configured by setting the appropriate pin connections on the memory chip and
adjusting the timing parameters in the system design.
How it works:
1. . Address generation:
2. . ALE signal:
The ALE signal is asserted high to latch the address onto the external memory chip.
3. PSEN signal:
If accessing external program memory, the PSEN signal is activated, enabling the external memory
to output data.
4. Data transfer:
During the appropriate clock cycles (including any wait states), the data is read from or written to
the external memory.
Control Signals:
Control signals are digital signals used to coordinate and manage various operations within a
microcontroller system. They're like traffic signals that orchestrate the flow of data and operations.
Here are the key aspects:
2. Functions:
Wait states are additional clock cycles inserted into memory access operations when the memory
device cannot operate at the same speed as the CPU. Here's how they affect the system:
1. Performance Impact:
- Each wait state adds one clock cycle to memory access time
2. Necessity:
3. System Effects:
4. Configuration:
Therefore, 3 wait states would be needed (1 normal cycle + 3 wait states = 4 cycles total)
This fundamental understanding of control signals and wait states is crucial for designing efficient
microcontroller systems and troubleshooting timing-related issues.
Q3. What do you mean by external memory. Why it is necessary in 8051 . how do we interface
with 8051 microcontroller.
Ans. The 8051 microcontroller is a popular microcontroller used in various applications, ranging
from small embedded systems to larger industrial applications. While the 8051 has a limited
amount of internal memory, it is possible to extend the memory capacity by interfacing it with
external memory devices.
External memory interfacing typically involves connecting the memory devices to the
microcontroller through a data bus and an address bus. The data bus is used to transfer data between
the microcontroller and the memory device, while the address bus is used to select a specific
memory location in the memory device.
To interface with external memory, the 8051 microcontroller uses dedicated pins such as ALE
(Address Latch Enable), PSEN (Program Store Enable), and RD (Read) and WR (Write) signals.
These signals are used to control the flow of data between the microcontroller and the external
memory device.
For minimal memory applications, the 8051 has internal data and code memory. In such a position.
For certain applications, this memory capacity will not be adequate. To expand the memory space
of the 8051 micro-controller, we must bind external ROM/EPROM and RAM. We also understand
that ROM serves as program memory and RAM serves as data memory. Let’s take a look at how
8051 accesses these memories.
External memory interfacing is necessary in the 8051 microcontroller for several reasons:
1. Limited internal memory: The 8051 microcontroller has a limited amount of internal
memory, including 128 bytes of RAM and 4KB of on-chip ROM. This memory may not
be sufficient for some applications that require larger program memory or more data
storage.
2. Larger programs: For applications that require larger programs, such as complex
algorithms or multiple functions, external memory interfacing can provide the necessary
program memory space to store these programs.
3. Data storage: Applications that require the storage of large amounts of data, such as data
logging or data analysis, may require external memory interfacing to store the data.
5. Cost-effective: External memory devices such as RAM and ROM are relatively
inexpensive, making it cost-effective to interface them with the microcontroller instead of
using more expensive on-chip memory.
Memory Capacity Address Line Required
• The memory chip has 11 address lines A10-A0, one chip pick (CS), and two control lines,
as seen in the table. To allow the output buffer, press RD, and to enable the input buffer,
press WR.
• The address lines are decoded using the internal decoder: (b) displays the logic diagram of
a 4096 (4 K) register EPROM (Erasable Programmable Read-Only Memory).
• It has a total of 12 address blocks. One chip pick (CS) and one read control signal (A11-
A0). EPROM does not need the (WR) signal since it is a read-only memory.
Ans
As we know 8k PROM =
A0 – A12 lines are used for addressing the PROM remaining A13-A15 will act as low
i
1. When we connect PSEN to the ground, then the 8051 microcontroller fetches the opcode
from the external ROM.
2. But, when we connect PSEN to VCC, the status of the PSEN is ‘not activated’ since it is
an active low pin. Hence, the program memory is saved in the internal ROM of 8051 itself.
To access the data memory space, we use the instruction MOVX A, @DPTR. Connect the RD pin
(PIN 3.7) to the OE of data ROM and give an active low signal to the Chip enable (CE) pin of data
ROM. Here we access the data from the external ROM containing the data and transferred to
internal RAM.
1. Step 1: Calculate the number of address lines required to access 16KB of data, that is 214 =
16KB. Here, we require 14 address lines A0 – A13.
2. Step 2: Decide the location of RAM and ROM, here we are going to interface program
ROM from 0000H and data RAM from 8000H.
3. Step 3: Select the decoder circuit, here we’re going to select 74LS138 decoder.
4. Step 4: We do not need a decoder circuit for program ROM, but we have to connect the
74LS138 decoder to data ROM and data RAM.
6. Step 6: Connect input A and B to P2.6 and P2.7 respectively, and the input C to ground.
7. Step 7: We connect external program and data ROM, for that we can use an AND gate with
its input being signal from RD (to access external data space) and PSEN (to access external
program space) and output to OE of external ROM.
8. Step 8: To interface the external RAM, we connect both RD and WR to WE and OE respectively
of external RAM