51 MCU array definition method

Publisher:明理厚德Latest update time:2015-08-10 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
If "code" or "data" is not added before the array, the array is stored in the program memory by default;
code specifies that the data is stored in the code area. The data is written into the code memory together with the code during programming and cannot be changed during operation;
xdata specifies that the data is stored in the external data memory;
data specifies that the data is stored in the internal lower 128-byte data memory. If the variable does not specify the storage location, the default is data type, and this part of the memory has the fastest addressing speed;
idata specifies that the data is stored in the internal lower 256-byte data memory, but 51 has only 128 bytes of internal RAM, and 52 has 256 bytes;
pdata specifies that the data is stored in the external lower 256-byte data memory. At this time, the 8-bit registers R0 and R1 are used for addressing instead of the 16-bit DPTR, and the addressing speed is faster than xdata.

What is the function of the unsigned char code table[] code in the 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 MOVC (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 it 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.

Attachment:

Storage Types in C51

code: program storage area (64KB),

data: directly addressable internal data storage area (128B)

idata: internal data storage area that is not directly addressable (256B)

bdata: bit-addressable internal data storage area (16B)

xdata: external data storage area (64KB)

pdata: paging external data storage area

data ---> addressable on-chip ram
bdata ---> bit-addressable on-chip ram
idata ---> addressable on-chip ram, allows access to all internal ram
pdata ---> paged addressable off-chip ram (MOVX @R0) (256 BYTE/page)
xdata ---> addressable off-chip ram (64k address range)
code ---> program storage area (64k address range), corresponding to MOVC @DPTR

 
   
 
const means that this array cannot be modified. The array is a constant array. code means that this array is in the ROM area after it is generated and cannot be modified. idata means that the array is in the 256 RAMs from 0x00 to 0xff after it is generated. Use pointer addressing. For details, refer to the following data, bdata, idata, pdata, xdata, code storage types and storage areas. bit is the address of a bit in the 20H .. 2FH area in the internal data storage space, or a bit address of the 8051 bit addressable SFR. code is a code address between 0000H and 0FFFFH. data is a data memory address between 0 and 127, or a special function register (SFR) address between 128 and 255. idata is an idata memory address between 0 and 255. xdata is an xdata memory address between 0 and 65535.
Reference address:51 MCU array definition method

Previous article:Single chip microcomputer controls MC55 module to realize remote wireless data transmission
Next article:Interface circuit diagram of DC speed measuring generator and single chip microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号