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

write_program_eeprom on 16F887?

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



Joined: 05 Oct 2007
Posts: 8

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

write_program_eeprom on 16F887?
PostPosted: Fri Mar 07, 2008 9:21 am     Reply with quote

PCM version 4.069

I'm confused about the usage of write_program_eeprom on 16F887.

According to the reference manual if FLASH_ERASE_SIZE > FLASH_WRITE_SIZE then write_program_eeprom does not erase.

I wrote a test program (see below) that reads the memory contents between 0x1C00 and 0x1C07 and sends it to the PC.
The original (erased by ICD2 programming of the chip) content is 16383.

I then reprogram the memory with 0..7 and read it again. This works.

I then reprogram the same addresses with a higher value. If the write_program_eeprom function does not erase I'm thinking this should not work, but it does, see output below.

Is it safe to use the write_program_eeprom this way to reprogram the program memory?

Thanks,

D2.

Code:
#include <16f887.h>
#fuses INTRC_IO,NOWDT,MCLR,NOPROTECT,BROWNOUT,BORV40,NOLVP
#device ADC=10
#use delay(internal=2M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=LIN)

void main(void) {
   unsigned int16 Value;
   unsigned int16  Scan;
   fprintf(LIN,"Erase Size: %u, Write Size: %u\n\r",getenv("FLASH_ERASE_SIZE"),getenv("FLASH_WRITE_SIZE"));
   for(Scan=0x1C00;Scan<0x1C08;Scan++){
      Value = read_program_eeprom(Scan);
      fprintf(LIN,"%5lu ",Value);
   }
   fprintf(LIN,"\n\r");
   for(Scan=0x1C00;Scan<0x1C08;Scan++){
      write_program_eeprom(Scan,Scan - 0x1C00);
   }
   for(Scan=0x1C00;Scan<0x1C08;Scan++){
      Value = read_program_eeprom(Scan);
      fprintf(LIN,"%5lu ",Value);
   }
   fprintf(LIN,"\n\r");
   for(Scan=0x1C00;Scan<0x1C08;Scan++){
      write_program_eeprom(Scan,Scan - 0x1000);
   }
   for(Scan=0x1C00;Scan<0x1C08;Scan++){
      Value = read_program_eeprom(Scan);
      fprintf(LIN,"%5lu ",Value);
   }
   fprintf(LIN,"\n\r");
   while (True) {
   }
}


Code:
Erase Size: 32, Write Size: 16
16383 16383 16383 16383 16383 16383 16383 16383
    0     1     2     3     4     5     6     7
 3072  3073  3074  3075  3076  3077  3078  3079
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 07, 2008 4:09 pm     Reply with quote

The erase operation is done by the PIC, in hardware, as part of
the write operation. It's not a separate operation that is invoked
by issuing a command. There is no "Erase" command.

The write_program_eeprom() function only writes one word to Flash,
so the procedure given in the PIC data sheet must be followed.
CCS does this in their library code:
Quote:
All eight buffer register locations should be written to
with correct data. If less than eight words are being writ-ten
to in the block of eight words, then a read from the
program memory location(s) not being written to must
be performed.


I've looked at the .LST file for the 16F887 for vs. 4.069, for a simple
test program that just has one line, that calls write_program_eeprom().
There may be a problem with the CCS code. I have some questions
about it. I'm still looking at it.
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