Reference source: Keil > Help > uVision Help > Cx51 Compiler User's Guide > Language Extensions > Memory Types
Storage Type
The Cx51 compiler can access all storage areas of the 8051. When declaring a variable, you can specify the allocated storage area, or you can make implicit allocations based on the memory model configuration.
In actual projects, xdata and code are often used.
Instructions
When declaring/defining variables, add the keywords data, idata, bdata, pdata, xdata, code.
unsigned char data var1;
unsigned char code text[] = "ENTER PARAMETER:";
unsigned char xdata array[100];
unsigned char idata x,y,z;
unsigned char pdata dimension;
unsigned char xdata vector[10][4][4];
unsigned char bdata flags;
When the MCU accesses the internal RAM, the reading and writing speed is faster than the extended RAM.
Therefore, when writing application code, place frequently used variables in internal RAM and less frequently used variables in external RAM.
Variables in Flash can only be read and are saved when power is off.
Variables in RAM can be read and written, but are not saved when power is off.
Detailed description
8051 Memory Structure
data
Data can only declare variables, not functions.
When reading and writing data variables, the MCU uses an 8-bit address to directly address the internal RAM (lower 128 bytes).
The advantage is the fastest reading and writing speed, and the disadvantage is that the available space is too small.
idata
idata can only declare variables, not functions.
When reading and writing idata variables, the MCU indirectly addresses the internal RAM (all 256 bytes) using an 8-bit address.
The accessible space is all 256 bytes of internal RAM, of which the lower 128 bytes are duplicated with the data space, but the access method is different.
bdata
bdata can only declare variables, not functions.
When reading and writing bdata variables, the MCU uses 8 address bits to address/directly address the internal RAM (part of 16 bytes).
The accessible space is 16 bytes of internal RAM, with an address range of 0x20~0x2F, located inside the data space.
pdata
pdata can only declare variables, not functions.
When reading and writing the pdata variable, the MCU uses an 8-bit address to indirectly address the extended RAM (the lower 256 bytes, a page).
xdata
xdata can only declare variables, not functions.
When reading and writing xdata variables, the MCU uses 16-bit addresses to indirectly address the extended RAM (all addresses, up to 64K bytes).
code
code can declare constants or functions.
When reading code constants, the MCU uses a 16-bit address to indirectly address the Flash space (maximum 64K bytes).
When declaring a function, the compiler implicitly adds the code keyword by default, and the user does not need to deal with it.
Previous article:8051 MCU Basics 3: C51 Memory Model (small, compact and large)
Next article:8051 MCU Basics 6: General Pointers and Directional Pointers
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Applications of RF Transformers
- RF FilterRF knowledge classics to understand
- 【NXP Rapid IoT Review】+Hello world!
- 5G miniaturized terminal and base station antenna technology
- DIY retro game console based on Raspberry Pi Zero
- Transistor static operating point
- The History of DSP and Why No One Mentions DSP Anymore
- RISC-V MCU IDE MRS (MounRiver Studio) development: Add standard math library reference
- A brief introduction to the timer A function of the 430 microcontroller
- [Social Recruitment] Capital Securities Recruitment [Semiconductor Researcher]