CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

About storing large amount of data into ROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








About storing large amount of data into ROM
PostPosted: Tue Dec 13, 2005 8:19 am     Reply with quote

hi all,

I think this thread is the continuing version of the one posted not long ago. I was given the ideas of implementation from some kind guys but now having some practical implementation problem.

My problem is, since I am drawing some graphics and building some menus on LCD using 18f8722, there are a huge amount of pre-defined arrays in the code. I used to define all these arrays as constant so as to save RAM but in the end I was running out of ROM.

People recommanded I store these arrays using #ROM separating each array using a separator '~'. At the beginning of the code, a scanning of that storage area is executed to obtain the idea where these arrays are stored in the ROM.

The code is basically like this:

Code:
#include<18f8722.h>
#device *=16
#include<math.h>
#include<stdlib.h>
#include<crc.c>


#USE RS232( BAUD = 9600, XMIT = PIN_G1, RCV = PIN_G2, STREAM = COM_A )

#USE RS232( BAUD = 9600, XMIT = PIN_C6, RCV = PIN_C7, STREAM = COM_B )

#rom 0x18000 = {"abc",'~',"1234",'~'}

int32 startAddress = 0x18000;

void main()
{
   int i;
   int32 j;
   int32 length[2];

   init_devices();

   for(i=0;i<2;i++)
   {
      for(j=0;*(j+startAddress) != '~'; j++)
         ;
      length[i] = j;
      startAddress += (j+1);
   }
         
   fprintf(COM_B,"\nlength 1 = %ld,length 2 = %ld\n",length[0],length[1]);


}


I am storing arrays "abc" and "1234" in program memory, address starting at 0x18000. However, it doesn't work like what I expected. The lengths returned are: 248 and 634 which are obviously wrong. Can people spot any thing weird here?

Also, I was recommanded using #ORG but have no idea how to put this directive in.
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Tue Dec 13, 2005 8:21 am     Reply with quote

sorry I forgot to login....


any thought,plz?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: About storing large amount of data into ROM
PostPosted: Tue Dec 13, 2005 8:52 am     Reply with quote

You are searching for a byte value so you need to tell the compiler to use byte orientated storage in the #rom directive with the int8 specifier. I also added a define so you do not need to statically define the address more than once.

Code:

#define Table 0x18000
#rom int8 Table = {"abc",'~',"1234",'~'}

int32 startAddress = Table;

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Tue Dec 13, 2005 9:01 am     Reply with quote

Hi Andrew,

Thanks for the reminding.

It still didn't seem to work. the lengths returned changed but still wrong. The returned lengths are now:

length 1 = 248,length 2 = 1068
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Dec 13, 2005 9:30 am     Reply with quote

Code:

#define Table 0x18000
#rom int8 Table = {"abc",'~',"1234",'~'}

int32 startAddress = Table;
byte z;

......

   for(i=0;i<2;i++)
   {
    for (j =0, z=0; z != '~'; j++)         
       read_program_memory(startAddress + j, &z, 1);

    length[i] = j;
    startAddress += (j+1);
    }

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah
Guest







PostPosted: Tue Dec 13, 2005 9:31 am     Reply with quote

You can't use pointers to ROM.
To access the ROM memory, use the 'read_program_memory' call, with the address.

Best Wishes
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Tue Dec 13, 2005 10:27 am     Reply with quote

Thanks guys, it works now...

Telmah, you remember you said using #org to avoid memory ovelap. How did you actualy use #org in this case?
Ttelmah
Guest







PostPosted: Tue Dec 13, 2005 1:13 pm     Reply with quote

The current compilers, _should_ create a memory segment if you use #rom. However I have had problems in the past with the compiler putting code into an area defined using this, and feel it is safer to use #org as well.
If you declare for instance:
#org 0x18000,0x180ff
Then the next item, is put into this memory segment. You can use #rom to do this.
So:
Code:

#define Table 0x18000
#org Table, Table+200

#rom int8 Table = {"abc",'~',"1234",'~'}

#org default

Ensures the area is reserved.

Best Wishes
ye



Joined: 11 May 2005
Posts: 57
Location: london

View user's profile Send private message

PostPosted: Wed Dec 14, 2005 4:40 am     Reply with quote

Thanks guys~
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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