Two methods of accessing the absolute address of the MCU in C language programming of 51 MCU

Publisher:灵感驿站Latest update time:2015-10-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When programming an 8051 microcontroller application system, it is often necessary to directly operate the various memory address spaces of the system. The target code generated by the C51 program after compilation has a floating address, and its absolute address must be determined after being linked and located by BL51. In order to be able to directly operate on any specified memory address in the C51 program, the extended keyword "at", pointer, pre-defined and link positioning control commands can be used.

Among these methods, I think the simplest and most effective method is to use the "_at_" keyword to specify the absolute address of the specified variable memory space. The general format is as follows:

                             [Memory type]            Data type             identifier_at_address             constant

            in:

                     The memory types                 include idata, data, xdata and other types that can be recognized by C51. It is best not to omit them.

                     The data type                    can be basic types such as int, long, float, and of course, complex data types such as arrays and structures can also be used              .                 I think that unsigned int can generally solve many problems.

                    The identifier                       is the name of the variable to be defined, and the programmer decides it himself

                   The address constant                     is the absolute address of the memory to be directly operated and must be located within the valid memory space.

Note: Variables cannot be initialized, only global variables can be used. Generally, do not use them lightly to avoid errors.

Example:

                     xdata            unsigned int             addr1            _at_ 0x8300;

Another method is to use a header file absacc.h, which is not difficult. Let's take an example to explain it:

               #include

                XBYTE[0x8300]=0;               /*Write 0 to the external memory (XDATA) address 0x8300

I strongly recommend using at, which may be better. Another point is that it should not be used indiscriminately, because some memory space cannot be occupied casually, the C51 compiler has already made other uses, and some space is very important for the microcontroller itself. If it is used indiscriminately, it is easy to make mistakes.

Reference address:Two methods of accessing the absolute address of the MCU in C language programming of 51 MCU

Previous article:51 MCU C language header file and its use
Next article:How difficult is serial communication between 51 MCU and PC?

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号