AT88SC102卡 不能写0操作
现在在用msp430写一个AT88SC102卡的底层驱动,现在密码校验已经可以了,要修改应用区的数据。大家看下这两个函数有没有问题。现在将应用区数据擦出为1是可以的了,现在想要将数据修改为0却不行。I/O的置位,地址的位置都是正确的
/********************************************************
* 写卡 *
********************************************************/
unsigned char AT88SC102Write(unsigned char startaddress,unsigned char *pointer_cardbuf,unsigned char bytes)
{
unsigned char i,j;
unsigned char doublebytes,wrbyte;
unsigned int bitstart;
unsigned char *temp_cardbuf;
temp_cardbuf=pointer_cardbuf;
bitstart = startaddress*8;
AT88SC102IO_OUT |= AT88SC102IO;
Card_SetAddress(bitstart);
AT88SC102IO_DIR |= AT88SC102IO;
doublebytes = bytes; //单字节数转为双字节数
doublebytes = (doublebytes + 1) >> 1;
doublebytes--;
if(doublebytes)
{
for(i = 0; i < doublebytes; i++)
{
Card_WriteBit(1);
for(j = 0; j < 16; j++)
{
Delay3us();
AT88SC102CLK_OUT |= AT88SC102CLK;
Delay3us();
AT88SC102CLK_OUT &= ~AT88SC102CLK;
Delay3us();
}
}
Card_WriteBit(1);
}else
{
Card_WriteBit(1);
}
// AT88SC102Pscverification(0xf0,0xf0,0);
Card_SetAddress(startaddress);
AT88SC102IO_DIR |= AT88SC102IO;
for(i = 0; i < bytes; i++)
{
wrbyte = *temp_cardbuf;
for(j = 0; j < 8; j++)
{
if(wrbyte & 0x80)
{
AT88SC102CLK_OUT |= AT88SC102CLK;
Delay3us();
AT88SC102CLK_OUT &= ~AT88SC102CLK;
Delay3us();
}
else
{
Card_WriteBit(0);
}
wrbyte = wrbyte << 1;
}
temp_cardbuf++;
}
return 1;
}
/********************************************************
* 写bit *
********************************************************/
void Card_WriteBit(unsigned char bitt) //擦除为写1
{
AT88SC102PGM_OUT |= AT88SC102PGM ;
Delay3us();
if(bitt == 1)
AT88SC102IO_OUT |= AT88SC102IO;
else
AT88SC102IO_OUT &= ~AT88SC102IO;
Delay3us();
AT88SC102CLK_OUT |= AT88SC102CLK;
Delay3us();
AT88SC102PGM_OUT &= ~AT88SC102PGM ;
__delay_cycles(12000);
AT88SC102CLK_OUT &= ~AT88SC102CLK;
Delay3us();
AT88SC102IO_OUT |= AT88SC102IO;
AT88SC102IO_DIR &= ~AT88SC102IO;
Delay3us();
AT88SC102CLK_OUT |= AT88SC102CLK;
Delay3us();
if((AT88SC102IO_IN&AT88SC102IO)==0)
{
Delay3us();
}
AT88SC102IO_DIR |= AT88SC102IO;
AT88SC102CLK_OUT &= ~AT88SC102CLK;
Delay3us();
}
[解决办法]
感谢大家,问题已经找到了,是Card_SetAddress(startaddress); 这里错了,应该改为Card_SetAddress(bitstart);就可以了
[解决办法]
大侠 有没有密码比较操作函数,给我发个呗。我也在做这个卡,读写都正确了就是比较密码不正确。多谢了865199288@qq.com 多谢了啊