ACCESSING EXTERNAL DATA MEMORY IN 8051 C

SECTION 14.5: ACCESSING EXTERNAL DATA MEMORY IN 8051 C
In Chapter 7, we showed how to place fixed data into the code space using 8051 C. In that chapter we also showed how to access fixed data stored in the code space of the 8051 family. In this section we show how to access the external data space of the 8051 family using C language. To access the external data space (RAM or ROM) of the 8051 using C, we use XBYTE[loc] where loc is an address in the range of 0000 – FFFFH. Example 14-18 shows how to write some data to external RAM addresses starting at 0. Notice that the XBYTE function is part of the absacc.h header file. Examine Examples 14-19 and 14-20 to gain some mastery of accessing external data memory using C.
Accessing DS89C4xO’s 1KB SRAM in C

In Section 14.4 we discussed how to access the 1KB SRAM of the DS89C4xO chip using Assembly language. Examples 14-21 and 14-22 will show the 8051 C version of some of the Assembly programs.



Example 14-18
Write a C program (a) to store ASCII letters ‘A’ to ‘E’ in external RAM addresses starting at 0, then (b) get the same data from the external RAM and send it to PI one byte at a time.
Solution:


Run the above program on your 8051 simulator and examine the contents of xdata to verify the result.
Example 14-19
An external ROM uses the 8051 data space to store the look-up table (starting at 100H) for DAC data. Write a C program to read 30 bytes of table data and send it to PI.
Solution:


Example 14-20
Assume that we have an external RAM with addresses 0000 – 2FFFH for a given 8051-based system, (a) Write a C program to move the message “Hello” into external RAM, and (b) read the same data in external RAM, and send it to the serial port.
Solution:





Example 14-21
Write a C program (a) to enable the access to the 1KB SRAM of the DS89C4xO, (b) put the ASCII letters ‘A’, ‘B’ and ‘C’ in SRAM, and (c) read the same data from SRAM and send each one to ports PO, PI, and P2. This is the C version of an earlier example.
Solution:




Example 14-22
Write a C program to (a) enable access to the 1KB SRAM of the DS89C4xO, (b) move a block of data from the code space of the DS89C420 chip into 1KB SRAM, then (c) read the same data from SRAM and send it to the serial port of the 8051 one byte at a time.
Solution:


SUMMARY
This chapter described memory interfacing with 8031/51-based systems. We began with an overview of semiconductor memories. Types of memories were compared in terms of their capacity, organization, and access time.

ROM (read-only memory) is nonvolatile memory typically used to store programs. The relative advantages of various types of ROM were described in this chapter, including PROM, EPROM, UV-EPROM, EEPROM, flash memory EPROM, and mask ROM.
RAM (random-access memory) is typically used to store data or programs. The relative advantages of its various types, including SRAM, NV-RAM, checksum byte RAM, and DRAM, were discussed.
Address decoding techniques using simple logic gates, decoders, and programmable logic were covered. RAM and ROM memories were interfaced with 8031 systems, and programs were written to access code and data stored on these external memories. The 64KB of external data space of the 8051 was discussed, and programs were written in both Assembly and C to access them. Finally, the 1 KB SRAM memory of the DS89C4xO chip was explored and we showed how to access it in both Assembly and C.

Next post:

Previous post: