sle4442.c

来自「mifarea卡程序mifarea卡程序mifarea卡程序」· C语言 代码 · 共 104 行

C
104
字号
/****************************************
 * sle4442.c                            *
 * functions for sle4442 card           *
 * designed by liulixun                 *
 * last update: 05-18-2007              *
 ****************************************/

#include "..\inc\includes.h"

// read main memory
int Sle4442ReadMainMem(unsigned char address, unsigned char *buf)
{
    unsigned int i;
    
    // send command and address
    Sle4442Command(0x30, address, 0x00);
    // read data
    for(i=0; i<256-address; i++)
    {
        buf[i] = IccSyncGetChar();
    }
    // send another clock puls
    IccSyncClock();
    
    return i;
}

// update main memory
void Sle4442WriteMainMem(unsigned char address, unsigned char val)
{
    // send command
    Sle4442Command(0x38, address, val);
    // polling io
    IccSyncPollingIO(50);
}

// read 4 bytes protect memory
void Sle4442ReadProtectMem(unsigned char *buf)
{
    unsigned char ci;
    
    // send command
    Sle4442Command(0x34, 0x00, 0x00);
    // read data
    for(ci=0; ci<4; ci++)
    {
        buf[ci] = IccSyncGetChar();
    }
    // send another clock puls
    IccSyncClock();
}

// write protect memory
void Sle4442WriteProtectMem(unsigned char address, unsigned char val)
{
    // send command
    Sle4442Command(0x3c, address, val);
    // polling io
    IccSyncPollingIO(50);
}

// read 4 bytes
void Sle4442ReadSecurityMem(unsigned char *buf)
{
    unsigned char ci;
    
    // send command
    Sle4442Command(0x31, 0x00, 0x00);
    // read data
    for(ci=0; ci<4; ci++)
    {
        buf[ci] = IccSyncGetChar();
    }
    // send another clock puls
    IccSyncClock();
}

// update 
void Sle4442WriteSecurityMem(unsigned char address, unsigned char val)
{
    // send command
    Sle4442Command(0x39, address, val);
    // polling io
    IccSyncPollingIO(50);
}

// verify
void Sle4442Verify(unsigned char address, unsigned char val)
{
    // send command
    Sle4442Command(0x33, address, val);
    // polling io
    IccSyncPollingIO(50);
}

void Sle4442Command(unsigned char cmd, unsigned char addr, unsigned char da)
{
    IccSyncStart();
    IccSyncPutChar(cmd);
    IccSyncPutChar(addr);
    IccSyncPutChar(da);
    IccSyncStop();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?