大哥,你可以帮我看一下我下面这段ISP断电保存的程序是哪里出错了吗?一直没有办法工作
bit EA_Save_bit = 1;
void Clear_BOF(void)
{
EA_Save_bit = EA;
EA = 0;
TA = 0xAA;
TA = 0x55;
PMCR &= 0xF3;
TA = 0xAA;
TA = 0x55;
CHPCON = 0x3B;
EA = EA_Save_bit;
}
//-----------------------------------------------------------------------------------------------------------
void Enable_ISP_Mode(void)
{
/* Enable ISP */
ISPCN=0x30;
EA_Save_bit = EA;
EA = 0;
TA = 0xAA;
TA = 0x55;
CHPCON |= 0x01;
EA = 1;
Trigger_ISP();
}
//-----------------------------------------------------------------------------------------------------------
void Disable_ISP_Mode(void)
{
/* Disable ISP */
ISPCN=0x30;
Trigger_ISP();
EA_Save_bit = EA;
EA = 0;
TA = 0xAA;
TA = 0x55;
CHPCON &= 0xFE;
EA = 1;//EA_Save_bit;
}
//-----------------------------------------------------------------------------------------------------------
void Trigger_ISP(void)
{
EA_Save_bit = EA;
EA = 0;
EA = 0;
TA = 0xAA;
TA = 0x55;
ISPTRG |= 0x01;//start
EA = 1;//EA_Save_bit;
}
//-----------------------------------------------------------------------------------------------------------
void Erase_DATA(void)
{
static uint u16Count;
Enable_ISP_Mode();
ISPCN = ERASE_ALL_DATA;
for(u16Count=96;u16Count<128;u16Count++)
{
ISPAL = LOBYTE(u16Count*128); // 96*128=12288=0x3000
ISPAH = HIBYTE(u16Count*128); // 每128字节/一页
Trigger_ISP();
}
Disable_ISP_Mode();
}
//-----------------------------------------------------------------------------------------------------------
void Read_DATA(void)
{
uchar j = 0;
Enable_ISP_Mode();
ISPAL = 0x00;
ISPAH = 0x30;
ISPCN = FLASH_READ_DATA;
if(j < 4)
{
Trigger_ISP();
status_buff.flash_value[j] = ISPFD;
ISPAL++;
if(ISPAL == 0)
{
ISPAH++;
}
}
j++;
Disable_ISP_Mode();
}
//-----------------------------------------------------------------------------------------------------------
void Program_DATA(void)
{
uchar j = 0;
Enable_ISP_Mode();
ISPAL = 0x00;
ISPAH = 0x30;
ISPCN = BYTE_PROGRAM_DATA;
if(j < 4)
{
ISPFD = status_buff.flash_value[j];
Trigger_ISP();
ISPAL++;
if(ISPAL == 0)
{
ISPAH++;
}
}
j++;
Disable_ISP_Mode();
}
|