XBYTE defines the external address so that it can communicate with the device connected to your IO port.
In general programs that read and write external RAM, you often see sentences like this:
The access instruction is like the 51's MOVX instruction you mentioned here (it will be compiled into this instruction in C language). When executing this instruction, the three groups of lines work in coordination.
mov dptr,#1000h
mov a,#55h
movx @dptr,a
The above three call statements can be expressed in C language as follows
#define
W_DATA=0X55;
When using the external bus, the data address and control signal are directly output high and low levels according to the specified timing, so you don't have to worry about it. Of course, you must meet the timing work. How to understand #define XBYTE ((unsigned char
volatile xdata * ))
8051 unique memory type
code
data
idata
bdata
xdata
pdata
Special data type
bit
sbit
Syntax
sbit
Example
sbit
or bit variable declared with bdata
char
sbit
(Note that static cannot be added before sbit)
sfr
Syntax
sfr
Example
sfr
Specify the absolute address of the variable
In a single module, you can use the following syntax to declare
[memory_space]
Example
pdata
If the variable must be used by multiple modules (Global Variable),
it is more convenient to define it in the header file as an abstract pointer.
#define
Example
#define
(Note the order of char and pdata)
ABSACC.H provides the following convenient macro definitions.
#define CBYTE ((unsigned char volatile code *) 0)
#define DBYTE ((unsigned char volatile data *) 0)
#define PBYTE ((unsigned char volatile pdata *) 0)
#define XBYTE ((unsigned char volatile xdata *) 0)
#define CWORD ((unsigned int volatile code *) 0)
#define DWORD ((unsigned int volatile data *) 0)
#define PWORD ((unsigned int volatile pdata *) 0)
#define XWORD ((unsigned int volatile xdata *) 0)
Hidden initialization program
The first program module executed by 80C51 after power reset (Power On Reset) is not the user's main program
main(), but a program module called startup.a51 hidden in the KEIL-C51 standard link library.
The main task of startup.a51 is to clear the memory blocks including idata, xdata, and pdata to 0, and
initialize the recursive pointer. Then startup.a51 is still executed by a
program module called init.a51 hidden in the KEIL-C51 standard link library. The main task of init.a51 is to initialize
variables with non-zero initial values.
After completing the above initialization program, the control of 80C51 will be handed over to main() to start executing the user's program.
#define XBYTE ((unsigned char volatile xdata *) 0)
defines
In this way, you can directly use XBYTE[0xnnnn] or *(XBYTE+0xnnnn) to access external RAM.
Among them, the initial address is 0x0000;
Baidu Knows:
#define XBYTE((char*)0x20000L) XBYTE[0x8000]=0x41; What does this procedure mean? #define XBYTE ((char*)0x20000L) defines XBYTE as a character pointer (or array) variable pointing to address 0x20000L XBYTE[0x8000]=0x41; Assign a value of 0x41 to the variable 0x8000 of the array XBYTE. That is, assign a value of 0x41 to the memory unit at address 0x28000L. This means that you are using a 51 chip with an external data bus. The external memory is most likely RAM, and the capacity of RAM is at least 0x8000 (32k) bytes. The capacity of RAM may be 64k bytes? If you still have questions, please send a message to contact Supplement 1: L stands for long, which means 0x20000L is a long integer. Generally speaking, in 8-bit microcontrollers such as 51, integers are represented by 16 bits of binary and long integers are represented by 32 bits of binary.
There is also this use:
Write a header file like this
Such a format:
Type storage space definition alias keyword _at_ register address
The keyword _at_ is an absolute definition of the address
Previous article:How to create multiple C files and precautions for 51 single chip microcomputer KEIL
Next article:Implementation of I2C bus protocol for 51 single chip microcomputer
Recommended ReadingLatest update time:2024-11-15 07:34
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- EEWORLD University Hall----Live Replay: ADI Digital Active Noise Cancelling Headphone Solution
- If the number of 1 bits in the accumulator is odd, P is set (odd parity); otherwise, P is cleared.
- 【NXP Rapid IoT Review】W3 Environmental Data Collection
- [Flower carving hands-on] Interesting and fun music visualization project (09) - X Music Spectrum
- Fudan Micro FM33LC046N Review Summary
- TMS320C55x Assembly Language Programming
- Tektronix 618 promotion has started! The lowest price of the year!
- Request a cadencePCB file
- MSP-FET430UIF Win8 Driver
- National College Student Electronic Design Competition TI Processor Board Application Details