About code, idata, xdata in C51

Publisher:创新火花Latest update time:2022-06-27 Source: eefocusKeywords:C51  code  idata  xdata 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 the 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.


Keywords:C51  code  idata  xdata Reference address:About code, idata, xdata in C51

Previous article:Notes on using printf in KEIL C51
Next article:How to implement mixed programming of C51 and assembly

Recommended ReadingLatest update time:2024-11-23 08:28

C51 key recognition, waiting for release
#include reg51.h unsigned char val; unsigned char i,j,k; sbit k1=P3^4; void delayms(int ms) // 1ms {  unsigned char i,j;  for(;ms 0;ms--)   for(i=6;i 0;i--)    for(j=82;j 0;j--); } void main() {  val=0xff;  while(1)  {   if(k1==0)   {    delayms(10);    if(k1==0)    {     P0=val;     val--;    }    while(k1==0); //Wai
[Microcontroller]
How to implement soft reset in C51?
You can define a function pointer to the reset vector (0x0000), and then call the function where a soft reset is required in the C program: ((void (code *) (void)) 0x0000) (); For example, the following program constantly resets: void reset (void) {   ((void (code *) (void)) 0x0000) (); } void main (void) {   r
[Microcontroller]
C51 source program to calculate the week by date
#include #define uint unsigned int #define uchar unsigned char uchar code monthday ={31,28,31,30,31,30,31,31,30,31,30,31};   uchar month_n_day(uint y,uchar m) //Calculate how many days there are in a certain month and year {        if(m==2)               return(((y%4 == 0) && (y%100 != 0) || (y%400 == 0))? 29
[Microcontroller]
Definition and application of C51 microcontroller interrupt function
C51 function declaration extends ANSI C, specifically including: 1. Interrupt function declaration: The interrupt declaration method is as follows: void serial_ISR () interrupt 4 { /* ISR */ } In order to improve the fault tolerance of the code, generate iret statements at unused interrupt entries and define unused i
[Microcontroller]
Definition and application of pointer variables of C51 microcontroller
one. Definition of pointer variables The definition of pointer variables is similar to the definition of general variables, and its form is as follows: Data type * identifier; Indicates that it is defined as a memory-based pointer. Without this option, it is defined as a general pointer. The difference between th
[Microcontroller]
Definition and application of pointer variables of C51 microcontroller
How to realize communication between C51 microcontroller and PLC
1. HMI (Human Machine Interface) is increasingly used in industrial automation systems and equipment due to its small size, high performance, and strong real-time characteristics. It has different displays such as letters, Chinese characters, graphics and pictures, and the interface is simple and friendly. Equipped
[Microcontroller]
[MPLAB] Share a MPLAB X IDE plugin --- Code Configurator
I recently used an MPLAB plug-in and found it quite convenient. I would like to share it with you: Code Configurator is a free graphical programming environment that can automatically generate C code for PIC through simple selection functions, saving time. Code Configurator official address For the convenience of ex
[Microcontroller]
Common Problems of C51 Microcontroller in Electronic Circuit Design
I have used 51 MCUs such as AT89C2051, AT89C51, AT89C52, etc. in my work. Later, I used 51 MCUs from Taiwan Xinmao, Winbond and other manufacturers. I encountered many problems in practice, which were not in the books. I remember that the knowledge in the books only had one page of illustrations, which was the timin
[Microcontroller]
Common Problems of C51 Microcontroller in Electronic Circuit Design
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号