Discussion Forum

look up table

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

DetailsMessage
Read-Only
Author
behrang moojani
Posted
10-Sep-2005 10:35 GMT
Toolset
None
New! look up table
i am trying to use code memory space to store some constants patterns. to do this, i have defined an array in code memory space as follows:

unsigned char code A[]={0x00,0x3F,0x50,0x90,0x50,0x3F,0xAA};

it doesn't work at all or sometimes i get unpredicted results. but when i define the array in data memory and initialize the array as follows. can anyone help me? thanks

A[1] = 0x00;
A[2] = 0x3F;
.
A[6] = 0xAA
Read-Only
Author
Andy Neil
Posted
10-Sep-2005 13:18 GMT
Toolset
None
New! RE: look up table
In what way does it "not work at all?"

Have you tried this in the simulator?

Have you looked in the map file & verified that the code constants are being placed in a sensible location?

Are you getting any errors or warnings during the build?

Post the smallest complete program that illustrates the problem - and remember those 'pre' and '/pre' tags when posting code (see the 'Notes' immediately above the 'Message' window when you post).
Read-Only
Author
behrang moojani
Posted
10-Sep-2005 18:23 GMT
Toolset
None
New! RE: look up table
dear Andy Neil
if you still read me, first of all, thanks for writing me back anyway, cause this problem is making me crazy, any way, i haven't tried it on simulator,instead i am trying this code directly on hardware each time i proramme it, the irony is that it works perfectly well when i initialize the array element by element,but it doesn't work when i try it the following way:
A[] = {0x00,0x03F,0x050,0x090,0x050,0x03F};
or

A[] = {0x00,0x03F,0x050,0x090,0x050,0x03F};

you have any suggestion?
Read-Only
Author
Dan Henry
Posted
10-Sep-2005 18:29 GMT
Toolset
None
New! RE: look up table
The array defined with initializers is initialized by the runtime startup code, whereas the other way is by explicit assignment in your program. Are you including the runtime startup in your project?

http://www.keil.com/support/man/docs/c51/c51_ap_startup.htm
Read-Only
Author
Andy Neil
Posted
10-Sep-2005 20:36 GMT
Toolset
None
New! RE: look up table
"Are you including the runtime startup in your project?"

It shouldn't be necessary to explicitly include it - if you don't explicitly include it, you should automatically get the default.
Read-Only
Author
Andy Neil
Posted
10-Sep-2005 20:44 GMT
Toolset
None
New! RE: look up table
"i haven't tried it on simulator, instead i am trying this code directly on hardware each time i proramme it"

And you say it's driving you crazy - so don't do it!
Unless you have a chip with on-chip debug - in which case, use it!

IF you can reproduce the problem in the simulator, it will be much easier to debug; if you can't, it most likely means that you have a hardware fault, misconfiguration, or your interfacing is bad.

"you have any suggestion?"

I'm still waiting for your response to my previous questions & suggestion:

Have you looked in the map file & verified that the code constants are being placed in a sensible location?

Are you getting any errors or warnings during the build?

Post the smallest complete program that illustrates the problem.
Read-Only
Author
Andy Neil
Posted
10-Sep-2005 20:50 GMT
Toolset
None
New! RE: look up table
Note that
unsigned char code A[]={0x00,0x3F,0x50,0x90,0x50,0x3F,0xAA};
is not equivalent to
A[1] = 0x00;
A[2] = 0x3F;
:
A[6] = 0xAA;
Your array indexes are out by one!

If you are making the same mistake elsewhere in your code, you will get unexpected behaviour!
(and you are probably trying to access the byte after the end of the array...!)
Read-Only
Author
behrang moojani
Posted
11-Sep-2005 19:55 GMT
Toolset
None
New! RE: look up table
dear Andy Neil
i am so thankful to youR attention, i checked startup.A51 to see if there is any option to manipulate the enternal code memory of 8051 for initialization, and there is no such option so far as i can see, so tell me if i am making a mistake, and then, this code is perfectly working well when i am initializing the array element by element in AT89C52 internal RAM, but because of the volume of data, i have no other option except using the code space. i even translated the C51 code i had written to assembly all by hand and it worked, but because of some complexities, it's not possible to wtire the entire code in assembly, i am looking forward to hear from you, thanKs.
Read-Only
Author
Andrew Neil
Posted
12-Sep-2005 06:49 GMT
Toolset
C51
New! RE: look up table
You need to find out why the initialisation in the definition isn't working.

See my previous replies:

* Check your 'C' array indexing;

* Use the simulator.
Read-Only
Author
Stefan Duncanson
Posted
12-Sep-2005 10:33 GMT
Toolset
None
New! RE: look up table
We cannot help you further unless you post the smallest complete program which shows the problem. Please copy and paste this from you editor - do not retype it.
Read-Only
Author
Benno Baumgartner
Posted
19-Sep-2005 12:38 GMT
Toolset
C51
New! RE: look up table
have you ever tried to set the "code" definition in the first place.
are you sure the array definition "A" is not defined elsewhere. Try out the following definition:

code unsigned char MyArray[7]={0x00,0x3F,0x50,0x90,0x50,0x3F,0xAA};
Read-Only
Author
behrang moojani
Posted
19-Sep-2005 21:38 GMT
Toolset
C51
New! RE: look up table
thanks for your attention, and thanks foR your replay, actually there was nathing wrong with the code i had written, there was something wrong with the version of software i was using, i didn't know it was using a cracked one.

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