Memory types and regions on 8051
Memory model
l Memory type indication
l Variable type indication
l Bit variables and bit-addressable data
l Special Function Registers
Pointer
Function attributes
Keywords
_at_
alien
bdata
bit
code
compact
data
idata
interrupt
large
pdata
_priority_
reentrant
sbit
sfr
sfr16
small
_task_
using
xdata
You can disable the use of these extensions with the NOEXTEND control directive
8051 Memory Areas
The 8051 architecture supports a number of physically separate memory areas or spaces for data and programs. Each memory area has its advantages and disadvantages. Some areas are readable but not writable, some are both readable and writable, and some are read and written much faster than others. This variety of memory spaces is different from mainframes, minicomputers, and microcomputers that place all data, programs, and constants in the same physical space within the computer.
Program Memory
Program memory is read-only memory and cannot be written to. Depending on the variant and hardware design of 8051, program memory can be internal to the 8051 CPU, external to it, or both. Program memory can be up to 64K bytes. Program code including all functions and runtime libraries are placed in program memory. Constants can also be placed in program memory. 8051 only executes programs that are placed in program memory.
In Cx51, program memory can be accessed through CODE type instructions
Internal Data Memory
Internal data storage exists inside the 8051 CPU and can be read and written. Depending on the 8015 variant, this internal data storage can be up to 256 bytes. The first 128 bytes can be addressed directly or indirectly. The next 128 bytes can only be accessed indirectly. The 16 bytes starting at 20h are bit addressable.
Since the internal data memory can be accessed using an 8-bit address, accessing the internal data memory is very fast. However, the internal data memory is only 256 bytes.
Using Cx51, the internal data memory can be divided into three different data types: data, xdata and bdata
The Data memory pointer refers only to the first 128 bytes of the internal data memory. Data placed in this area is accessed using direct addressing.
Idata refers to all 256 bytes of internal data memory; however, data placed in this area is accessed through indirect addressing, which is slightly slower than direct addressing.
Bdata refers to the 16-byte bit-addressable space starting from 20h. This area can declare bit-addressable data.
External Data Memory
(slightly)
Special Function Register Memory
(slightly)
Memory Models
The memory model determines the default memory type for function parameters, automatic variables, and variables without a declared memory type.
Note: Except for very special applications, use SMALL memory type. This will generate code that runs faster and more efficiently.
Small Model
In this mode, all variables are placed in the internal data memory area of 8051 by default. Data access efficiency is very high in this mode. However, the stack is also placed in the internal RAM, so the stack size requirement is very demanding. If the linker/compiler is configured to overwrite the internal data memory, then this mode is the best choice.
Compact Model
In this mode, all variables are placed in the first page of the external data memory. 256 bytes of variables can be stored in this mode. The limitation of this mode comes from its addressing method, which uses registers R0 and R1 for addressing. This mode is not as efficient as small mode, and variable access is not as fast. But this mode is faster than large mode.
When using compact mode, Cx51 uses @R0 and @R1 to access external data memory. If you want to access external data memory higher than 256 bytes, the high byte can be provided through Port 2. In this case, you must correctly initialize Port2 to the correct page number of the external data memory. This can be done in the startup code. You must also specify the starting address of PDATA for the connector.
Large Model
In large mode, all variables are placed in an external data memory area (up to 64K bytes). The data pointer (DPTR) is used for addressing. Memory access through this data pointer is inefficient, especially for variables with a data size greater than 2 bytes. This access method generates more code than small and compact methods.
Memory Types
The Cx51 compiler explicitly supports the 8051 architecture and base variants, and provides access to all 8051 memory areas. Each variable can be explicitly assigned to a specific memory space.
Explicitly Declared Memory Types
You can specify the storage area for a variable by including a memory type identifier in its declaration.
type |
describe |
code |
Data memory (64K bytes), accessed by movc @a+dptr |
data |
Directly addressable internal data memory, fastest addressing of variables |
idata |
Indirect addressing of internal data memory, addressing the internal 256 bytes |
bdata |
Internal bit-addressable area, bit-addressable and byte-addressable (16 bytes) |
xdata |
External data memory, addressed by mov @dptr |
pdata |
Addressing a page (256 bytes) of external data memory, addressed by movx @Rn |
With the signed and unsigned attributes, you can include the storage type identifier in the variable declaration.
char data var1;
char code text[] = "ENTER PARAMETER:";
unsigned long xdata array[100];
float idata x,y,z;
unsigned int pdata dimension;
unsigned char xdata vector[10][4][4];
char bdata flags;
Note: In previous versions
data char x;
Equivalent to
char data x;
However, in future versions of the Cx51 compiler, this feature will no longer be supported.
Implicit Memory TypesDefault memory type
If the variable default memory type identifier is specified when the variable is declared, the default memory type is automatically selected. Function parameters or automatic variables that cannot be placed in registers are also stored in the default memory area.
The default memory type is determined by the compiler based on the SMALL, COMPACT, and LARGE settings.
Previous article:C51 Compiler - Language Extensions (2) - Data Types
Next article:2-way DS18B20 control
Recommended ReadingLatest update time:2024-11-16 12:24
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Compiler Principles C Language Description (Ampel)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Patent application
- 【Portable Programmable Meter】Project Submission
- There is a basic question about AD9
- After current sampling, the inverted ratio is amplified by 2 times (U9A), and then the output is connected to the form of a hysteresis comparator (U9B), which is...
- DSP-BIOS usage from environment to building the first project
- File status after dup and fork functions are executed
- EEWORLD University Hall----Live Replay: Explore the Black Technology of Network Cameras with Infineon
- Tesla Coil 2 "Low Power Discharge + Detailed Pictures" Welcome to guide
- Problems with the multi-function Bluetooth remote control
- Problems in FPGA Experiments