View previous topic :: View next topic |
Author |
Message |
arschloch
Joined: 09 Jul 2013 Posts: 2 Location: Banned - spammer
|
10f200 how to read byte in program after #rom directive? |
Posted: Tue Jul 09, 2013 8:27 am |
|
|
Hello guys.
I need to save some data in ROM directly. I'm trying to google it for 3 hours, but I cannot find how to read them back and use in program
It looks like so:
Code: |
#include <10F200.h>
#rom 0xEF = {0x811, 0x811, 0x811, 0x811}
|
After then I need to read it back and use in program
read_program_memory doesn't works
Is it possible with this chip ? (dont know asm and pic controllers at all) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 09, 2013 12:15 pm |
|
|
The 10F200 doesn't have the ability to read flash program memory, but
you could do it like this, using a 'const' array as shown below. The #org
is optional. In MPLAB go to the View / Program Memory menu and look
at addresses starting at 0xEF. You will see it takes more than just 4
program memory locations to store the data. That's how it works.
If you don't use #org, the compiler will decide where to put the data.
That's OK.
Code: | #include <10F200.h>
#fuses NOWDT, NOMCLR
#use delay(clock=4M)
#org 0xEF, 0xFF
const int16 temp[] = {0x811, 0x922, 0xA33, 0xB44};
//==========================================
void main()
{
int8 i;
int16 value;
i = 3;
value = temp[i];
while(1);
} |
|
|
|
arschloch
Joined: 09 Jul 2013 Posts: 2 Location: Banned - spammer
|
|
Posted: Tue Jul 09, 2013 1:20 pm |
|
|
big thanks!
i've tried to use #org but did something wrong
your example works well |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Wed Jul 10, 2013 1:09 am |
|
|
You don't actually have to use #ORG (as PCM programmer says: "If you don't use #org, the compiler will decide where to put the data"). The data is still in 'program memory', you just don't know where. It doesn't make any difference if you know where it is or not, since the 10F, doesn't have any instruction to directly read program memory....
What the code is doing, is creating a small program, using an offset 'jump' based on the value given to it, and RETLW instructions to return the values required. So you could think of it as being equivalent to a program like:
Code: |
int16 tempval(int8 index)
{
switch (index) {
case 0:
return 0x811;
break;
case 1:
return 0x922;
break;
case 3:
return 0xA33;
break;
case 4:
return 0xB44;
break;
}
}
|
Except the compiler generates it as efficiently as possible.
Since it is program code, it is all in program memory.
It is a 'bodge round', for the chip's lack of a function to read the program memory....
Best Wishes |
|
|
|