Open In App

External Memory Interfacing in 8051 Microcontroller

Last Updated : 21 Apr, 2023
Like Article

Introduction :

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 in 8051 microcontroller involves connecting external memory devices such as RAM and ROM to the microcontroller to provide additional memory space. This allows the microcontroller to execute larger and more complex programs, store more data, and perform more complex operations.

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 the 8051 accesses these memories.

Why need External Memory Interfacing in 8051 Microcontroller ?

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.
  4. Flexibility: External memory interfacing provides greater flexibility in the design of embedded systems, allowing for customization and adaptability to meet specific application requirements.
  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.

External Program Memory :

  • The program fetches to addresses 0000H through OFFFH are directed to the internal ROM in the 8051 when the EA pin is attached to Vec, and program fetches to addresses 1000H through FFFFH are directed to the external ROM/EPROM. When the EA pin is grounded, all addresses fetched by the program (0000H to FFFFH) are led to it.

  • ROM/EPROM that is external to the device. As seen in Fig. 1, the PSEN signal is used to trigger output e external ROM/EPROM.
  • Port 0 is used as a multiplexed address/bus, as seen in Fig2. In the initial T-cycle, it provides a lower order 8-bit address, and later it is used as a data bus. The external latch and the ALE signal provided by the 8051 are used to latch the 8-bit address.

Timing Waveform for external program memory

  • Remote ROM/EPROM(Read Only Memory/Electronic Programmable ROM/Electronic Programmable ROM/Electronic Program The PSEN signal is used to activate output e external ROM/EPROM, as seen in Fig. 1.
  • As seen in Fig2, port 0 is used as a multiplexed address/bus. It supplies a lower-order 8-bit address in the first T-cycle and later serves as a data bus. The 8-bit address is latched using the external latch and the ALE signal given by the 8051.

  • 1External Interrupt 0 is 0003H, Timer 0 is 000BH, External Interrupt 1 is 0013H, Timer 1 is 001BH, and so on. If an interrupt is to be used, the operation routine for it must be in the same place as the interrupt. If the interrupt isn’t used, the service location may be used as general-purpose program memory.

Instructions to Access External ROM / Program Memory :
This table is explaining the instructions to access external ROM/program memory.

MOVC A, @ A+DPTRCopy the contents of the external ROM address formed by adding A and the DPTR, to A
MOVC A, @ A + PCThis operation will do copy This operation contents of the external ROM address formed by adding A and the PC, to A.

External Memory Interfacing :

  • Up to 64 k-bytes of additional data memory can be addressed by the 8051. The external data memory is accessed using the “MOVX” instruction.
  • The 8051’s internal data memory is split into three sections: Lower 128 bytes, Upper 128 bytes, and SFRs. While they are physically distinct bodies, the upper addresses and SFRs share the same block of address space, 80H by FFH.
  • The upper address space is only accessible via indirect addressing, and SFRs are only accessible via direct addressing, as seen in Higher address space, on the other hand, can be reached using either direct or indirect addressing.

A map of the 8051 data memory Fig. 5

  • Fig. 7 a and b show the timing waveform for external data memory read and write cycles, respectively.



Instructions to Access External Data Memory :
The Table explains the instruction to access external data memory.

MOVX A, @RpIn this operation, it will copy the contents of the external address in Rp to A.
MOVX A. @DPTRCopy the contents of the external address in DPTR to A.
MOVX @Rp. A Copy data from A to the external address in Rp
MOVX DPTR, ACopy data from A to the external address in DPTR.

Important Points to Remember in Accessing External Memory :

  • In the Case of accessing external memory, All external data moves with external RAM or ROM involve the A register.
  • While accessing external memory, R can address 256 bytes and DPTR can address 64 k-bytes
  • MOV X instruction is used to access external RAM or 1/O addresses.

Note –
It must be noted that while the Program counter(PC) will be used then to access external ROM, it will be incremented by 1 (to point to the next instruction) before it is added to A to form the physical address of external ROM.

Memory Address Decoding :
We know that read/write memories consist of an array of registers, in which each register has a unique address: The size of the memory is NX Mas shown in Fig. 11.2.1 (a) where N is the number of registers and M is the word length, in a number of bits.

Example-1 : 
If memory is having 12 address lines and 8 data lines, then number of registers/memory locations = 2^N=2^N=2^{12}=4096           Word length = Mbit = 8-bit.

Example-2 : 

  • If the memory has 8192 memory locations, then it has :3 address lines The Table 11.2.1 summarizes the memory capacity and address lines required for memory interfacing
Memory CapacityAddress Line Required
1 K = 1024 memory locations10
2 K = 2048 memory locations11
4 K = 4096 memory locations12
8K= 8192 memory locations13
16 K = 16384 memory locations14
32 K = 32768 memory locations15
64 K = 65536 memory locations16
  • 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.
  • Memory and 1/0 modules are used in the microprocessor/microcontroller framework. Since the data, address, and control buses are shared by all devices, the microprocessor can only communicate (read/write) with one device at a time.
  • It is essential to decoding the address from the microprocessor/microcontroller in order to connect with memory or I/O devices. The strategies for decoding addresses are described in the following section.
  • The memory interfacing requires to following components as follows.
  1. Select the chip.
  2. Identify the register.
  3. Enable the appropriate buffer.

Address Decoding Techniques :

  • Absolute decoding/Full decoding
  • Linear decoding/Partial decoding

Technique-1 :
Absolute decoding –

  • In this technique, all the higher address lines are decoded to select the memory chip, and the memory chip is chosen only for the logic levels defined in these high-order address lines and no other logic levels will select the chip.
  • The memory interface with utter encoding is seen in Figure 11.22. In massive memory structures, this addressing strategy is commonly used.

Memory Map –

Memory ICsA15A14A13A12A11A10A9A8A7A6A5A4A3A2A1A0Address
Starting address of EPROM00000000000000000000H
End address of EPROM000000111111111103FFH
Starting address of RAM00100000000000002000H
End address of RAM001000111111111123FFH

Technique-2 :
Linear decoding –

  • Individual high-order address lines can be used to pick memory chips in compact systems, eliminating the need for hardware for decoding logic. Linear decoding is the term for this method.
  • The addressing of RAM using the linear encoding technique is seen in Figure 10. Partial decoding is another name for this process.
  • It lowers the cost of encoding and circuitry, but it has the disadvantage of requiring multiple addresses (shadow addresses).
  • The addressing of RAM using the linear encoding technique is seen in Figure 10. After inversion, A is a line attached to the chip select signal of the EPROM and then to the chip select signal of the RAM. As a result, EPROM is selected when the status of A line is “empty,” and RAM is selected when the status of the A15 line is “one.” Since the other address lines aren’t used to generate chip pick signals, their status isn’t taken into account.

Memory Map –

Memory ICsA15A14A13A12A11A10A9A8A7A6A5A4A3A2A1A0Address
Starting address of EPROM0xxxxx00000000000000H
End address of EPROM0xxxxx111111111103FFH
Starting address of RAM1xxxxx00000000008000H
End address of RAM1xxxxx111111111183FFH

Issues in External Memory Interfacing in 8051 Microcontroller :

There are several issues that can arise when interfacing external memory with the 8051 microcontroller. Some common issues include:

  1. Timing: The timing of the signals that control the external memory access must be accurate, or it can lead to errors in data transfer or program execution.
  2. Interference: Interference from external sources such as electromagnetic interference (EMI) or radio frequency interference (RFI) can cause errors or data corruption in the memory access.
  3. Signal integrity: The signal integrity of the address and data lines must be maintained to ensure accurate data transfer between the microcontroller and the external memory device.
  4. Address decoding: The external memory devices must be properly decoded so that the correct memory location is accessed. Incorrect address decoding can lead to data corruption or program errors.
  5. Power supply: The external memory devices must be powered properly to ensure stable and reliable memory access.
  6. Compatibility: The external memory devices used for interfacing must be compatible with the microcontroller, including their operating voltage, timing requirements, and interface protocol.
  7. Circuit design: Proper circuit design is required to ensure that the external memory devices are interfaced correctly with the microcontroller and other components in the system.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads