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

12f617 program memory write help

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



Joined: 05 Sep 2013
Posts: 1
Location: Italy

View user's profile Send private message

12f617 program memory write help
PostPosted: Thu Sep 05, 2013 4:31 am     Reply with quote

Hi,

I want to use the program memory of a 12F617 to store some data bytes (the chip misses data eeprom but has got program memory self r/w capability).

I have compiler V4.124. I followed the latest CCS manual at page 633 and examples. I am using write_program_memory() and erase_program_eeprom() calls.
I am using address 0x300 to store 8 byte of data. I can write the data only once, if I try to write different data to overwite the previous data I get garbage.
Notice that I am using MPLAB and MPSIM. Cannot test in real hw at the moment, so I don't know if it is a limitation of MPSIM or a problem with my code.

This is the simple code I am using:

Code:
void main()
{
   int ix;
   int8    value[16] = {1, 2, 3, 4, 0, 0, 0, 0};
   int8 newvalue[16] = {5, 6, 7, 8, 0, 0, 0, 0};
   int8 readvalue[16];
   
   ix = getenv("FLASH_ERASE_SIZE"); //returns 32
   ix = getenv("FLASH_WRITE_SIZE"); //returns 8
   
   //correct writing: will write 0201 0403 0000 000 at 0x300
   write_program_memory(0x300, value, 8);
   
   erase_program_eeprom(0x300); //as per CCS instructions
   
   //wrong writing: this will write garbage at 0x300 (0201 0003 0000 0000)
   write_program_memory(0x300, newvalue, 8);
   
   //do nothing
   for (;;)
      delay_ms(100); 
}
Can anybody help?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 06, 2013 2:14 pm     Reply with quote

According to the 12F617 data sheet, the PIC is supposed to automatically
erase the flash memory before it writes to it. The 12F617 data sheet says:
Quote:

3.4 Writing the Flash Program Memory

When the write is performed on the last word
(PMADRL<1:0> = 11), a block of sixteen words
is automatically erased and the content of
the four-word buffer registers are written into
the program memory.


The MPLAB simulator doesn't do this. I tested it with CCS vs. 4.141
and MPLAB vs. 8.91 and the flash memory bits are not erased
(set to all 1's) before new data is written. As a result, sequential
calls of write_program_memory() in the simulator do a bitwise
ANDing operation on the flash. This is what you are seeing.

Other people on the MPLAB forum report the same thing:
https://www.microchip.com/forums/tm.aspx?m=602846
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