📄 iap1.c
字号:
//SST89e554 IAP
#include <intrins.h>
#include "reader.h"
#include "iap.h"
//#include "sst89e554rc.h"
pdata unsigned char IAPbuffer[128]=0;
unsigned char read_byte_Flash(unsigned int byte_address)
{
unsigned char ch;
SFCF =SFCF | 0x40;
SFAL=(unsigned char)(byte_address);
SFAH=(unsigned char)(byte_address>>8);
SFCM=ByteVerify;
_nop_();
ch =SFDT ;
SFCF=SFCF&0xBF;
SFDT=0;
return ch;
}
void read_Flash(unsigned int byte_address, unsigned char *buff, unsigned char len)
{
SFCF =SFCF|0x40;
while(len)
{
SFAL=(unsigned char)(byte_address);
SFAH=(unsigned char)(byte_address>>8);
SFCM=ByteVerify;
_nop_();
*buff=SFDT ;
buff++;
byte_address++;
len--;
}
SFCF=SFCF&0xBF;
SFDT=0;
// return ;
}
void sector_erase(unsigned char byte_address) //扇区擦除
{
SFCF=SFCF|0x40; //enable iap
SFAL=(unsigned char)(byte_address);
SFAH=(unsigned char)(byte_address>>8);
SFCM=SectorEase;
while(SFST&0X4){}
SFCF=SFCF&0xBF;
SFDT=0;
}
unsigned char pgm_byte_Flash(unsigned int byte_address, unsigned char ch)
{
SFCF =SFCF | 0x40;
SFAL=(unsigned char)(byte_address);
SFAH=(unsigned char)(byte_address>>8);
SFDT= ch;
SFCM= ByteProgram;
while(SFST&0x04){}
SFCF=SFCF&0xBF;
SFDT=0;
return ch;
}
void write_byte_Flash(unsigned int byte_address, unsigned char ch)
{
unsigned char i;
unsigned char pdata *buff;
SFCF =SFCF | 0x40;
// save block data
SFAH=(unsigned char)(byte_address>>8);
SFAL=(unsigned char) (byte_address) & 0x80;
buff = IAPbuffer;
for (i=128; i>0; i--)
{
SFCM=ByteVerify;
_nop_();
*buff=SFDT ;
buff++;
SFAL++;
}
// set new data
IAPbuffer[(unsigned char) (byte_address)] = ch;
// erase Sector
SFAH=(unsigned char)(byte_address>>8);
SFAL=(unsigned char) (byte_address);
SFCM=SectorEase;
while(SFST&0x04){}
// program data
SFAH=(unsigned char)(byte_address>>8);
SFAL=(unsigned char) (byte_address) & 0x80;
buff = IAPbuffer;
for (i=128; i>0; i--)
{
SFDT=*buff;
SFCM=ByteProgram;
while(SFST&0x04){}
buff++;
SFAL++;
}
SFCF=SFCF&0xBF;
SFDT=0;
}
void write_Flash(unsigned int byte_address, unsigned char *dat, unsigned char len)
{
unsigned char i;
unsigned char pdata *buff;
SFCF =SFCF | 0x40;
while (len)
{
// save sector data
SFAH=(unsigned char)(byte_address>>8);
SFAL=(unsigned char) (byte_address) & 0x80;
buff = IAPbuffer;
for (i=128; i>0; i--)
{
SFCM=ByteVerify;
_nop_();
*buff=SFDT ;
buff++;
SFAL++;
}
buff = IAPbuffer + (((unsigned char)(byte_address)) & 0x7F);
for (; buff<128; buff++)
{
*buff = *dat;
dat++;
if (--len == 0) break;
}
// erase Sector
SFAH=(unsigned char)(byte_address>>8);
SFAL=(unsigned char) (byte_address) & 0x80;
SFCM=SectorEase;
while(SFST&0x04){}
// program data
SFAH=(unsigned char)(byte_address>>8);
SFAL=(unsigned char) (byte_address) & 0x80;
buff = IAPbuffer;
for (i=128; i>0; i--)
{
SFDT=*buff;
SFCM=ByteProgram;
while(SFST&0x04){}
buff++;
SFAL++;
}
byte_address = (byte_address & 0xFF80) + 0x80;
}
SFCF=SFCF&0xBF;
SFDT=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -