📄 flash.c
字号:
#include <intrins.h>
#include "config.h"
#include "system.h"
#include "isp.h"
#define delay_us() { _nop_(); _nop_(); _nop_();}
void vFlashCmd(unsigned char cmd)
{
#if Sp756P==1
v_A16 = 0;
v_A17 = 0;
#else
vBankValue(0);
#endif
vWriteFlash(0x5555, 0xAA);
vWriteFlash(0x2AAA, 0x55);
vWriteFlash(0x5555, cmd);
}
void vFlashErase(void)
{
unsigned char mPola,mPolb;
vFlashCmd(0x80); //擦除命令序列
vFlashCmd(0x10);
mPola = vReadFlash(0x5555);
mPolb = vReadFlash(0x5555);
while ((mPola ^ mPolb) == 0x40)
{
mPola = mPolb;
mPolb = vReadFlash(0x5555);
}
}
void vWriteSector(unsigned char *wAddr,unsigned int mFSector,unsigned int wSector,unsigned char wBank)
{
unsigned char data wdat;
unsigned int data i;
unsigned char mPolc, mPold;
vExitInterrupt();
vFlashCmd(0xA0);
vBankSet(wBank);
for(i=0;i<mFSector;i++)
{
wdat = *(wAddr+i);
vWriteFlash(wSector,wdat);
wSector++;
}
wait_ms(Twc);
wSector--;
mPolc = vReadFlash(wSector);
mPold = vReadFlash(wSector);
while ((mPolc ^ mPold) == 0x40)
{
mPolc = mPold;
mPold = vReadFlash(wSector);
}
vEnterInterrupt();
}
unsigned int vVerify(unsigned char *vBuff,unsigned int mFSector,unsigned int vAddress,unsigned char vBank)
{
unsigned char data vchar;
unsigned char vHexcode;
unsigned int vnum;
unsigned int vErrsum = 0;
vExitInterrupt();
vBankSet(vBank);
for(vnum=0;vnum<mFSector;vnum++)
{
vHexcode = *(vBuff+vnum);
vchar = vReadFlash(vAddress);
vAddress++;
if(vchar != vHexcode)vErrsum++;
}
vEnterInterrupt();
return vErrsum;
}
unsigned int vFlashId(void)
{
unsigned int flash_id=0;
vFlashCmd(0x90);
wait_ms(Twc);
flash_id = vReadFlash(0x0000) << 8 | vReadFlash(0x0001);
vFlashCmd(0xF0);
wait_ms(Twc);
return flash_id;
}
void wait_ms(unsigned int click)
{
unsigned int idata i;
unsigned int idata cli;
cli = click;
while(cli--)
{
i=48;
do{
delay_us();
}while(i--);
}
}
void vBankSet(unsigned char bank)
{
#if Sp756P==1
switch(bank)
{
case 0x00 :
v_A16 = 0;
v_A17 = 0;
break;
case 0x01 :
v_A16 = 1;
v_A17 = 0;
break;
case 0x02 :
v_A16 = 0;
v_A17 = 1;
break;
case 0x03 :
v_A16 = 1;
v_A17 = 1;
break;
default:
v_A16 = 0;
v_A17 = 0;
break;
}
#else
switch(bank)
{
case 0x00 :
vBankValue(0);
break;
case 0x01 :
vBankValue(1);
break;
case 0x02 :
vBankValue(2);
break;
case 0x03 :
vBankValue(3);
break;
default:
vBankValue(0);
break;
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -