|
|
View previous topic :: View next topic |
Author |
Message |
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
ROM statement |
Posted: Sat Sep 18, 2010 9:26 am |
|
|
Hi
Is there problem with the rom statement?
The first ex. work! it is not using the rom statement.
Code: |
int8 key_20[19]= {0x40,0x04,0x07,0x20,0x00,0x92,0x14,0x01,0xf5,0x00,0x00,0x70,0x07,0x00,0x00,0x81,0x00,0x00,0xa8};
void SendKey(int8 *data, int8 dl){
int8 i;
for (i=0;i<dl;i++)
SendByte(data[i]);
MStop();//End
}
void main(){
SendKey(&Key_20,sizeof(Key_20));
} |
***NotWorking*** But why??
Code: | rom int8 key_20[19]= {0x40,0x04,0x07,0x20,0x00,0x92,0x14,0x01,0xf5,0x00,0x00,0x70,0x07,0x00,0x00,0x81,0x00,0x00,0xa8};
void SendKey(rom int8 *data, int8 dl){
int8 i;
for (i=0;i<dl;i++)
SendByte(data[i]);
MStop();//End
}
void main(){
SendKey(&Key_20,sizeof(Key_20));
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sat Sep 18, 2010 1:54 pm |
|
|
This is a case of RTFM.....
The PIC has a memory architecture with separate spaces for the ROM and RAM. In the early PICs, there were no instructions to allow direct reading of the ROM, so the ROM statement, created a program that returns the required value, when passed the element number. Hence it was basically nearly impossible to directly address the ROM, and construct a pointer to the ROM space.
With latter chips, this restriction did disappear, but constructing a pointer to the ROM space, still requires a separate address range to the RAM.
Now, if you want to use pointer access to the ROM memory, you can use the CONST directive, rather than ROM, which then adds the extra code to do this. You can tell the compiler to treat all ROM statements this way with a #device statement, but at a cost in size and speed, for the cases where it is not used as well. Better really to use the CONST directive when needed.
Best Wishes |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Sat Sep 18, 2010 2:10 pm |
|
|
If using const statement as:
Code: | const int8 key_20[19]= {0x40,0x04,0x07,0x20,0x00,0x92,0x14,0x01,0xf5,0x00,0x00,0x70,0x07,0x00,0x00,0x81,0x00,0x00,0xa8}; |
This won't compile?
Code: | void SendKey(const int8 *data, int8 dl){... same as before |
This compile but won't work(because the const must be in ram, I guess).
Code: | void SendKey(int8 *data, int8 dl){... same as before |
hmmm? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sun Sep 19, 2010 2:07 am |
|
|
Think about your syntax.
First, the name of an array, _is_ it's address. You are taking the address of an address. Wrong value.
const int8 *, or ROM int8 *, says that this is a constant pointer. not what you have or want. The compiler handles pointers to constants using just the type, and that this is a pointer OK.
I think if you correct your actual pointer generation, you should find it'll work.
Best Wishes |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Sun Sep 19, 2010 2:27 am |
|
|
Thanks for reply.
I change the program to use "rom" and then pass it as a 16 bit pointer.
The first in my function is: read_program_memory(data,Buffer.Key,dl);
Now the program work as expected.
But I think it is difficult to understand you can use "rom" directly from "main" or in "function" just you use the name for the "rom". Then the compiler will insert correct code.
-But if passing the "rom" address(pointer) to a function then the compiler wont make the right code, you must take care of reading the program_memory.
Working ex. just if any other have the same problem.
Code: | rom int8 key_20[19]= {0x40,0x04,0x07,0x20,0x00,0x92,0x14,0x01,0xf5,0x00,0x00,0x70,0x07,0x00,0x00,0x81,0x00,0x00,0xa8};
struct {
int8 Key[19];
int8 Start[8];
}Buffer={};
void SendKey(int16 *data, int8 dl){
read_program_memory(data,Buffer.Key,dl);
//more code here!
}
void main(void){
SendKey(&Key_20,sizeof(Key_20));
delay_ms(1000);
//more code here!
} |
Anyway now all is fine. |
|
|
|
|
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
|