Reply by February 13, 20072007-02-13
In our application, when we update our application stored in flash of
AT89C51ED2 by the IAP function, sometimes we find that one bit every
128bytes can't be write right.for example, one bit every 128bytes was
'0' for ever and can't be changed to '1'.why?

About two years ago, ATMEL's Microcontroller T89C51RD2 was used in our
product. After ATMEL didn't produce it and advise us replace it by
AT89C51ED2. In order to be compatible with the former product which
use T89C51RD2, we use the API function(only make a little change) in
T89C51RD2's Anotes to write data to flash.

The API function of page write is:
#ifdef __API_WR_CODE_PAGE
Uchar __api_wr_code_page (Uint16 add_flash, Uint16 add_xram, Uchar
nb_data)
{
  bit ea_save;
  ea_save = EA;
#ifdef LARGE_MEMORY_MODEL
  data_addr_flash=add_flash;
  data_addr_xram=add_xram;
  data_nb_data=nb_data;
  DPTR = data_addr_flash;
  ACC = data_nb_data;
  __API_FILL_FF_PAGE();
  AUXR1 &= ~0x01;                /* Set DPTR=DPTR0 */
  DPTR = data_addr_flash;
  AUXR1++;                        /* DPTR=DPTR1 */
  DPTR = data_addr_xram;
  ACC = 0x09;
  ASM_MOV_R1_A();
  ACC = data_nb_data;             /* Number of bytes to program */
#else
  DPTR = add_flash;
  ACC = nb_data;
  __API_FILL_FF_PAGE();
  AUXR1 &= ~0x01;                /* Set DPTR=DPTR0 */
  DPTR = add_flash;
  AUXR1++;                        /* DPTR=DPTR1     */
  DPTR = add_xram;
  ACC = 0x09;
  ASM_MOV_R1_A();
  ACC = nb_data;
#endif
  __API_FLASH_ENTRY_POINT();
  AUXR1++;                        /* Set DPTR=DPTR0 */
      EA=ea_save;     // restore interrupt state
  return (ACC);
}
#endif

we add MAP_BOOT before __API_FLASH_ENTRY_POINT(); and
        UNMAP_BOOT after __API_FLASH_ENTRY_POINT();, so it can also be
used in AT89C51ED2.

Can you help me:
1.ATMEL stoped T89C51RD2 and because the flash write function have
some problem or other?
2.In __API_FILL_FF_PAGE(), it referred to FCON register, but in the
AT89C51ED2 DataSheet,  FCON is not used in API. if we use FCON in
AT89C51ED2's API function, does it have problem?
3.Can you give me some more messages about the defect of AT89C51ED2's
flash and the root of the defect?
4.Can you give me some advice?

Thanks in advice