Test of Keil C51 xdata base address partial addressing

Source: Internet
Author: User
Keil C51 xdata base address partial addressing test [transfer]

(22:18:31)

ReprintedBytes
Tags:

C51 base address it
Category: Software Technology

Http://blog.sina.com.cn/s/blog_44153f8f0100eqsj.html

 

 I recently used keilc51 to create a program. I want to use an external data storage device and address other external chips. because I want to use continuous read/write of external data, I did a little research on xdata.

   I,  The first method is to define external address constants. The program is as follows:

# Definexram      Zero x 0000
# Definecydram    Zero X 1000
# Defineepm244h   Zero X 4000
# Defineepm244l   Zero X 5000

Void readdata (unint add)

{

  Volatileunchar xdata * xramadd;
  Xramadd = cydram + Add; // just produce the CS signal of thecy7c024.
  RDATA = * xramadd;
  _ NOP _();
  Xramadd = epm244h;
  Rdatah = * xramadd;
  Xramadd = epm244l;
  Rdatal = * xramadd;

}

Void main ()

{

       Readdata (0x0002 );

}

The above program can read the address after 0 x flexibly. Simply add the offset address to be read to the end. If you call the address in the main program, the data of 0 x is returned. Define an xramadd pointer in the subroutine to direct the requested address to it. Note that volatile should be added, so that you will not be optimized by the programmer when you are connected.

2. The other case is to use the _ AT _ command. I think this method is not flexible enough. If we want to read and write multiple data consecutively, we need to define an array, and there is no pointer flexibility. The program is as follows:

Volatile unchar xdatascydram _ At_0x1000;
Volatile unchar xdatasepm244h _ At_0x4000;
Volatile unchar xdatasepm244l _ At_0x5000;

Void readdata (unint add)

{

  RDATA = scydram + Add; // Just produce the CS signal of the cy7c024.
  Rdatah = sepm244h;
  Rdatal = sepm244l;

}

Void main ()

{

       Readdata (0x0002 );

}

The result is incorrect. The Compiler does not address 0x1002 as required, but 0x1000. How can this problem be solved? Define an array, volatile unchar xdatascydram [256] _ At_0x1000; only in this way can the corresponding results be obtained through array calls. The procedure is as follows:

Void readdata (unchar add)

{

  RDATA = scydram [add]; // Just make the CS signal of the cy7c024.
  Rdatah = sepm244h;
  Rdatal = sepm244l;

}

Void main ()

{

       Readdata (0x02 );

}

The data read in this way is correct.

3. You can use xbyte to define the file, but you must include the # include <absacc. h> file. As follows.

# Include <absacc. h>

# Definescydram Xbyte [0x1000];
# Define sepm244h Xbyte [0X4000];
# Define sepm244l Xbyte [0x5000];

I think it is the same as the _ AT _ command. But the flexibility is worse. Arrays cannot be defined. It can only be single address addressing, which is mainly used for external fixed address addressing, such as 8255,373 and AD converter. It is best to use the first method for continuous addressing, and the second method can define an array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.