|
|
View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
Constant Data Table in ROM- 2 Dimensions? |
Posted: Tue Dec 27, 2005 6:54 am |
|
|
Hi
I would like to place a 2d array into ROM. It is a constant array, can someone please tell me how to do this?
(When I define it as int P[10][7] some of the data gets mixed up, and I do not know why).
Thank you in advance
a. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Dec 27, 2005 8:23 am |
|
|
arrow wrote: | I would like to place a 2d array into ROM. It is a constant array, can someone please tell me how to do this? | Have a look at this thread |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Tue Dec 27, 2005 8:52 am |
|
|
I tried compiling this:
Code: |
#include <18F458.h>
#fuses HS,WDT128,PROTECT,NOLVP,PUT
#case
int const table[4][3] = {{1,2,3}, {4,5,6}, {7,8,9}, {0xa, 0xb, 0xc}};
void main(void)
{
int x;
x = 10;
}
|
And it does compile. I tried printing out the .hex file and disassembly listing, but i couldn't find any pattern of "1,2,3,4,5,6" anywhere in it, so i guess it is stored in some cryptic way. If you have hyperterminal hooked up to a unit, why don't you try printf'ing "table[2, 2]" and it should be giving you the value '9' (i think). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 27, 2005 11:45 am |
|
|
Quote: | I tried printing out the .hex file and disassembly listing, but i couldn't find any pattern of "1,2,3,4,5,6" anywhere in it. |
The compiler will only put the const array into ROM if you put in
a line of C code to access the array. Even then, if you access the
array with constant indexes (such as table[0][0]), the compiler
will optimize that fetch into a MOVLW statement and it won't put the
entire array into ROM. If you want to see the entire array put
into ROM, you must use a variable for at least one of the indexes.
Then edit the .H file for your PIC, and comment out the #nolist
statement at the top. Re-compile and look at the .LST file.
Example:
Code: | #include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
int const table[4][3] = {{1,2,3}, {4,5,6}, {7,8,9}, {0xa, 0xb, 0xc}};
//=============================
void main()
{
int8 x;
int8 i;
x = table[i][0]; // Use a variable for one of the indexes
while(1);
}
|
Here is the top part of the .LST file for the program above.
Code: | 0000: GOTO 0020
.... #include <18F452.h>
.... /// Standard Header file for the PIC18F452 device ////
.... #device PIC18F452
0004: CLRF FF7
0006: ADDLW 14
0008: MOVWF FF6
000A: MOVLW 00
000C: ADDWFC FF7,F
000E: TBLRD*+
0010: MOVF FF5,W
0012: RETURN 0
0014: DATA 01,02 // Here is the array data.
0016: DATA 03,04
0018: DATA 05,06
001A: DATA 07,08
001C: DATA 09,0A
001E: DATA 0B,0C
.................... //#nolist |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|