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

rom TABLE

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







rom TABLE
PostPosted: Mon Dec 06, 2004 2:16 am     Reply with quote

Hi,

I'm a newbie in C and I want to know how I can implement a table in rom;
for example if I have this in assembler, how i can 'translate it in c?

#org 1000h
DB 01,02,03,04,05,06,07,08
.
.
.
#org 2000h
DA "HELLO WORD! "
.
.
.
#END

Thanks to everybody
Max
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 06, 2004 1:39 pm     Reply with quote

It's done with a #rom statement.

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

#rom 0x1000 = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}
#rom 0x2000 = {"HELLO WORLD! "}

// Notice this 2nd method. It uses 'int8' and will pack two bytes
// per ROM word, instead of one byte per word. Look at the Program
// Memory window to see this.
#rom int8 0x1100 = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}


//==================================
void main()
{



while(1);
}
GUEST
Guest







rom TABLE
PostPosted: Tue Dec 07, 2004 3:41 am     Reply with quote

Thanks a lot !!

I have an other question:
If I want to read this data from ROM and put it to a RAM buffer -in assembler I can use 'table read' or 'table write' instruction- , which is the C sintax? The sintax is the same for data (0x01,0x02 ....) and ascii ("HELLO ...")?
Thanks in advance and sorry for my bad english!
Max
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 07, 2004 10:14 am     Reply with quote

Quote:
If I want to read this data from ROM and put it to a RAM buffer - which is the C syntax?

Look in the CCS manual or Help file at these functions:

read_program_eeprom()

read_program_memory()
Ttelmah
Guest







Re: rom TABLE
PostPosted: Tue Dec 07, 2004 10:23 am     Reply with quote

GUEST wrote:
Thanks a lot !!

I have an other question:
If I want to read this data from ROM and put it to a RAM buffer -in assembler I can use 'table read' or 'table write' instruction- , which is the C sintax? The sintax is the same for data (0x01,0x02 ....) and ascii ("HELLO ...")?
Thanks in advance and sorry for my bad english!
Max

PCM programmer has given you the solution to keep 'assembler compatible', but the other is to go fully 'C'
const int8 table[] = {0,1,2,3,4,5,6,7,8 };

Gives you an array, stored in the ROM. You can access it by simply using 'table[n]' where 'n' is a number from 0..8, and use it as a normal variable. What is happening is that the C compiler actually stores the numbers, and hidden in front of these, either the 'read_program_eeprom' code, or (on older chips), the numbers are replaced with 'retlw' instructions returning the required values, and a 'call' routine is placed in front to call the required value.
You can place such a routine at a specific address, but if your code is going to be fully 'C', you can just let the compiler store it as required.
The answers to your original question, really depend massively on whether you need to retain 'reverse compatibility' with the way the assembler stores the numbers, or whether you are switching to a fully 'C' solution. If the latter is the case, you can stop using directives like #ROM, and rely on the compiler placing the tables as needed, and retrieving them as needed.

Best Wishes
guest
Guest







PostPosted: Tue Dec 07, 2004 10:58 am     Reply with quote

Ok,
now I understand better (I hope Very Happy ) how C works and I can try to realize my application (but I hope to find you another time if I have others problems... ops!).
Thank you to everybody for help.
Bye Max
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