新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > SLE4442卡_IC的51單片機(jī)驅(qū)動(dòng)程序

SLE4442卡_IC的51單片機(jī)驅(qū)動(dòng)程序

作者: 時(shí)間:2016-12-02 來源:網(wǎng)絡(luò) 收藏

void Byte_WRT(uchar Xdata) //寫字節(jié)
{
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; //循環(huán)右移,從最低位開始寫
}
}

本文引用地址:http://butianyuan.cn/article/201612/324690.htm


void Command(uchar command,uchar address,uchar IC_data)
{
Start();
Byte_WRT(command); //發(fā)送命令
Byte_WRT(address); //發(fā)送地址
Byte_WRT(IC_data); //發(fā)送數(shù)據(jù)
Stop(); //操作命令結(jié)束
}

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) //密碼校驗(yàn)函數(shù)
{
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) //讀主存區(qū)
{
Command(0x30,addr,0xff);
while(N--)
{
*p=Byte_Read();
p++;
}
}



評(píng)論


技術(shù)專區(qū)

關(guān)閉