The XBYTE macro accesses individual bytes in the external data memory of the 8051. You may use this macro in your programs as follows:
#include
.
.
.
rval = XBYTE [0x0002];
XBYTE [0x0002] = 57;
.
.
.This example reads and writes the contents of the byte in external data memory at address 0002h.
The range of valid index values for this macro is 0-65535.
http://www.keil. com/support/man/docs/c51/c51_xbyte.htm
The above is obtained by ctrl+c in keil's help. I have seen someone in the forum asking how to use C language to implement positioning storage. Haha, I still said no at that time. It's possible! Now when I was searching for using, I accidentally saw XBYTE. I clicked on it and found something great!
Baidu results: This is mainly used when using C51's P0 and P2 ports for external expansion. Among them, XBYTE [0x0002], P2 port corresponds to the high bit of the address, and P0 port corresponds to the low bit of the address. Generally, the P2 port is used for control signals, and the P0 port is used as a data channel.
For example: P2.7 is connected to WR, P2.6 is connected to RD, and P2.5 is connected to CS, then an address of the external RAM can be determined. When you want to write a byte to an address of the external RAM, the address can be set as XBYTE [ 0x4000], where WR and CS are low and RD is high, which is the high bit 4. Of course, the rest can be determined according to the situation, and then pass
XBYTE [0x4000] = 57. With this assignment statement, 57 can be written to 0x4000 of the external RAM. This address corresponds to one byte.
Excerpted from the Q&A of forum netizens:
Question:
In general programs for reading and writing external RAM, we often see sentences like this:
XBYTE[address]=data Write data
data="XBYTE"[address] Read data
But what I want to ask Yes, why do we no longer need to take into account the timing after using XBYTE?
In other words, when reading and writing data, why don't WR and RD need to be controlled by programs?
I have referred to many programs for reading and writing external RAM, but I can't find the statements that control the WR and RD control lines.
Can anyone help explain why this is?
It would be best if you can also talk about the specific usage of XBYTE...
Answer:
External bus,
1 The external bus consists of 3 groups of buses, and the data address is controlled. We often call it the external bus, since there are 3 different groups of signals. , so how do they coordinate their work? Generally speaking, the CPU has special external data access instructions, such as the 51 MOVX instruction you are talking about 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, the C language of the above 3 -
tone statement can be expressed as follows #define
W_DATA Yes, so you don’t need to worry about it. Of course , you must meet the timing requirements. Excerpted from a netizen’s blog article: How to understand #define data Internal data memory idata that can be directly accessed Internal data memory bdata that can be accessed with Mov @Rn Internal memory xdata that can be bit addressable (Bit Addressable) External data memory pdata that can be accessed with MOVX @DPTR Accessed with MOVX @Rn Special data type bit of external data memory General bit (bit) variable sbit Absolutely addressed bit (bit) variable syntax sbit my_flag = location; (location range is from 0x00 ~ 0x7F) Example sbit EA = 0xAF; or with bdata declaration bit variable char bdata my_flags; sbit flag0 = my_flags ^ 0; (Note that static cannot be added before sbit) sfr Special Function Register syntax sfr my_sfr = location; (location ranges from 0x80 ~ 0xFF) Example sfr P0 = 0x80; A variable specifying an absolute address can be declared in a single module using the following syntax [memory_space] type variable_name _at_ location Example pdata char my_pdata _at_ 0x80; If the variable must be used by multiple modules (Global Variable) then It is more convenient to define it in the header file in the form of abstract pointer.
#define variable_name *((data_type *) location)
Example
#define my_pdata *((char pdata *) 0x80)
(Note the order of char and pdata)
ABSACC.H provides the following convenient macro (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 on reset is not the user's main program
main(), but a hidden one in the KEIL-C51 standard link library A program module called startup.a51.
The main job of startup.a51 is to clear the memory block including idata, xdata, and pdata to 0,
and initialize the recursive pointer. Then startup.a51 is executed still a
program module called init.a51 hidden in the KEIL-C51 standard link library. The main job of init.a51 is to initialize
variables with non-zero initial value settings.
After completing the above initialization procedure, the control of 80C51 will be handed over to main() to start executing the user's program.
#define XBYTE ((unsigned char volatile xdata *) 0)
Define XBYTE as a pointer to the unsigned char data type in the xdata address space. The pointer value is 0.
In this way, you can directly access the external RAM with Got it
Previous article:Experiment 2 8-bit adder design
Next article:51 MCU decoding PPM wave
Recommended ReadingLatest update time:2024-11-16 14:28
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- The evaluation plan for the current probe and signal generator winners is open! The instruments have been distributed, and we look forward to the sharing of the 6 little ones
- How to use stm to make lcd12864 display
- Thank you + my son, my daughter, and my wife
- How to set breakpoints when debugging a program in keil4?
- 【Qinheng Trial】3. System clock and TIMER0
- [SAMR21 New Gameplay] 32. CPU-related functions
- C2000 Power-on Boot Mode Analysis
- EEWORLD University Hall----Electromagnetic Compatibility Principles and Design
- MSP430 realizes access card function (RFID) through RC522
- Several key performance characteristics of the MSP432P401R MCU 14-bit ADC