Use of xbyte in C51

Publisher:CelestialSoulLatest update time:2017-01-06 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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 /* Include Macro Definitions */
.
.
.
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

Keywords:C51 Reference address:Use of xbyte in C51

Previous article:Experiment 2 8-bit adder design
Next article:51 MCU decoding PPM wave

Recommended ReadingLatest update time:2024-11-16 14:28

What is the definition format of C51 bit variables?
What is the definition format of C51 bit variables? How to define a bit variable of bdata type byte variable? Answer: bit Bit variable name 1 ] sbit bit variable name = bdata type variable name ^ bit number constant
[Microcontroller]
C51 MCU Programming Skills: LCD1602 Programming Experience Sharing
Introduction: Let me first explain that the chip driver of the LCD1602 I am going to talk about below is HD44780. If your LCD1602 driver chip is not HD44780, then the following content is not applicable. This time I will share my LCD1602 programming experience: Let me first explain that the chip driver of the LCD160
[Microcontroller]
C51 MCU Programming Skills: LCD1602 Programming Experience Sharing
C51 Programming 18-Interrupt (Serial Communication 2)
There are two independent receiving and sending SBUFs inside the MCS-51 microcontroller. The receiving SBUF cannot send, and the sending SBUF cannot receive. They share the same address (99H). The internal logic structure is shown in the figure below: In the internal logic structure of the serial, we can see that se
[Microcontroller]
C51 Programming 18-Interrupt (Serial Communication 2)
Performance comparison of AVR, C51 and PIC 8-bit microcontrollers
1. 51 Series   The most widely used eight-bit microcontroller is Intel's 51 series. Due to its reasonable hardware structure, standardized instruction system and long production history, it has the advantage of first-mover advantage. Many famous chip companies in the world have purchased the core patent technology of
[Microcontroller]
C51 MCU interrupt number and interrupt vector
1. External interrupt 0, 1; caused by the level signal of pin /INT0, /INT1 respectively.  2. Timer/Counter 0, 1; caused by the overflow of T0, T1 respectively.  3. Serial port sending, receiving; caused by sending a byte or receiving a byte.  There are 5 interrupt sources in total.   1. Interrupt number External in
[Microcontroller]
The startup process of C program in keil c51
The assembly starts from org 0000h, so how does Keil C51 start the main() function? Keil C51 has a startup program startup.a51, which is always compiled and linked with the C program. Let's see how it is compiled with the main() function; //The main function is as follows; void main(void) {     while (1) This is an un
[Microcontroller]
C51 Functions of ADC0809 Analog-to-Digital Converter
/*********************ADC0809 function****************/ //Start A/D conversion function: StartADC() void  StartADC(uchar Address) { PinC = (bit) (Address & 0x04); //C highest bit PinB = (bit) (Address & 0x02); PinA = (bit) (Address & 0x01); //The above 3 sentences output address CBA Pin
[Microcontroller]
3*3 matrix keyboard program for C51 microcontroller
#include   #include dis.h /**Delay 1**/ //Used for debounce void delay1(void) {uchar i;  for(i=0;i 200;i++);  } /****Delay 2**********/  void delay2(void) {   uchar i,j,s;   for(i=250;i 0;i--)   for(j=250;j 0;j--)   for(s=5;s 0;s--); } /****Serial port initialization****/ void chuankou_init(void) {
[Microcontroller]
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号