|
|
View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
rom TABLE |
Posted: Mon Dec 06, 2004 2:16 am |
|
|
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
|
|
Posted: Mon Dec 06, 2004 1:39 pm |
|
|
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 |
Posted: Tue Dec 07, 2004 3:41 am |
|
|
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
|
|
Posted: Tue Dec 07, 2004 10:14 am |
|
|
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 |
Posted: Tue Dec 07, 2004 10:23 am |
|
|
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
|
|
Posted: Tue Dec 07, 2004 10:58 am |
|
|
Ok,
now I understand better (I hope ) 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 |
|
|
|
|
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
|