|
楼主 |
发表于 2011-6-23 15:46:06
|
显示全部楼层
可以写入了,但现在出现一个问题,就是为了提高写入准确性,想读回数据校验,卡编程完成之后立马返回的数据是不是就是我刚刚写进去的?
unsigned char BlockWrite5557(unsigned char block, unsigned char *key, unsigned char *sDat,unsigned char *rDat)
{
unsigned char temp[3];
unsigned char stu;
temp[0] = 0x80 | ((block & 0x10) << 2); //1100 0000或1000 0000
temp[1] = (block & 0x08) << 4; //1000 0000 0000
temp[2] = (block & 0x07) << 5; //1110 0000 0000
SendCmd5557(&temp[0], 0x80 | 2); //2位操件码
if (key[0]) SendCmd5557(&key[1], 32); //密码位
SendCmd5557(&temp[1], 1); //1位锁定位
SendCmd5557(&sDat[0], 32); //32位数据位
SendCmd5557(&temp[2], 0x40 | 3); //3位块地址位
stu =1;
if (GetPreamble()==0) //捕捉头
{
if (ReadWord(rDat,4)) 读入rDat[4]中……
{
stu=0;
}
}
return stu;
}
unsigned char WG_WriteT5557(unsigned char *sdat) //返回0有效
{
unsigned char SysKey[] = {0x01, 0x01, 0x02, 0x02, 0x24};
unsigned char i,ch,stu;
unsigned char rdat[4];
unsigned char text[4]={0xFF,0xFF,0xFF,0xFF};
for (i=0; i<1; i++) //试写块1
{
for (ch=0; ch<3; ch++) //循环3次写入并校验
{
stu = BlockWrite5557(i+1, &SysKey[0], &sdat[4*i],rdat); //读取写入数据
eeprom_write_block(text,0x60,4);
eeprom_write_block(rdat,0x60,4); 返回的数据(32位)写入EEPROM便于观察
Sound(RED_LONG|1);
if (stu==0)
{
if (memcmp(&sdat[4*i],rdat,4)==0) break; //比较数据正确就跳出
stu = 1;
}
if(stu==1) break;
}
if(stu==0) break; //3次写入失败 stu=1;
}
return stu; //写入成功 stu=1;
} |
|