On the Data,idata,xdata,pdata,code data types in the programming of Keil microcontroller

Source: Internet
Author: User

From the data storage type, the 8051 series has on-chip, off-chip program memory, on-chip, off-chip data memory, the on-chip program memory is also divided into direct addressing area and indirect addressing type, respectively, corresponding to code, data, XData, idata, and according to the characteristics of the 51 series pdata type, Using different memory will make program execution more efficient, and when writing a C51 program, it is best to specify the storage type of the variable, which will help improve program execution efficiency (this problem will be explained later). and ansi-c slightly different, it only sub-SAMLL, COMPACT, large mode, a variety of different models corresponding to the actual hardware system, there will be different compilation results.


Differences in Data,idata,xdata,pdata in the 51 series:
Data: Fixed refers to the front 0x00-0x7f 128 ram, can be directly read and write with ACC, the fastest, the resulting code is minimal.
Idata: Fixed refers to the previous 0X00-0XFF 256 RAM, where the first 128 and data 128 are identical, only because of the way the access is different. Idata is accessed in a pointer-like manner in C. The statements in the assembly are: Mox ACC, @Rx. (Unimportant supplement: C-Idata do a good job of pointer-type access)
XData: External extended RAM, generally referred to as external 0x0000-0xffff space, accessed with dptr.
pdata: Low 256 bytes of external extended RAM, address reads and writes on A0-A7, with Movx ACC, @Rx Read and write. This is more special, and C51 seems to have a bug, it is recommended to use less. But also has his merit, the concrete usage belongs to the intermediate question, here does not mention.
Microcontroller C language unsigned char code table[] code is what role?
The role of code is to tell the microcontroller, I define the data to be placed in the ROM (program store) inside, can not be changed after writing, in fact, is quite with the assembly inside the address MOVX (as if), because there is no way to describe in C in detail whether the ROM or RAM (register), So in the software added this statement to replace the assembly instructions, and the corresponding data is stored in RAM meaning.
The program can be easily divided into code (program) area, and data area, the code area is not changed when running, the data area to put the global variables and temporary variables, is to constantly change, the CPU from the code area read instructions, the data area to perform operations processing, So the code area stored in what medium is not important, like the previous computer program stored on the card, the code area can also be placed in the ROM, also can be placed in RAM, also can be placed in flash (but the speed is much slower, the main read flash than read RAM time), So the general practice is to put the program in Flash, and then load into the RAM to run, the data area there is no choice, it must be placed in RAM, placed in the ROM can not be changed.


How does bdata use it?
If the program requires 8 or more bit variables, if you want to give 8 variables at a time to assign value, it is not convenient, (for example, say it's convenient, want to know more in-depth understanding in the application itself) and can not define a bit array, there is only one method
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;
A 8 bit variable mode_n is defined.
This is the special data type that defines the statement, KEILC. Remember, it must be sbit.
Cannot bit mode_0 = mode^0;
Assignment statements If all these C languages are treated as XOR or arithmetic
//------------------------------------------------------------------------------------------------------------- -----
Space Name address range description
DATA D:00H~7FH in-chip RAM direct addressing area
bdata D:20H~2FH in-chip ram-bit addressing area
IDATA I:00H~FFH in-chip RAM indirect addressing area
XDATA X:0000H~FFFFH 64KB Conventional off-chip RAM data area
hdata X:0000H~FFFFFFH 16MB extended off-chip RAM data area
code C:0000H~FFFFH 64K Regular on-chip ROM area
hconst (Ecode) C:0000H~FFFFFFH 16MB extended off-chip ROM constant area (available as code area for Dallas390)
bank0~bank31 B0:0000H~FFFFH
:
:
B31:0000H~FFFFH Block code area, maximum expandable 32x64kb ROM
//------------------------------------------------------------------------------------------------------------- ----------------------------
Files generated by Keil:
. PLG: Compiler compilation results
. Hex and. Bin: Executable files
. Map and. LST: Linked files
. O: Target file
. CRF,. LNP,. D, and. AXF: Debug Files
. OPT: Save project configuration information
. BAK: Project backup file
M51 file, startup file.

Note: This document is collected from the network

On the Data,idata,xdata,pdata,code data types in the programming of Keil microcontroller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.