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 support@ccsinfo.com

write 2000 bytes in ROM and read it

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








write 2000 bytes in ROM and read it
PostPosted: Sat Jan 05, 2008 10:12 am     Reply with quote

How can I write data in ROM with #ROM and get it ?

thanks a lot
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 06, 2008 5:35 pm     Reply with quote

Here is a short program that shows how to do it. This example only
stores 20 bytes in ROM, but you can add more bytes in the #rom
declaration. Here's the output of this program on a terminal window:
Quote:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Code:
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define DATA_ADDRESS 0x1000  // Start address for data
#define DATA_SIZE  20   // in bytes


#rom int8 DATA_ADDRESS =
{
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
}

//--------------------------------------
void display_data(int32 rom_address)
{
int i;
int8 buffer[100];

read_program_memory(rom_address, buffer, DATA_SIZE);

for(i = 0; i < DATA_SIZE; i++)
    printf("%u ", buffer[i]);
}

//====================================
void main()
{
display_data(DATA_ADDRESS);

while(1);
}
Ttelmah
Guest







PostPosted: Mon Jan 07, 2008 3:00 am     Reply with quote

However, 'caveat', this only applies to chips that support reading of their program memory (most of the 'newer' chips). You can't do this on some older chips, because the support is not there in the processor instructions. On these, it is actually basically 'impossible'.

Best Wishes
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Mon Jan 07, 2008 9:27 am     Reply with quote

But is there a limit on how much data can be saved using a single #ROM directive, or the total amount of data which can be saved with multiple #ROM directives in the same program? I encountered a situation where I thought the compiler was refusing to accept more than a certain amount of data, but I solved the problem another way before I really reached an understanding of what was happening. I'd be curious to hear what limits exist, if any.
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