51 microcontroller (code, idata, keyword notes)

"code" keyword 51 unique

There is a kind of data that we want to use in the program, but it will not change its value. When defining this kind of data, you can add a code keyword to modify it, and this data will be stored in our program space Flash, so It can greatly save the RAM usage of the MCU. After all, the RAM space of our MCU is relatively small, while the program space is much larger. Then the truth table of digital tubes to be used now, we only use their values, without changing them, we can use the code keyword to put it into Flash.

Keywords in the Keil C51 language, representing the division of different RAM areas

data: on-chip RAM from 0x00~0x7F
idata: on-chip RAM from 0x00~0xFF
pdata: off-chip RAM from 0x00~0xFF
xdata: off-chip RAM from 0x0000~0xFFFF

In Keil's default settings, data can be omitted, that is, when nothing is added, the variables are defined in the data area.

The RAM access in the data area uses direct addressing in assembly language and the execution speed is the fastest. If you define it as idata, you can access not only the data area, but also the range of 0x80H~0xFF, but after adding the idata keyword, the 51 single-chip microcomputer uses general register indirect addressing when accessing, which is slower than data .

And we usually don’t want to access 0x80H~0xFF in most cases, because this block is usually used for interrupt and function call stack, so in most cases, when we use internal RAM, we only use data. .

For external RAM, the variables defined by pdata are stored in the address range of 0x00~0xFF of external RAM. The access of this address is similar to idata, which is indirect addressing with general registers. If you define xdata,

The range that can be accessed is wider, and the range of access is wider. Addresses from 0 to 64K can be accessed, but it needs to use 2 byte registers DPTRH and DPTRL for indirect addressing, and the speed is the slowest.

————————————————
Copyright Statement: This article is the original article of the CSDN blogger "zager", which follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting .
Original link: https://blog.csdn.net/weixin_40379058/article/details/79416994

Guess you like

Origin blog.csdn.net/weixin_43244265/article/details/106084630