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

memcpy

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



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

memcpy
PostPosted: Mon Sep 04, 2006 6:43 am     Reply with quote

Hello all,

I am starting out with CCS and PIC's. I have got the a point in my program that I need my PIC to learn a few ID's that are read into the PIC via a RS232 line.
When a new ID is to be learned a pin is taken low and the new ID is read on the RS232 line. This ID then must be given a reference (between 1-99) and stored in ROM.

Now I have been playing with the memcpy and read memory address from 0x1000 (as suggested by another user) and got the ff 3f reply. But If I try to put something in there before I read it, for example 11 (ascii) it wont read it back.
{
char ids[10];
int8 rf1[10] = "113A";
}
{
memcpy (0x1000, &rf1[0], 2);
}
{
read_program_memory(0x1000, ids[0], 2);
printf("%x %x %s", ids[0], ids[1], rf1);
}

output from this is

ff 3f 113A

surely it should be

31 31 113A ??

Am I missing something??

Thanks

Steve
bwgames



Joined: 21 Jul 2005
Posts: 36

View user's profile Send private message

PostPosted: Mon Sep 04, 2006 8:09 am     Reply with quote

Wouldn't it be easier to use the internal EEPROM? CCS provide commands and examples (EXT_INTEE.C) for this.

e.g. (not checked and it only works if your ID is 8bytes maximum.)
Code:

char ID;
char read_ID;

while(1)
{
if(PIN_XX==0) //if pin whatever is LOW
{
//read from rs232 and write value to eeprom
id = getch(); //get character from RS232
write_eeprom(0,ID); //write ID at address 0
}

read_string = read_eeprom(0); //if pin not low, read eeprom at address 0
printf("%c",read_ID); //output ID

}



You could use the EEPROM address as the ID.
Of course, this only works if your PIC has internal EEPROM on it (what chip is it?), but hopefully it gives you a starting point.
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Mon Sep 04, 2006 8:58 am     Reply with quote

It would be easier if the PIC i was using had internal EEPROM, I am using the PIC16F77 and has no EEPROM for data.

I am thinking about moving to the PIC16F877 anyways so that will give me user EEPROM.

Thanks for help though.
Ttelmah
Guest







PostPosted: Mon Sep 04, 2006 9:13 am     Reply with quote

The reason the program doesn't give the results you expect, is that memcpy, only talks to the RAM, not to the program memory.
You need to write the data, with the write_program_memory command, before you can read it with the read_program_memory command.
Beware, that the write life of the program memory is short. Using EEPROM, is _much_ better, if this data needs to be updated at all frequently. Changing to the 877, or adding an external EEPROM, is a much better solution. Also, if you intend to write to a fixed memory area like this, then you _must_reserve the area, or you will end up overwriting the program...

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