Discussion Forum

Writing constant to ROM

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Kiah Hion Tang
Posted
8-Feb-2001 09:04 GMT
Toolset
None
New! Writing constant to ROM
Maybe this is a simple question, but I just couldn't figure it out. Can someone tell me how to place a constant variable into the specific ROM area? I would like to be able to set a constant value at a particualr ROM area and use a pointer to get it whenever I need it.

Cheers,
Tang
Read-Only
Author
Andrew Neil
Posted
8-Feb-2001 11:36 GMT
Toolset
None
New! RE: Writing constant to ROM
unfortunately, the _at_ keyword can't be used with initialisation.

How about
code const unsigned char fred = 0xaa;
and then using the linker to fix the location?
you'd probably need to define 'fred' such that it was in a segment of its own?
Read-Only
Author
Kiah Hion Tang
Posted
8-Feb-2001 11:43 GMT
Toolset
None
New! RE: Writing constant to ROM
How to use linker to fix the location?
Read-Only
Author
Andrew Neil
Posted
8-Feb-2001 12:10 GMT
Toolset
None
New! RE: Writing constant to ROM
Dunno - I'm afraid you'll have to look that up for yourself in the manuals (which are all in PDF format on the free CD, and can be accessed via the Books tab in the uVision Project window):

Look in the C51 manual for where it describes C51's segment naming & usage conventions, then look in the Assembler/Utilities manual for how to locate a specific segment at a specific address.

Or try searching the Keil knowledge base, http://www.keil.com/search.asp

Or, as your E-Mail appears to be at the University of Warwick, can you just pop over and ask the very nice people at Hitex? ;-)
Read-Only
Author
Kiah Hion Tang
Posted
8-Feb-2001 12:14 GMT
Toolset
None
New! RE: Writing constant to ROM
Ha.. :)) good suggestion. Hitex is a good source of knowledge.
Read-Only
Author
Jon Ward
Posted
8-Feb-2001 17:10 GMT
Toolset
None
New! RE: Writing constant to ROM
Here is a link to the knowledgebase atricle that describes how to do this.

http://www.keil.com/support/docs/301.htm

Jon
Read-Only
Author
Kiah Hion Tang
Posted
8-Feb-2001 17:22 GMT
Toolset
None
New! RE: Writing constant to ROM
Exactly what I am looking for.

CHEERS!!
Read-Only
Author
Doug Hewett
Posted
22-Feb-2001 18:45 GMT
Toolset
None
New! RE: Writing constant to ROM
Please see my latest posting re this issue. It differs slightly from your example. Specifically:

User's guide, 01.97, C compiler C51 on page 63 'explicitly defined memory types' recommends a syntax.

The Utilities guide, 04.95, page 119, has a different syntax in files c_mess0.c, c_mess1.c.

the utilities guide contradicts the recommendation in the user's guide.

Yet the 'preferred' method in the C51 compiler will NOT work. You must use the 'obsolete' method of the Utilities guide.

(1) Please explain.

(2) What is correct syntax for:
const unsigned char code *MyArray[NumberFruits] = {"apple,"banana","cherry"};
Read-Only
Author
Mark Odell
Posted
8-Feb-2001 18:23 GMT
Toolset
None
New! RE: Writing constant to ROM
I still dream of this construct:

const unsigned char code magicNum _at_ 0x8000 = 0xAA;
I can dream.

- Mark
Read-Only
Author
Andrew Neil
Posted
9-Feb-2001 00:28 GMT
Toolset
None
New! RE: Writing constant to ROM
and why ever not?
Read-Only
Author
Franc Urbanc
Posted
9-Feb-2001 20:03 GMT
Toolset
None
New! RE: Writing constant to ROM
Mark, your dream has become true in C251 v2.14 already. I use it to store the Revision code of the application.

Franc
Read-Only
Author
Mark Odell
Posted
10-Feb-2001 01:16 GMT
Toolset
None
New! RE: Writing constant to ROM
Impossible! How could that be? How could C251 get that feature before C51? C51 is probably used 10 to 1 over C251.

Unfare! I declare a 10 yard penalty, repeat second down (Man it's great to have the XFL now. February can be so cold without football).

- Mark
Read-Only
Author
Franc Urbanc
Posted
10-Feb-2001 17:19 GMT
Toolset
None
New! RE: Writing constant to ROM
Here is how I do it:

1. I define the code version in the header file:
/*********************** FIRMWARE CODE VERSION	*****************************/

#define CODE_VERSION	3		// 10 is version 1.0

In the source module, I put the variable into the codespace (into the gap just behind external interrupt 0 LJMP instruction):

unsigned char code version _at_ 0x0006 = CODE_VERSION;

This value can be accessed by the system flash upgrade software at location 6 of the code region 0xFF. So The software displays the new version at file opening time and before actual downloading to the target system.

Franc
Read-Only
Author
Andrew Neil
Posted
10-Feb-2001 20:17 GMT
Toolset
None
New! RE: Writing constant to ROM

unsigned char code version _at_ 0x0006 = CODE_VERSION;
But that's not allowed - you can't use an initialiser with the _at_ keyword.

See p79 in the C51 User's Guide, 03.2000:
"The following restrictions apply to absolute variable location:
1. Absolute variables cannot be initialized.
2. Functions and variables of type bit cannot be located at an absolute address."

Read-Only
Author
Mark Odell
Posted
12-Feb-2001 01:36 GMT
Toolset
None
New! RE: Writing constant to ROM
That's what I thought. I'm still dreaming of this feature for the C51.

- Mark
Read-Only
Author
Russell Anderson
Posted
25-Feb-2005 14:37 GMT
Toolset
C51
New! RE: Writing constant to ROM
Why does Keil have this restriction? You can do this with Raisonance and I would like to have my code be compatible with both. For Raisonance you just use:
at 0x803d code char my_char = 0x55;

I don't need to have a variable name created, but I would like to be able to set a byte that configures the hardware. This is a hardware configuration byte that needs to be programmed when the program is loaded. If I understand correctly there is no way to add a single statement to the Keil C program for this function. I have to link an assembly language file to do that with Keil. Is that correct?
Read-Only
Author
Stefan Duncanson
Posted
25-Feb-2005 15:12 GMT
Toolset
C51
New! RE: Writing constant to ROM
"Why does Keil have this restriction?"

Although it seems a simple enough addition apparently it will involve a major rewrite of part of the compiler.

You can put the 'variable' in its own 'C' source file then link that as a 'user segment'. There's an example in the knowledgebase somewhere.
Read-Only
Author
Andrew Neil
Posted
9-Feb-2001 00:30 GMT
Toolset
None
New! RE: Writing constant to ROM
Thanks for that, Jon.

As you can probably tell, I've done this before - but not yet with the Keil toolset.
I'm sure it'll come in handy.
Read-Only
Author
Doug Hewett
Posted
22-Feb-2001 18:49 GMT
Toolset
None
New! RE: Writing constant to ROM
this is a copy of my posting today. If I follow the recommendation of the compiler manual, the linker puts the table of pointers into xdata. I must use the non-preferred method (per the utilities manual).
Thanks.
By the way, I can't find the pdf for the utilites manual. Is there one?
=== paste ===
User's guide, 01.97, C compiler C51 on page 63 'explicitly defined memory types' recommends a syntax.

The Utilities guide, 04.95, page 119, has a different syntax in files c_mess0.c, c_mess1.c.

the utilities guide contradicts the recommendation in the user's guide.

Yet the 'preferred' method in the C51 compiler will NOT work. You must use the 'obsolete' method of the Utilities guide.

(1) Please explain.

(2) What is correct syntax for:
const unsigned char code *MyArray[NumberFruits] = {"apple,"banana","cherry"};
Read-Only
Author
Drew Davis
Posted
25-Feb-2005 23:45 GMT
Toolset
None
New! RE: Writing constant to ROM
const unsigned char code *MyArray[NumberFruits] = {"apple,"banana","cherry"};


There's one occurrence of "code" in this definition, to the left of the *. That means it applies to the "unsigned char". So, this is a table of pointers (in RAM) that point to characters in code memory. If you want the pointers themselves in code memory, you need to specify that as well:

const unsigned char code* code MyArray...

Next Thread | Thread List | Previous Thread Start a Thread | Settings