T5557 讀寫卡詳解


 

 

 

 

T5557的基本信息就不在這里詳細介紹,不了解的可以去看T5557的收據手冊。

一上來直接開始講操作

 存在七種操作,我們重點介紹四種,Standard Write,Protected Write,Direct access(PWD = 0)和Direct access(PWD = 1)。

Standard Write和Direct access(PWD = 0)在T5557卡沒有設置密碼模式(Page0的Block0的第28位PWD設置為0)的時候使用,此為無密碼模式,修改卡內的數據無需任何權限。

Protected Write和Direct access(PWD = 1)在T5557卡密碼模式Page0的Block0的第28位PWD設置為1)下使用,此為有密碼模式,修改卡內數據需要驗證密碼的正確性。

下面將詳細介紹用白卡完成以上的四種操作。

拿到白卡的第一步是配置Page0的Block0配置寄存器(Mode Register)詳見Figure 3,默認值為‘00 08 80 E8’h,表示RF/32、曼徹斯特編碼,無密碼模式。

需要將模式寄存器的修改為‘00 14 80 00’h,表示RF/64、曼徹斯特編碼。如需設置密碼求將第28位設置為1。

初始化函數如下:

void Card_initialization()//初始化卡片
{
Start_Gap();
SendOpcode(StandardWrite10); //10 2
SendLock(LOCK00); //0 1
SendByte(InitT55xxDataArr[0]); // 4
SendByte(InitT55xxDataArr[1]); // 4
SendByte(InitT55xxDataArr[2]); // 4
SendByte(InitT55xxDataArr[3]); // 4
SendAddress(BLOCK0);
}

 

Standard Write:

///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// 函數名: Standard_Write_T5577(uchar lock,uchar opcode,uchar data_arr[4],uchar block)
// 參 數: lock為要發送的鎖定位,block為待寫入數據的塊編號數 ,opcode為待發送的操作碼,data_arr[4]為要發送的4字節數據
void Standard_Write_T5577(unsigned char opcode,unsigned char lock,unsigned char data_arr[4],unsigned char block)
{
Start_Gap();
SendOpcode(opcode); //10 2
SendLock(lock); //0 1
SendByte(data_arr[0]); // 4
SendByte(data_arr[1]); // 4
SendByte(data_arr[2]); // 4
SendByte(data_arr[3]); // 4
SendAddress(block); // 3
}

Protected Write:

void Protect_Write_T5577(unsigned char opcode,unsigned char lock,unsigned char data_arr[4],unsigned char block)
{
Start_Gap();
SendOpcode(opcode); //10 2
SendPassword();
SendLock(lock); //0 1
SendByte(data_arr[0]); // 4
SendByte(data_arr[1]); // 4
SendByte(data_arr[2]); // 4
SendByte(data_arr[3]); // 4
SendAddress(block); // 3
}

Direct access(PWD = 0):

void Read_0_Page_block(unsigned char block) //塊讀0頁
{
Start_Gap();
SendOpcode(StandardWrite10); //10 2
SendLock(0X00); //0 1
SendAddress(block);

}

Direct access(PWD = 1):

void Protect_Read_0_Page_block(unsigned char block) //保護讀讀0頁 此時PWD需要設置為1
{
Start_Gap();
SendOpcode(StandardWrite10); //10 2
SendPassword(); //此密碼根據卡號匹配數據庫獲得
SendLock(0X00); //0 1
SendAddress(block);

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM