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

PIC18 Program memory read/write

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








PIC18 Program memory read/write
PostPosted: Mon Aug 23, 2004 9:58 pm     Reply with quote

How can I read/write ONE byte to the program memory of 18F452? It seems all the reads/writes need to be done in chunks of two (or four?) bytes. Is one-byte operation possible?

And will writing only one byte using WRITE_PROGRAM_MEMORY( address, dataptr, 1);
work or it will destroy the next bytes?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Aug 24, 2004 8:53 am     Reply with quote

The way I understand it, writing to program memory is slow. If this is the case,... why wouldn't you read the 4,(or what ever) bytes, change the one byte that needs changing and write it out.

I know i skirted around the issue, but,.. I try to take the easy way out.
Ttelmah
Guest







Re: PIC18 Program memory read/write
PostPosted: Tue Aug 24, 2004 10:11 am     Reply with quote

Anonymous wrote:
How can I read/write ONE byte to the program memory of 18F452? It seems all the reads/writes need to be done in chunks of two (or four?) bytes. Is one-byte operation possible?

And will writing only one byte using WRITE_PROGRAM_MEMORY( address, dataptr, 1);
work or it will destroy the next bytes?

You can generate your own one byte read function, by directly accessing the registers involved, or just use the internal function, and 'make8', to extract the high byte of the low byte. The read is pretty simple, you just have to load the three address bytes into TBLPTRU, TBLPTRH, & TBLPTRL, issue a 'TBLRD' instruction, and retrieve the value from TABLAT.
The other way, the answer is no.
Writing is done in 'blocks'. These are 8bytes long on these chips. So to write one byte, requires you to read the seven values from the rest of the bytes in the same block, then write all eight values (the seven old values, and the one new one), in a single operation.
If you want to save byte wide data, consider the internal EEPROM instead. This supports byte wide access, and has much better read/write life. The primary reason to write to the internal program memory, would be to transfer code, and since the processor has a 16bit 'word', this would be the smallest unit it makes sense to use. The existing CCS functions allow this to be done. They will also should perform the necessary read/rewrite, for a single byte transfer, but personally I'd check the assembler before relying on this...

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