About data, idata, xdata, pdata, code in keil

Publisher:RadiantEnergyLatest update time:2015-12-25 Source: eefocusKeywords:keil  data  idata  xdata  pdata  code Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
    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 like this, C language will treat it as an XOR 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
IDATA
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.


Keywords:keil  data  idata  xdata  pdata  code Reference address:About data, idata, xdata, pdata, code in keil

Previous article:MCU PID Program
Next article:Keil "RECURSIVE CALL TO SEGMENT" completely solves

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号