www.pudn.com > TCPmodbushy.rar > OP_FlashOfCP220.c
/******************************************************************************
* Module Name : OP_FlashOfCP220.C
* CPU Type : c8051
*
* Description :
*
* History Author Version Comment
* 06.09.15 sjh V0.1 Original version
*
* Copyright (C) 2003 Xinje Electronic Co., Ltd. All rights reserved.
******************************************************************************/
#include "o:\netif\CP220x_REG.h"
#include "o:\netif\OP_FlashOfCP220.h"
bit data OpenEA;
/******************************************************************************
* erase
******************************************************************************/
void EraseFlash( unsigned int iSetorAdd )
{
OpenEA = EA;
EA = OFF;
/* Step 1: Write 0xA5 followed by 0xF1 to FLASHKEY. */
FLASHKEY = 0xA5;
FLASHKEY = 0xF1;
/* Step 2: Set FLASHADDRH:FLASHADDRL to any address within the 512-byte page to be erased. */
FLASHADDRH = HIGH_BYTE( iSetorAdd );
FLASHADDRL = LOW_BYTE( iSetorAdd );
/* Step 3: Write the value 0x01 to FLASHERASE. */
FLASHERASE = 0x01;
/* Step 4: Check FLASHSTA to determine when the Flash operation is complete. The Flash Write/Erase */
while( FLASHSTA & FLBUSY )
continue;
EA = OpenEA;
}
/******************************************************************************
* Write Data To byte
* Note: 1.donot call this function in IntProcess Function;
* Note: 2.data be Written's space be ensure to erase
******************************************************************************/
void WriteByteToFlash( unsigned int iSetorAdd, unsigned char chData )
{
OpenEA = EA;
EA = OFF;
/* Step 1: Write 0xA5 followed by 0xF1 to FLASHKEY. */
FLASHKEY = 0xA5;
FLASHKEY = 0xF1;
/* Step 2: Set FLASHADDRH:FLASHADDRL to the address of the byte to be written. */
FLASHADDRH = HIGH_BYTE( iSetorAdd );
FLASHADDRL = LOW_BYTE( iSetorAdd );
/* Step 3: Write the value to be written to the FLASHDATA register. */
FLASHDATA = chData;
/* Step 4: Check FLASHSTA to determine when the Flash operation is complete. */
while( FLASHSTA & FLBUSY )
continue;
EA = OpenEA;
}
/******************************************************************************
* Write Mul bytes
* Note: once Write Bytes most is 256
******************************************************************************/
void WriteMulByteSToFlash( unsigned int iSetorAdd, unsigned char chCount, unsigned char xdata *pData )
{
unsigned char i;
for( i=0; i