原创 iar 8051 中实现对F530Aflash编程

2010-8-8 20:43 2664 9 9 分类: MCU/ 嵌入式

重点是要产生movx指令


 


//-----------------------------------------------------------------------------
// FLASH_ByteWrite
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   :
//   1) FLADDR addr - address of the byte to write to
//                    valid range is 0x0000 to 0x3BFF for 16K Flash devices
//                    valid range is 0x0000 to 0x1FFF for  8K Flash devices
//   2) U8 byte - byte to write to Flash.
//
// This routine writes <byte> to the linear FLASH address <addr>.
//-----------------------------------------------------------------------------


void FLASH_ByteWrite (unsigned char __code *addr, U8 byte)
{
   unsigned char EA_SAVE = IE_bit.EA;                   // Preserve EA
   unsigned char __xdata *pwrite;             // FLASH write pointer


   IE_bit.EA = 0;


    VDM0CN = 0xA0;                      // Enable VDD monitor and high threshold


   RSTSRC = 0x02;                      // Enable VDD monitor as a reset source


   pwrite = (unsigned char __xdata*)addr;


   FLKEY  = 0xA5;                      // Key Sequence 1
   FLKEY  = 0xF1;                      // Key Sequence 2
   PSCTL = 0x01;                      // PSWE = 1 which enables writes PSEE = 1


   VDM0CN = 0xA0;                      // Enable VDD monitor and high threshold


   RSTSRC = 0x02;                      // Enable VDD monitor as a reset source


   *pwrite = byte;                     // Write the byte


   PSCTL &= ~0x01;                     // PSWE = 0 which disable writes


    IE_bit.EA = EA_SAVE;                // Restore interrupts


}


 


//-----------------------------------------------------------------------------
// FLASH_PageErase
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   :
//   1) FLADDR addr - address of any byte in the page to erase
//                    valid range is 0x0000 to 0x39FF for 16K Flash devices
//                    valid range is 0x0000 to 0x1DFF for  8K Flash devices
//
// This routine erases the FLASH page containing the linear FLASH address
// <addr>.  Note that the page of Flash containing the Lock Byte cannot be
// erased from application code.
//-----------------------------------------------------------------------------


void FLASH_PageErase (unsigned char __code *addr)
{
    unsigned char EA_SAVE = IE_bit.EA;  // Preserve EA
    unsigned char __xdata *pwrite;             // FLASH write pointer



   
   IE_bit.EA = 0;                             // Disable interrupts


   VDM0CN = 0xA0;                      // Enable VDD monitor and high threshold


   RSTSRC = 0x02;                      // Enable VDD monitor as a reset source


   pwrite = (unsigned char __xdata *) addr;


   FLKEY  = 0xA5;                      // Key Sequence 1
   FLKEY  = 0xF1;                      // Key Sequence 2
   PSCTL |= 0x03;                      // PSWE = 1; PSEE = 1


   VDM0CN = 0xA0;                      // Enable VDD monitor and high threshold


   RSTSRC = 0x02;                      // Enable VDD monitor as a reset source


   *pwrite = 0;                        // Initiate page erase


   PSCTL &= ~0x03;                     // PSWE = 0; PSEE = 0


   IE_bit.EA = EA_SAVE;                       // Restore interrupts
}

文章评论0条评论)

登录后参与讨论
我要评论
0
9
关闭 站长推荐上一条 /2 下一条