/****************************************************************************
* 名 称:Get_Balance()
* 功 能:取余额
* 入口参数:money 余额
* 出口参数:0正常,,其它错误码
****************************************************************************/
unsigned char Get_Balance(unsigned long *money){
unsigned char cmd[]={0x0a,0x00,0x80,0x5c,0x00,0x02,0x04};
unsigned char buff[10];
unsigned char len;
unsigned short st;
if(PiccCMD14443_4(cmd,buff,7,&len)==0){
st = buff[len-2]*0x100+buff[len-1];
if(st==0x9000){
memcpy((unsigned char *)money,&buff[2],4);
return 0;
}else{
return 2;
}
}
return 1;
}
/****************************************************************************
* 名 称:Cash_Withdraw()
* 功 能:消费初始化
* 入口参数:sn 终端编号
money 交易金额
passwordtype 密码类型
MAC1 MAC1
len 卡返回数据的长度
* 出口参数:0正常,,其它错误码
****************************************************************************/
unsigned char Cash_Withdraw(unsigned char *sn,//终端编号
unsigned char *money,//交易金额
unsigned char passwordtype,
unsigned char *MAC1,
unsigned char *len){//消费初始化
unsigned char cmd[]={ 0x0b,0x00,0x80,0x50,0x01,0x02,0x0b};
unsigned char cmd1[19];
unsigned char i,cmd_len=0;
unsigned char bak;
unsigned short st;
for(i=0;i<7;i++)
cmd1[cmd_len++]=cmd[i];
cmd1[cmd_len++]=passwordtype;
for(i=0;i<4;i++)
cmd1[cmd_len++]=money[i];
for(i=0;i<6;i++)
cmd1[cmd_len++]=sn[i];
cmd1[cmd_len++]=0x0f;
bak = PiccCMD14443_4(cmd1,MAC1,19,len);
if(bak==0){
st = MAC1[*len-2]*0x100+MAC1[*len-1];
if(st==0x9000){
return 0;
}else{
return 2;
}
}else{
return 1;
}
}
/****************************************************************************
* 名 称:charCash_Withdraw2()
* 功 能:消费
* 入口参数:je_sn 义易序列号
je_data 交易日期
je_time 交易时间
mac1 MAC1
* 出口参数:0正常,,其它错误码
****************************************************************************/
unsigned char charCash_Withdraw2(unsigned char *je_sn,
unsigned char *je_data,
unsigned char *je_time,
unsigned char *mac1
){
unsigned char cmd[30];
unsigned char i,cmd_len=7;
unsigned char bak;
unsigned short st;
unsigned char buff[20];
unsigned char len;
je_sn=je_sn;
cmd[0]=0x0a;
cmd[1]=0x00;
cmd[2]=0x80;
cmd[3]=0x54;
cmd[4]=0x01;
cmd[5]=0x00;
cmd[6]=0x0f;
for(i=0;i<4;i++)
cmd[cmd_len++]=je_sn[i];
for(i=0;i<4;i++)
cmd[cmd_len++]=je_data[i];
for(i=0;i<3;i++)
cmd[cmd_len++]=je_time[i];
for(i=0;i<4;i++)
cmd[cmd_len++]=mac1[i];
bak = PiccCMD14443_4(cmd,buff,22,&len);
if(bak==0){
st = buff[len-2]*0x100+buff[len-1];
if(st==0x9000) return 0;
return 2;
}else{
return bak;
}
}
/****************************************************************************
* 名 称:GetName()
* 功 能:取姓名
* 入口参数:name 名字
* 出口参数:0正常,,其它错误码
****************************************************************************/
unsigned char GetName( unsigned short *name ){
unsigned char cmd[]={0x0b,0x00,0x00,0xb0,0x96,0x00,0x0a};//0a,0a
unsigned char buff[15];
unsigned char len;
unsigned char i;
unsigned short st;
unsigned char r_data[]="0123456789abcdef";
unsigned char r_data1[]="0123456789ABCDEF";
//11 0A 00 6F 0B 84 09 A0 00 00 00 03 86 98 07 02 90 00
if(PiccCMD14443_4(cmd,buff,7,&len)==0){
st = buff[len-2]*0x100+buff[len-1];
// SendStr(buff,len);
if(st==0x9000){
*name = 0 ;
for( i = 0 ; i < 16 ; i++ ){
if(r_data[i]==buff[2]) break;
if(r_data1[i]==buff[2]) break;
}
*name = *name * 0x10;
*name = *name+i;
for( i = 0 ; i < 16 ; i++ ){
if(r_data[i]==buff[3]) break;
if(r_data1[i]==buff[3]) break;
}
*name = *name * 0x10;
*name = *name+i;
for( i = 0 ; i < 16 ; i++ ){
if(r_data[i]==buff[4]) break;
if(r_data1[i]==buff[4]) break;
}
*name = *name * 0x10;
*name = *name+i;
for( i = 0 ; i < 16 ; i++ ){
if(r_data[i]==buff[5]) break;
if(r_data1[i]==buff[5]) break;
}
*name = *name * 0x10;
*name = *name+i;
//*name = buff[2]*0x100+buff[3];
return 0;
}else{
return 2;
}
}
return 1;//0B 00 62 28 10 20 01 00 00 00 02 02 00 00 20 07 08 01 00 00 00 08 90 00
//20 07 08 01 00 00 00 08
}
/****************************************************************************
* 名 称:IRQ_Eint3()
* 功 能:外部中断EINT3服务函数,取反B1控制口。
* 入口参数:无
* 出口参数:无
****************************************************************************/
void RC531_IRQ_Lib(void){
static unsigned char irqBits;
static unsigned char irqMask;
static unsigned char nbytes;
static unsigned char cnt;
WriteRawIO(0,0x80);
if (MpIsrInfo && MpIsrOut){
while( ReadRawIO(RegPrimaryStatus) & 0x08){ //是否有中断
irqMask = ReadRawIO(RegInterruptEn);
irqBits = ReadRawIO(RegInterruptRq) & irqMask;
MpIsrInfo->irqSource |= irqBits;
if (irqBits & 0x01){
nbytes = 64 - ReadRawIO(RegFIFOLength); //取FIFO长度
if ((MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent) <= nbytes){
nbytes = MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent;
WriteRawIO(RegInterruptEn,0x01); //开中断
}
for ( cnt = 0;cnt < nbytes;cnt++){
WriteRawIO(RegFIFOData,MpIsrOut[MpIsrInfo->nBytesSent]);
MpIsrInfo->nBytesSent++;
}
WriteRawIO(RegInterruptRq,0x01);
}
if (irqBits & 0x10){
WriteRawIO(RegInterruptRq,0x10); //清除标中断标记
WriteRawIO(RegInterruptEn,0x82);
if (MpIsrInfo->cmd == PICC_ANTICOLL1){
WriteIO(RegChannelRedundancy,0x02); //奇偶校验
WriteRawIO(0,0x80);
}
}
if (irqBits & 0x0E){
nbytes = ReadRawIO(RegFIFOLength);
for ( cnt = 0; cnt < nbytes; cnt++){
MpIsrOut[MpIsrInfo->nBytesReceived] = ReadRawIO(RegFIFOData);
MpIsrInfo->nBytesReceived++;
}
WriteRawIO(RegInterruptRq,0x0A & irqBits);
}
if (irqBits & 0x04){
WriteRawIO(RegInterruptEn,0x20);
WriteRawIO(RegInterruptRq,0x20);
irqBits &= ~0x20;
MpIsrInfo->irqSource &= ~0x20;
WriteRawIO(RegInterruptRq,0x04);
}
if (irqBits & 0x20){
WriteRawIO(RegInterruptRq,0x20);
MpIsrInfo->status = MI_NOTAGERR;
}
}
}
}
/****************************************************************************
* 名 称:Rc500Init
* 功 能:外部中断的初始化。
* 入口参数:无
* 出口参数:0正常,其它错误码
****************************************************************************/
unsigned char Rc500Init(void){
SPI1_Config();
RC531RST_CLR();
RC531NSS_SET();
return MfConfig();
}
/*
unsigned char PcdRequest(unsigned char req_code)
{
char status;
MfCmdInfo1 *pi;
PcdSetTmo(14);
WriteRC(RegChannelRedundancy,0x03);
ClearBitMask(RegControl,0x08);
WriteRC(RegBitFraming,0x07);
pi->MfCommand=PCD_TRANSCEIVE;
pi->MfLength=1;
pi->MfData[0]=req_code;
status=PcdComTransceive(pi);
// ser_send(&status,1);
if(!status)
{ if(pi->MfLength!=0x10)
{
//status=MI_BITCOUNTERR;
status=0x55;
}
}
return status;
}
unsigned char PcdAnticoll(unsigned char *snr) //读取卡片序列号函数
{
unsigned char i;
unsigned char snr_check=0;
char status=MI_OK;
MfCmdInfo1 *pi;
PcdSetTmo(14);
WriteRC(RegDecoderControl,0x28);
ClearBitMask(RegControl,0x08);
WriteRC(RegChannelRedundancy,0x03);
pi->MfCommand=PCD_TRANSCEIVE;
pi->MfLength=2;
pi->MfData[0]=PICC_ANTICOLL1;
pi->MfData[1]=0x20;
status=PcdComTransceive(pi);
// ser_send(&status,1);
if(!status)
{
for(i=0;i<4;i++)
{
snr_check^=pi->MfData[i];
}
if(snr_check!=pi->MfData[i])
{
status=MI_SERNRERR;
}
else
{
for(i=0;i<4;i++)
{
*(snr+i)=pi->MfData[i];
}
}
}
ClearBitMask(RegDecoderControl,0x20);
*/
|