In terms of data storage type, the 8051 series has on-chip and off-chip program memory, on-chip and off-chip data memory. The on-chip program memory is also divided into direct addressing area and indirect addressing type, corresponding to code, data, xdata, idata and pdata type set according to the characteristics of the 51 series. Using different memories will make the program execution efficiency different. When writing C51 programs, it is best to specify the storage type of variables, which will help improve the program execution efficiency (this issue will be specifically discussed later). Slightly different from ANSI-C, it is only divided into SAMLL, COMPACT, and LARGE modes. Different modes correspond to different actual hardware systems and will also have different compilation results.
The difference between data, idata, xdata, and pdata in the 51 series:
Data: Fixedly refers to the first 128 RAMs from 0x00 to 0x7f, which can be read and written directly using acc, with the fastest speed and the smallest generated code.
idata: Fixedly refers to the first 256 RAM from 0x00 to 0xff, of which the first 128 are exactly the same as the 128 of data, but the access method is different. idata is accessed in a pointer-like manner similar to C. The statement in the assembly is: mox ACC, @Rx. (Unimportant supplement: pointer-style access to idata in C works very well)
xdata: External extended RAM, generally refers to the external 0x0000-0xffff space, accessed using DPTR.
pdata: The lower 256 bytes of external expansion RAM, read and write when the address appears on A0-A7, use movx ACC,@Rx to read and write. This is quite special, and C51 seems to have a bug for this, so it is recommended to use it less. But it also has its advantages. The specific usage belongs to the intermediate problem, so it will not be mentioned here.
What is the function of unsigned char code table[] code in microcontroller C language?
The role of code is to tell the microcontroller that the data I define should be placed in ROM (program storage area), and it cannot be changed after being written. In fact, it is equivalent to the addressing MOVX (it seems) in the assembly language. Because the C language cannot describe in detail whether it is stored in ROM or RAM (register), this statement is added to the software to replace the assembly instruction. The corresponding data also means that the data is stored in RAM.
The program can be simply divided into code (program) area and data (data) area. The code area cannot be changed during running. The data area is used to store global variables and temporary variables, which need to be constantly changed. The CPU reads instructions from the code area and performs operations on the data in the data area. Therefore, it does not matter what medium the code area is stored on. Computer programs were stored on cards before. The code area can also be placed in ROM, RAM, or flash (but the running speed will be much slower, mainly because reading flash takes more time than reading RAM). Therefore, the general practice is to put the program in flash and then load it into RAM to run; there is no choice for the DATA area, it must be placed in RAM, and it cannot be changed if it is placed in ROM.
How to use bdata?
If the program needs 8 or more bit variables, it is not convenient if you want to assign values to 8 variables at once. (Give an example to explain its convenience. If you want to understand it more deeply, please think about it yourself in the application.) You cannot define a bit array. There is only one way
char bdata MODE;
sbit MODE_7 = MODE^7;
sbit MODE_6 = MODE^6;
sbit MODE_5 = MODE^5;
sbit MODE_4 = MODE^4;
sbit MODE_3 = MODE^3;
sbit MODE_2 = MODE^2;
sbit MODE_1 = MODE^1;
sbit MODE_0 = MODE^0;
8 bit variables MODE_n are defined.
This is a definition statement, a special data type of Keilc. Remember that it must be sbit
and not bit MODE_0 = MODE^0;
If the assignment statement is written like this, C language will regard it as an exclusive OR operation.
Space Name
Address range
illustrate
DATA
D:00H~7FH
On-chip RAM direct addressing area
BDATA
D:20H~2FH
On-chip RAM bit addressable area
DATA
I:00H~FFH
On-chip RAM indirect addressing area
XDATA
X:0000H~FFFFH
64KB regular off-chip RAM data area
HDATA
X:0000H~FFFFFFH
16MB extended off-chip RAM data area
CODE
C:0000H~FFFFH
64K conventional on-chip and off-chip ROM code area
HCONST(ECODE)
C:0000H~FFFFFFH
16MB extended off-chip ROM constant area (can be used as code area for Dallas390)
BANK0~BANK31
B0:0000H~FFFFH
:
:
B31:0000H~FFFFH
Group code area, maximum expandable 32X64KB ROM
Files generated by keil:
.plg: compiler compilation results.hex
and .bin: executable files.map
and .lst: link files.o
: target files.crf
, .lnp, .d and .axf: debugging files.opt
: save project configuration information.bak
: project backup file
M51 file, startup file.
The storage space resource allocation of ordinary 51 series microcontrollers:
Space Name |
Address range |
illustrate |
DATA |
D:00H~7FH |
On-chip RAM direct addressing area |
BDATA |
D:20H~2FH |
On-chip RAM bit addressable area |
DATA |
I:00H~FFH |
On-chip RAM indirect addressing area |
XDATA |
X:0000H~FFFFH |
64K off-chip RAM data area |
CODE |
C:0000H~FFFFH |
64K on-chip and off-chip ROM code area |
BANK0~BANK31 |
B0:0000H~FFFFH
:
:
B31:0000H~FFFFH |
Group code area, maximum expandable 32X64KB ROM |
Space Name |
Address range |
illustrate |
DATA |
D:00H~7FH |
On-chip RAM direct addressing area |
BDATA |
D:20H~2FH |
On-chip RAM bit addressable area |
DATA |
I:00H~FFH |
On-chip RAM indirect addressing area |
XDATA |
X:0000H~FFFFH |
64KB regular off-chip RAM data area |
HDATA |
X:0000H~FFFFFFH |
16MB extended off-chip RAM data area |
CODE |
C:0000H~FFFFH |
64K conventional on-chip and off-chip ROM code area |
HCONST(ECODE) |
C:0000H~FFFFFFH |
16MB extended off-chip ROM constant area (can be used as code area for Dallas390) |
BANK0~BANK31 |
B0:0000H~FFFFH
:
:
B31:0000H~FFFFH |
Group code area, maximum expandable 32X64KB ROM
|
Previous article:51 MCU drive AD7799 program (keil c)
Next article:Multi-motor soft start system based on single chip microcomputer
- 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
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Happy Dragon Boat Festival, salty rice dumplings, sweet rice dumplings, which kind do you like?
- [Topmicro Intelligent Display Module Review] 5. Development Board NUCLEO-F746ZG Communication with Intelligent Display Module
- How to safely measure high voltage with a LOTO oscilloscope?
- Please restore the number of invitees to 8. Thank you. Thank you. I invited 8 people before, but there are already 6 people in the list.
- SensorTile.Box Expert Mode Gyroscope Sensor
- Why is the single-ended impedance on the PCB controlled to 50 ohms?
- Experts talk about IPC7351
- CC1101 Study Notes - Preliminary Understanding
- 5G commercial use is on the way, are you ready?
- Chat with Vicor engineers about efficient power supply and learn about modular power solutions for drones!