|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
PIC18 Program memory read/write |
Posted: Mon Aug 23, 2004 9:58 pm |
|
|
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
|
|
Posted: Tue Aug 24, 2004 8:53 am |
|
|
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 |
Posted: Tue Aug 24, 2004 10:11 am |
|
|
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 |
|
|
|
|
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
|