📄 comr6c.c
字号:
#include "crc16.h"
#include "typedef.h"
#include "time.h"
#include "baseclk.h"
#include "comr6c.h"
#include "intrins.h"
#include "ll.h"
void _sendfifocmd(void)
{
bit flag;
uchar Bytecnt,nrofBytes ,bitcnt,nbBit,ISOcmd;
uint i;
ISOcmd = ReflectBYTE(pcdata[5]);
pcdata[1] = pcdata[1]&0x07;
if (pcdata[2]==0x16)
nrofBytes = pcdata[0]-3-2; //last 2 bytes are for CRC.
else if (pcdata[2]==0x18)
{
nrofBytes = 1; // send only command nr
pcdata[1] = 0;
}
else
nrofBytes = pcdata[0]-3;
_startBit();
for(Bytecnt=0;Bytecnt<nrofBytes ;Bytecnt++)
{
if(Bytecnt<nrofBytes-1)
nbBit = 8;
else if(!pcdata[1])
nbBit = 8;
else
nbBit = pcdata[1];
for(bitcnt=0;bitcnt<nbBit;bitcnt++)
{
_setTimer(2);
while ((DOUT)&&(!TIMERINT)); //FIFO Management
clrTimer();
pcdata[Bytecnt+3] = pcdata[Bytecnt+3] << 1;
flag = CY;
_sendBit(flag);
}
if(Bytecnt == 0)
{
for(i=0;i<0x5FF;i++);
}
}
switch (ISOcmd)
{
case 0x21: case 0x22: case 0x24:
case 0x27: case 0x28: case 0x29: case 0x2A:
case 0xA2: case 0xA3: case 0xa4: case 0xa5:
{
_setTimer(2);
while((DOUT)&&(!TIMERINT)); _stopBit();
_clrTimer();
for(i=0;i<0xbff;i++); break;
}
}
}
void _gettagresponse(uchar responseaftercmd, char SID)
{
uchar Bytecnt,bitcnt, ASICRDY, TAGRDY, TAGDONE, bitval, temp;
bit b_col = 0;
b_collision = 0;
ASICRDY = 0; TAGRDY = 0;
while((DOUT)); _stopBit(); _nop_(); _nop_();
while((DOUT));
_trans1();
if (responseaftercmd) // wait for buffer to empty before cont.
{
TH0 = 0x63; TL0 = 0xc0; //12ms
_setTimer(TIME_OUT_ASICRDY); //wait for ERR-pulse
while ((!ERR)&&(!TIMERINT));
if (ERR)
{
while ((ERR)&&(!TIMERINT));
if (!ERR)
{ //err pulse (typ. 18us) detected
ASICRDY = 1;
TH0 = 0x63; TL0 = 0xc0; //12ms
_setTimer(TIME_OUT_TAGRDY);
}
}
}
else
{
ASICRDY=1;
TH0 = 0x63; TL0 = 0xc0; //12ms
_setTimer(TIME_OUT_TAGRDY);
}
if(ASICRDY)
{ // wait for tag to respond; wait for S2 signal.
while((!TAGRDY)&&(!TIMERINT))
{
if (_findS2())
{
TAGRDY=1;
TH0 = 0x63; TL0 = 0xc0; //12ms
_setTimer(TIME_OUT_READDATA);
}
}
}
if(TAGRDY)
{
TAGDONE=0;
bitcnt=0;
Bytecnt=3; //It's value is nr of bytes -1 (i.e. the value in [o])
temp= 0;
while ((!TAGDONE)&&(!TIMERINT))
{
bitval =_readbit();
switch (bitval)
{
case 0x02:
b_col = 1;
break;
case 0x03:
TAGDONE =1; //received ES2
pcdata[Bytecnt] = temp;
pcdata[0] = Bytecnt;
pcdata[1] = bitcnt;
if(chkCRC(pcdata+3,Bytecnt-3))
{
userCardOk = 1;
}
break;
case 0x04: //timeout
break;
default:
if (bitcnt==8) //start new byte
{
if(Bytecnt <100)
{
pcdata[Bytecnt] = temp;
temp=0;
bitcnt =0;
Bytecnt++;
}
}
bitcnt++;
temp = temp*2 + bitval;
break;
}
}
}
else if (SID) //no tag in slot, doesn't mean timeout
TIMERINT=0;//TIFR = TIFR|0x10; //reset TIMERINT
b_collision = b_col;
_trans2(); //uctrl becomes again master of clock
_clrTimer();
}
uchar rd_ConReg(void)
{
uchar j,bitval;
bit flag;
pcdata[2]=0;
_startBit();
pcdata[0] =4;
pcdata[1] =0;
pcdata[2] =0;
pcdata[3]=0x71; /* send command */
for(j=0;j<8;j++)
{
pcdata[3] = pcdata[3] << 1;
flag = CY;
_sendBit(flag);
}
for(j=0;j<8;j++) /*get regCfg*/
{
bitval = _rwbit(0);
pcdata[2] = pcdata[2]*2 + bitval;
}
_stopBit(); /*send ES1*/
pcdata[0] = 0x03;
pcdata[1] = 0x00;
return(pcdata[2]);
}
/*
void wr_Timereg(void)
{
pcdata[0] = 6;
pcdata[1] = 5;
pcdata[2] = 0;
pcdata[3] = 0x7B;
// pcdata[4] = 0xC3;
// pcdata[5] = 0x80;
pcdata[4] = 0xC1; //Time reg val
pcdata[5] = 0x80;
_command00();
}
////////////////////////////////////////////////////
void wr_ConReg(uchar temp)
{
pcdata[0] = 5;
pcdata[1] = 0;
pcdata[2] = 0;
pcdata[3] = 0x7D;
pcdata[4] = temp; //control Reg val
_command00();
}
*/
void switchon(void)
{
_startBit();
_sendBit(1);
_stopBit();
}
////////////////////////////////////////////////////
/*
void switchoff(void)
{
SCLOCK = 0; _nop_();
DIN = 0; _nop_();
SCLOCK = 1; _nop_();
DIN = 1; _nop_();
DIN = 0; _nop_();
SCLOCK = 0 ; _nop_();
}
*/
////////////////////////////////////////////////////
/*
void powerDown(void)
{
pcdata[0] = 4;
pcdata[1] = 0;
pcdata[2] = 0;
pcdata[3] = 0x7E;
_command00();
}
*/
////////////////////////////////////////////////////
/*
void powerUp(void)
{
uint i;
_startBit();
for(i=0;i<0x8ff;i++);
switchon();
}
*/
////////////////////////////////////////////////////
uchar _commandrd(void)
{
uchar i;
pcdata[1] = 0;
pcdata[2] = 0x00;
pcdata[3] = 0x30; /* 通讯参数设置:低数据率、FM调制*/
for(i= 4;i<pcdata[0];i++)
{
pcdata[i] = ReflectBYTE(pcdata[i]); /*数据倒序*/
}
_sendfifocmd();
_gettagresponse(1,0);
if (TIMERINT) { return(0); }
else { return(1); }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -