bit SetIAP(uchar Address)
{
bit i = EA;
if(Address % 2)return(1);//IAPLB must be even number
EA = 0;
IFMT = 0x04; //IAPLB set command
IFD = Address;//0x02*0x100 = 0x200;(must be even number!!)
ISPCR|= 0x80; //enable ISP
SCMD = 0x46;
SCMD = 0xB9; //start to set IAPLB
_nop_();
SCMD = 0; //disable the isp
ISPCR = 0; //disable ISP
EA = i;
return(0);
}
bit WriteIAP(uint Address,uchar dat)
{
bit i = EA;
EA = 0;
IFADRH = Address >> 8; //address high byte
IFADRL = (uchar)Address;//address low byte
IFMT = 0x02; //write command
IFD = dat; //data
ISPCR |= 0x80; //enable ISP
SCMD = 0x46;
SCMD = 0xb9; //start to operate
_nop_();
SCMD = 0; //disable the isp
ISPCR = 0; //disable ISP
EA = i;
if(ISPCR & 0x10)return(1);
else return(0);
}
bit EraseIAP(uchar Address)
{
bit i = EA;
EA = 0;
IFADRH = Address; //address high byte
IFADRL = 0; //address low byte
IFMT = 0x03; //eraser command
ISPCR = 0x00; //waiting time set
ISPCR |= 0x83; //enable ISP
SCMD = 0x46;
SCMD = 0xb9; //start to operate
_nop_();
SCMD = 0; //disable the isp
ISPCR = 0; //disable ISP
EA = i;
if(ISPCR & 0x10)return(1);
else return(0);
}
uchar ReadIAP(uint Address)
{
bit i = EA;
EA = 0;
IFADRH = Address >> 8; //address high byte
IFADRL = (uchar)Address;//address low byte
IFMT = 0x01; //write command
ISPCR = 0x00; //waiting time set
ISPCR |= 0x83; //enable ISP
SCMD = 0x46;
SCMD = 0xb9; //start to operate
_nop_();
SCMD = 0; //disable the isp
ISPCR = 0; //disable ISP
EA = i;
return(IFD);
}