8051 Memory Organization
The 8051 microcontroller's memory is divided into Program Memory and Data Memory. Program Memory (ROM) is used for permanent saving program being executed, while Data Memory (RAM) is used for temporarily storing and keeping intermediate results and variables.
Program Memory (ROM)
Program Memory (ROM) is used for permanent saving program (CODE) being executed. The memory is read only.
Depending on the settings made in compiler, program memory may also used to store a constant variables.
The 8051 executes programs stored in program memory only. code
memory type specifier is used to refer to program memory.
8051 memory organization alows external program memory to be added.
How does the microcontroller handle external memory depends on the pin EA logical state.
Internal Data Memory
Up to 256 bytes of internal data memory are available depending on the 8051 derivative. Locations available to the user occupy addressing space from 0 to 7Fh, i.e. first 128 registers and this part of RAM is divided in several blocks. The first 128 bytes of internal data memory are both directly and indirectly addressable. The upper 128 bytes of data memory (from 0x80 to 0xFF) can be addressed only indirectly.
Since internal data memory is used for CALL stack also and there is only 256 bytes splited over few different memory areas fine utilizing of this memory is crucial for fast and compact code. See types efficiency also.
Memory block in the range of 20h to 2Fh is bit-addressable, which means that each bit being there has its own address from 0 to 7Fh.
Since there are 16 such registers, this block contains in total of 128 bits with separate addresses
( Bit 0 of byte 20h has the bit address 0, and bit 7 of byte 2Fh has the bit address 7Fh).
Three memory type specifiers can be used to refer to the internal data memory: data
, idata
, and bdata
.
External Data Memory
Access to external memory is slower than access to internal data memory.
There may be up to 64K Bytes of external data memory. Several 8051 devices provide on-chip XRAM space that is accessed with the same instructions as the traditional external data space.
This XRAM space is typically enabled via proper setting of SFR register and overlaps the external memory space. Setting of that register must be manualy done in code, before any access to external memory or XRAM space is made.
The mikroBasic PRO for 8051 has two memory type specifiers that refers to external memory space: xdata
and pdata
.
SFR Memory
The 8051 provides 128 bytes of memory for Special Function Registers (SFRs).
SFRs are bit, byte, or word-sized registers that are used to control timers, counters, serial I/O, port I/O, and peripherals.
Refer to Special Function Registers for more information. See sbit
also.
What do you think about this topic ? Send us feedback!