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

10f200 how to read byte in program after #rom directive?

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



Joined: 09 Jul 2013
Posts: 2
Location: Banned - spammer

View user's profile Send private message

10f200 how to read byte in program after #rom directive?
PostPosted: Tue Jul 09, 2013 8:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 12:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 09, 2013 1:20 pm     Reply with quote

big thanks!
i've tried to use #org but did something wrong
your example works well
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Wed Jul 10, 2013 1:09 am     Reply with quote

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
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