📄 14443.c
字号:
for(i = 1; i < 5; i++) newUID[i - 1] = buf[i];
CounterSet();
countValue = 100; /* 1.2ms for TIMEOUT */
startCounter; /* start timer up mode */
i_reg = 0x01;
while(i_reg == 0x01)
{
} /* wait for end of RX or timeout */
AnticollisionLoopA(select, CollPoss, newUID); /* recursive call for anticollision procedure */
} /* if */
if(more)
{ /* perform anticollison command for 7 or 10 - byte UID - recursive call for cascade levels */
AnticollisionLoopA(select, NVB, UID); /* only the select field is different, everything else is the same */
if(POLLING) found = 1;
} /* if */
if(found)
{
LEDtypeAON;
}
else
{
LEDtypeAOFF;
}
} /* AnticollisionLoopA */
/*
=======================================================================================================================
=======================================================================================================================
*/
void AnticollisionSequenceA(unsigned char REQA)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
unsigned char i, select = 0x93, NVB = 0x20;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
buf[0] = ISOControl;
buf[1] = 0x88; /* recieve with no CRC */
WriteSingle(buf, 2);
/*
* delay_ms(5);
*/
if(REQA) buf[5] = 0x26; /* send REQA command */
else
buf[5] = 0x52; /* send WUPA command */
RequestCommand(&buf[0], 0x00, 0x0f, 1);
irqCLR; /* PORT2 interrupt flag clear */
irqON;
/*
* UIDsize = ((buf[2] >> 6) & 0x03) + 1;
*/
if(i_reg == 0xff || i_reg == 0x02)
{
for(i = 40; i < 45; i++) buf[i] = 0x00;
AnticollisionLoopA(select, NVB, &buf[40]);
if(POLLING) LEDtypeAON;
}
else
{
LEDtypeAOFF;
}
buf[0] = ISOControl;
buf[1] = 0x08; /* recieve with no CRC */
WriteSingle(buf, 2);
irqOFF;
} /* AnticollisionSequenceA */
/*
=======================================================================================================================
=======================================================================================================================
*/
unsigned char Request14443A(unsigned char *pbuf, unsigned char lenght, unsigned char BitRate)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
unsigned char index, j, command, RXBitRate, TXBitRate, reg[2];
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
TXBitRate = ((BitRate >> 4) & 0x0F) + 0x08;
RXBitRate = (BitRate & 0x0F) + 0x08;
reg[0] = ISOControl;
reg[1] = TXBitRate;
WriteSingle(reg, 2);
RXTXstate = lenght; /* RXTXstate global wariable is the main transmit counter */
*pbuf = 0x8f;
*(pbuf + 1) = 0x91; /* buffer setup for FIFO writing */
*(pbuf + 2) = 0x3d;
*(pbuf + 3) = RXTXstate >> 4;
*(pbuf + 4) = RXTXstate << 4;
if(lenght > 12) lenght = 12;
RAWwrite(pbuf, lenght + 5); /* send the request using RAW writing */
/* Write 12 bytes the first time you write to FIFO */
irqCLR; /* PORT2 interrupt flag clear */
irqON;
RXTXstate = RXTXstate - 12;
index = 18;
i_reg = 0x01;
while(RXTXstate > 0)
{
LPM0; /* enter low power mode and exit on interrupt */
if(RXTXstate > 9)
{ /* the number of unsent bytes is in the RXTXstate global */
lenght = 10; /* count variable has to be 10 : 9 bytes for FIFO and 1 address */
}
else if(RXTXstate < 1)
{
break; /* return from interrupt if all bytes have been sent to FIFO */
}
else
{
lenght = RXTXstate + 1; /* all data has been sent out */
} /* if */
buf[index - 1] = FIFO; /* writes 9 or less bytes to FIFO for transmitting */
WriteCont(&buf[index - 1], lenght);
RXTXstate = RXTXstate - 9; /* write 9 bytes to FIFO */
index = index + 9;
} /* while */
RXTXstate = 1; /* the response will be stored in buf[1] upwards */
while(i_reg == 0x01)
{
}
reg[0] = ISOControl;
reg[1] = RXBitRate;
WriteSingle(reg, 2);
command = 0x16;
DirectCommand(&command);
command = 0x17;
DirectCommand(&command);
i_reg = 0x01;
CounterSet();
countValue = 0xF000; /* 60ms for TIMEOUT */
startCounter; /* start timer up mode */
while(i_reg == 0x01)
{
} /* wait for RX complete */
if(i_reg == 0xFF)
{ /* recieved response */
kputchar('[');
for(j = 1; j < RXTXstate; j++)
{
Put_byte(buf[j]);
} /* for */
kputchar(']');
return(0);
}
else if(i_reg == 0x02)
{ /* collision occured */
kputchar('[');
kputchar('z');
kputchar(']');
return(0);
}
else if(i_reg == 0x00)
{ /* timer interrupt */
kputchar('[');
kputchar(']');
return(1);
}
else
;
irqOFF;
return(1);
} /* Request14443A */
/*
=======================================================================================================================
Function sends the SlotMarker command for // ;
the 14443B protocol. This command includes // ;
the slot number. // ;
=======================================================================================================================
*/
void SlotMarkerCommand(unsigned char number)
{
buf[0] = 0x8f;
buf[1] = 0x91;
buf[2] = 0x3d;
buf[3] = 0x00;
buf[4] = 0x10;
buf[5] = (number << 4) | 0x05;
i_reg = 0x01;
RAWwrite(&buf[0], 6);
irqCLR; /* PORT2 interrupt flag clear */
irqON;
CounterSet(); /* TimerA set */
countValue = 0x4E20; /* 20ms */
startCounter;
while(i_reg == 0x01)
{
}
} /* SlotMarkerCommand */
/*
=======================================================================================================================
=======================================================================================================================
*/
void AnticollisionSequenceB(unsigned char command, unsigned char slots)
{
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
unsigned char i, collision = 0x00, j, found = 0;
unsigned int k = 0;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
RXErrorFlag = 0x00;
buf[0] = 0x8f;
buf[1] = 0x91;
buf[2] = 0x3d;
buf[3] = 0x00;
buf[4] = 0x30;
buf[5] = 0x05;
buf[6] = 0x00;
if(slots == 0x04)
{
EnableSlotCounter();
buf[7] |= 0x08;
}
buf[7] = slots;
if(command == 0xB1) buf[7] |= 0x08; /* WUPB command else REQB command */
i_reg = 0x01;
RAWwrite(&buf[0], 8);
irqCLR; /* PORT2 interrupt flag clear */
irqON;
j = 0;
while((i_reg == 0x01) && (j < 2))
{
j++;
CounterSet(); /* TimerA set */
countValue = 0x4E20; /* 20ms */
startCounter;
LPM0;
} /* wait for end of TX */
i_reg = 0x01;
CounterSet(); /* TimerA set */
countValue = 0x4E20; /* 20ms */
startCounter;
for(i = 1; i < 17; i++)
{
RXTXstate = 1; /* the response will be stored in buf[1] upwards */
while(i_reg == 0x01)
{ /* wait for RX complete */
k++;
if(k == 0xFFF0)
{
i_reg = 0x00;
RXErrorFlag = 0x00;
break;
}
}
if(RXErrorFlag == 0x02) i_reg = RXErrorFlag;
if(i_reg == 0xFF)
{ /* recieved SID in buffer */
if(POLLING)
{
found = 1;
}
else
{
kputchar('[');
for(j = 1; j < RXTXstate; j++) Put_byte(buf[j]);
kputchar(']');
}
}
else if(i_reg == 0x02)
{ /* collision occured */
if(!POLLING)
{
kputchar('[');
kputchar('z');
kputchar(']');
}
collision = 0x01;
}
else if(i_reg == 0x00)
{ /* slot timeout */
if(!POLLING)
{
kputchar('[');
kputchar(']');
}
}
else
;
if((slots == 0x00) || (slots == 0x01) || (slots == 0x02) || ((slots == 0x04) && (i == 16))) break;
SlotMarkerCommand(i);
i_reg = 0x01;
if(!POLLING)
{
put_crlf();
}
} /* for */
if(slots == 0x04) DisableSlotCounter();
irqOFF;
if(found)
{
LEDtypeBON;
}
else
{
LEDtypeBOFF;
}
if(collision != 0x00) AnticollisionSequenceB(0x20, 0x02); /* Call this function for 16 timeslots */
} /* AnticollisionSequenceB */
// === Modifications====================================================
// 10/30/06 Aarthi Lines 52, 685 - Added condition to check if program
// execution is in polling loop. This is needed to avoid
// communication to the USB-UART converter before the
// GUI is invoked.
// =====================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -