本帖最后由 飘雪殇 于 2018-6-4 19:55 编辑
#define DATA_SIZE 128
#define PAGE_ERASE_AP 0x22
#define BYTE_READ_AP 0x00
#define BYTE_PROGRAM_AP 0x21
#define PAGE_SIZE 128
void Trigger_IAP(void)
{
set_IAPGO; //trigger IAP
if((CHPCON&SET_BIT6)==SET_BIT6) // if fail flag is set, toggle error LED and IAP stop
{
clr_IAPFF;
}
}
void Erase_APROM(u16 u16_addr)
{
UINT16 u16Count;
set_IAPEN; // Enable IAP function
IAPFD = 0xFF; // IMPORTANT !! To erase function must setting IAPFD = 0xFF
IAPCN = PAGE_ERASE_AP;
set_APUEN; // APROM modify Enable
for(u16Count=0x0000;u16Count<DATA_SIZE/PAGE_SIZE;u16Count++) //
{
IAPAL = LOBYTE(u16Count*PAGE_SIZE + u16_addr);
IAPAH = HIBYTE(u16Count*PAGE_SIZE + u16_addr);
Trigger_IAP();
}
clr_APUEN;
clr_IAPEN;
}
void write_DATAFLASH_BYTE(u16 START_ADDR,u8 u8_Data)
{
set_IAPEN;
set_APUEN;
IAPAL = LOBYTE(START_ADDR);
IAPAH = HIBYTE(START_ADDR);
IAPCN = BYTE_PROGRAM_AP;
IAPFD = u8_Data;
Trigger_IAP();
clr_APUEN;
clr_IAPEN;
}
//-------------------------------------------------------------------------
UINT8 read_APROM_BYTE(UINT16 Data_Addr)
{
UINT8 rdata;
set_IAPEN;
IAPAL = Data_Addr;
IAPAH = Data_Addr>>8;
IAPCN = 0x00;
rdata = 0x00;
set_IAPGO;
rdata = IAPFD;
clr_IAPEN;
return rdata;
}
|