7098 views|16 replies

298

Posts

0

Resources
The OP
 

Usage of absolute address in C51 [Copy link]

 
Is it possible to place a variable in a fixed area and initialize it at the same time?
This post is from 51mcu

Latest reply

Same question, after specifying an absolute address in C51 code, is there no way to assign an initial value? If it is mixed programming, there used to be a way: Specify the initialization data in the A51 assembly code: CSEG AT 0x1000 DB 12H,34H,56H,78H Then define the reference in the C51 code: unsigned char code *pinfo =0x1000; or code unsinged char pinfo[4] _at_ 0x1000;   Details Published on 2023-1-27 10:42
 

6069

Posts

4

Resources
2
 
If you look up "absolute address in C51" on the Internet or in a book, someone will tell you.
This post is from 51mcu

Comments

ena
But they are just definitions and cannot be assigned values  Details Published on 2018-3-16 12:00
 
 
 

298

Posts

0

Resources
3
 
damiaa posted on 2018-3-16 11:46 Look up "absolute address in C51" on the Internet or in a book and someone will tell you.
But they are just definitions, not assignments.
This post is from 51mcu

Comments

When you define it, isn't it just assigning a value to this address?  Details Published on 2018-3-16 12:52
 
 
 

1305

Posts

0

Resources
4
 
ena posted on 2018-3-16 12:00 But they are just definitions, not assignments
If you define it, isn't it just assigning a value to the variable address? Dead brain!
This post is from 51mcu

Comments

ena
, it just defines that this variable is stored at a certain address, but the specific value is unknown?  Details Published on 2018-3-16 13:02
 
 
 

298

Posts

0

Resources
5
 
yang_alex posted on 2018-3-16 12:52 When you define it, isn't it just assigning a value to this variable address? Dead brain!
, it just defines this variable to be stored at a certain address, but the specific value is unknown?
This post is from 51mcu

Comments

Do you mean you don't know the address of the variable? Or do you mean you don't know the value of the variable? Did you not specify the address of the variable when defining it? Like this: C51 provides a method to access absolute addresses: 1. Absolute macros: In a program, use "#include" to use the macros defined in it to  Details Published on 2018-3-16 13:09
 
 
 

1305

Posts

0

Resources
6
 
ena posted on 2018-3-16 13:02 , just define this variable to be stored at a certain address, but don’t know the specific value?
Do you mean you don’t know the address of the variable? Or do you mean you don’t know the value of the variable? Didn’t you specify the address of the variable when defining it? Like this: C51 provides a way to access absolute addresses: 1. Absolute macros: In the program, use “#include"You can use the macros defined therein to access absolute addresses, including: CBYTE, XBYTE, PWORD, DBYTE, CWORD, XWORD, PBYTE, DWORD For specific usage, please refer to absacc.h. For example: rval=CBYTE[0x0002]; points to the address 0002h of the program memory rval=XWORD [0x0002]; points to the address 0004h of the external RAM 2. The _at_ keyword can be added directly after the data definition with _at_ const, but please note: (1) Absolute variables cannot be initialized; (2) Bit-type functions and variables cannot be specified with _at_. For example: idata struct link list _at_ 0x40; specifies that the list structure starts at 40h. xdata char text[25b] _at_0xE000; specifies that the text array starts from 0E000H. Tip: If the external absolute variable is an I/O port or other data that can change on its own, it needs to be described using the volatile keyword. Please refer to absacc.h.
This post is from 51mcu

Comments

ena
I mean how to assign a value to this variable, because what I saw in the document is "absolute variables cannot be initialized". But in MDK, using __attribute__ is OK: const int ID __attribute__((at(0xf200)))=0x10; I don't know if there is such a method in C51.  Details Published on 2018-3-16 13:35
 
 
 

298

Posts

0

Resources
7
 
yang_alex posted on 2018-3-16 13:09 Do you mean you don't know the address of the variable? Or do you mean you don't know the value of the variable? Didn't you specify the address of the variable when defining it? Like this...
I mean how to assign a value to this variable, because what I saw in the document is "absolute variables cannot be initialized". But in MDK, using __attribute__ is OK: const int ID __attribute__((at(0xf200)))=0x10; I don't know if there is such a method in C51.
This post is from 51mcu

Comments

You need to understand what an absolute variable is. I understand that it is defined to an address in the FLASH space. You certainly cannot initialize it in the program! If it is defined in the RAM space, it can be initialized.  Details Published on 2018-3-16 14:09
 
 
 

6069

Posts

4

Resources
8
 
Any of the text[25b] array can be assigned a value. rval = XWORD [0x0002]; points to the 0004h address of external RAM. In this way, rval can be assigned a value. As long as it is not CCODE CBYTE, etc. (restricted to code space) or const-restricted (RAM XDATA IDATA).
This post is from 51mcu
 
 
 

1305

Posts

0

Resources
9
 
ena posted on 2018-3-16 13:35 I mean how to assign a value to this variable, because what I saw in the document is "absolute variables cannot be initialized". But in MDK, use __a ...
You need to understand what an absolute variable is. I understand that it is defined to an address in the FLASH space. You definitely cannot initialize it in the program! If it is defined in the RAM space, it can be initialized.
This post is from 51mcu

Comments

ena
Well, I guess I can't  Details Published on 2018-3-16 14:36
 
 
 

298

Posts

0

Resources
10
 
yang_alex posted on 2018-3-16 14:09 You need to understand what an absolute variable is. I understand that it is defined to an address and defined to the FLASH space. You certainly cannot initialize it in the program! For example...
Well, I guess you can't put
This post is from 51mcu
 
 
 

5

Posts

0

Resources
11
 
Come to learn, popular teaching
This post is from 51mcu
 
 
 

525

Posts

235

Resources
12
 
const int ID __attribute__((at(0xf200)))=0x10; In the example given by the host, ID is actually a constant. It is stored at the address 0XF200 and can be accessed by accessing ID in the program.
This post is from 51mcu

Comments

ena
But it fails to compile in KEILC51  Details Published on 2018-3-17 08:57
 
Personal signature爱电子,爱生活
 
 

298

Posts

0

Resources
13
 
wsdymg posted on 2018-3-16 20:53 const int ID __attribute__((at(0xf200)))=0x10; In the example given by the host, ID is actually a constant. It is stored at 0XF200...
But it fails to compile in KEILC51
This post is from 51mcu
 
 
 

4005

Posts

0

Resources
14
 
51 uses the keyword code code unsigned char Arry[256] _at_ (0x1000) = { 0,1,2,3,4,5 };

This post is from 51mcu

Comments

ena
This will prompt an error; error C274: "icode": absolute specifier illegal  Details Published on 2020-6-13 11:51
 
 
 

298

Posts

0

Resources
15
 
huo_hu posted on 2018-3-18 17:12 51 uses the keyword code code unsigned char Arry[256] _at_ (0x1000) = { 0,1,2,3,4,5 };

This will prompt an error;

error C274: "icode": absolute specifier illegal

This post is from 51mcu

Comments

You have to check that the value specified later is indeed in the flash area  Details Published on 2020-6-14 21:59
 
 
 

4005

Posts

0

Resources
16
 
ena posted on 2020-6-13 11:51 This will prompt an error; error C274: "icode": absolute specifier illegal

You have to check that the value specified later is indeed in the flash area

This post is from 51mcu
 
 
 

1

Posts

0

Resources
17
 

Same question, after specifying an absolute address in C51 code, is there no way to assign an initial value?

If it is mixed programming, there used to be a way:

Specify the initialization data in the A51 assembly code:
CSEG AT 0x1000
DB 12H,34H,56H,78H
Then define the reference in the C51 code:
unsigned char code *pinfo =0x1000;

or code unsinged char pinfo[4] _at_ 0x1000;

This post is from 51mcu
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list