新闻中心

EEPW首页>嵌入式系统>设计应用> SLE4442卡_IC的51单片机驱动程序

SLE4442卡_IC的51单片机驱动程序

作者: 时间:2016-12-02 来源:网络 收藏

void Byte_WRT(uchar Xdata) //写字节
{
uchar count;
DATA_OUT;
DelayUs(2);
for(count=8;count!=0;count--)
{
CLK_LOW;
DelayUs(2);
if((Xdata)&0x01)
{
DATA_HIGH;
}
else
{
DATA_LOW;
}
DelayUs(2);
CLK_HIGH;
DelayUs(2);
Xdata = Xdata >> 1; //循环右移,从最低位开始写
}
}

本文引用地址://m.amcfsurvey.com/article/201612/324690.htm


void Command(uchar command,uchar address,uchar IC_data)
{
Start();
Byte_WRT(command); //发送命令
Byte_WRT(address); //发送地址
Byte_WRT(IC_data); //发送数据
Stop(); //操作命令结束
}

void Process(void)
{
uint j; //写指令后的处理过程
DATA_OUT;
DelayUs(2);
CLK_LOW;
DATA_LOW;
DelayUs(2);
for(j = 0;j < 255;j++)
{
CLK_HIGH;
DelayUs(2);
CLK_LOW;
DelayUs(2);
}
DATA_HIGH;
}

void Process2(void)
{
uint j; //写指令后的短处理过程
DATA_OUT;
DelayUs(2);
CLK_LOW;
DATA_LOW;
DelayUs(2);
for(j = 0;j < 2;j++)
{
CLK_HIGH;
DelayUs(2);
CLK_LOW;
DelayUs(2);
}
DATA_HIGH;
}

uchar Code_Check(uchar Code1,uchar Code2,uchar Code3) //密码校验函数
{
uchar i;
Command(0x31,0x00,0x00);
for(i = 0;i < 4;i++)
{
ErrorCount[i] = Byte_Read();
}
if(ErrorCount[0] == 0)
{
return 0;
}
else
{
if((ErrorCount[0]&0x01) == 1)
{
ErrorCount[0] &= 0x06; //bit0=0;
}
else if((ErrorCount[0]&0x02) == 1)
{
ErrorCount[0] &= 0x05; //bit1=0;
}
else
{
ErrorCount[0] &= 0x03; //bit2=0
}
}
Command(0x39,0x00,ErrorCount[0]);
Process();

Command(0x33,0x01,Code1);
Process2();

Command(0x33,0x02,Code2);
Process2();

Command(0x33,0x03,Code3);
Process2();

Command(0x39,0x00,0xff);
Process();

Command(0x31,0x00,0x00);
for(i = 0;i < 4;i ++)
{
ErrorCount[i] = Byte_Read();
}
if(ErrorCount[0] == 0x07)
{
return 1;
}
else
{
return 0;
}
}


void ReadMainROM(uchar addr,uchar *p,uchar N) //读主存区
{
Command(0x30,addr,0xff);
while(N--)
{
*p=Byte_Read();
p++;
}
}



评论


技术专区

关闭