本帖最后由 kfawj 于 2015-12-12 18:35 编辑
void SST26VF_WR(byte dat)
{
byte i, j;
j = dat;
for(i = 0x00; i < 0x08; i++){
if(j & 0x80){
SST26VF_D = 1;
}
else{
SST26VF_D = 0;
}
SST26VF_C = 1;
Nop();
j <<= 0x01;
SST26VF_C = 0;
}
}
byte SST26VF_RD(void)
{
byte i, j, dat;
dat = 0x00;
for(i = 0x00; i < 0x08; i++){
dat <<= 0x01;
j = SST26VF_Q;
SST26VF_C = 1;
if(j){
dat |= 0x01;
}
Nop();
SST26VF_C = 0;
}
return dat;
}
void SST26VFxxx_Read_Bytes(byte addh, word addl, byte *dat, word len)
{
word dl;
byte *p;
while(SST26VF_RStat() & 0x81);
p = dat;
SST26VF_S = 0;
SST26VF_WR(SST26VF_READ);
SST26VF_WR(addh);
SST26VF_WR(addl >> 0x08);
SST26VF_WR(addl & 0xFF);
for(dl = 0x00; dl < len; dl++){
*p = SST26VF_RD();
p++;
}
SST26VF_S = 1;
}
void SST26VFxxx_Write_Bytes(byte addh, word addl, byte *dat, word len)
{
word dl;
byte *p;
while(SST26VF_RStat() & 0x81);
SST26VF_WriteEN();
_T2IE = 0;
p = dat;
SST26VF_S = 0;
SST26VF_WR(SST26VF_PP);
SST26VF_WR(addh);
SST26VF_WR(addl >> 0x08);
SST26VF_WR(addl & 0xFF);
for(dl = 0x00; dl < len; dl++){
SST26VF_WR(*p);
p++;
}
SST26VF_S = 1;
_T2IE = 1;
SST26VF_WriteDI();
}
|