?? trf7960.c
字號:
#include "main.h"
void STARTcondition(void)
{
TRFWrite = 0x00;
clkON;
TRFWrite = 0xff;
clkOFF;
} /* STARTcondition */
void STOPcondition(void)
{
TRFWrite |= 0x80; /* stop condition */
clkON;
TRFWrite = 0x00;
clkOFF;
}
void STOPcont(void)
{ /* stop condition for continous mode */
TRFWrite = 0x00;
TRFDirOUT;
TRFWrite = 0x80;
__no_operation();
TRFWrite = 0x00;
} /* STOPcond */
//---------------initialize TRF796X-----------------------------
void InitialTRF7960(void)
{
TurnOnRF();
//add code
command[0] = 0x0b;
command[1] = 0xe7;
WriteSingle(command, 2);
//end add code
command[0] = ISOControl; // set register 0x01 for ISO15693 operation
command[1] = 0x02;
WriteSingle(command, 2);
command[0] = ModulatorControl;
command[1] = 0x60;
WriteSingle(command, 2);
}
//---------------write the register of TRF796X------------------
void WriteSingle(unsigned char *pbuf, unsigned char length)
{
int i;
STARTcondition();
while(length > 0)
{
*pbuf = (0x1f &*pbuf); /* register address */
/* address, write, single */
for(i = 0; i < 2; i++)
{
TRFWrite = *pbuf; /* send command and data */
clkON;
clkOFF;
pbuf++;
length--;
}
} /* while */
STOPcondition();
}
//--------------read the register of TRF796X-------------------
void ReadSingle(unsigned char *pbuf, unsigned char lenght)
{
STARTcondition();
while(lenght > 0)
{
*pbuf = (0x40 | *pbuf); /* address, read, single */
*pbuf = (0x5f &*pbuf); /* register address */
TRFWrite = *pbuf; /* send command */
clkON;
clkOFF;
TRFDirIN; /* read register */
clkON;
__no_operation();
*pbuf = TRFRead;
clkOFF;
TRFWrite = 0x00;
TRFDirOUT;
pbuf++;
lenght--;
}
STOPcondition();
}
//--------------read multiple registers-----------------------
void ReadCont(unsigned char *pbuf, unsigned char lenght)
{
STARTcondition();
*pbuf = (0x60 | *pbuf); /* address, read, continous */
*pbuf = (0x7f &*pbuf); /* register address */
TRFWrite = *pbuf; /* send command */
clkON;
clkOFF;
TRFDirIN; /* read register */
while(lenght > 0)
{
clkON;
__no_operation();
*pbuf = TRFRead;
clkOFF;
pbuf++;
lenght--;
} /* while */
STOPcont();
}
//-------------send direct command to TRF796X----------------
void DirectCommand(unsigned char *pbuf)
{
STARTcondition();
*pbuf = (0x80 | *pbuf); /* command */
*pbuf = (0x9f &*pbuf); /* command code */
TRFWrite = *pbuf; /* send command */
clkON;
clkOFF;
STOPcondition();
}
//-------------Inventory-----------------------
void InventoryRequest(unsigned char *mask, unsigned char length)
{
int size = 3;
int k;
unsigned char flags = 0x02;
unsigned char com_buf[8];
com_buf[0] = ModulatorControl;
//com_buf[1] = 0x31;
com_buf[1] = 0x31;
WriteSingle(com_buf, 2);
com_buf[0] = Command(Reset);
com_buf[1] = Command(TransmitCRC); /* send with CRC */
com_buf[2] = 0x3d; /* write continous from 1D */
com_buf[3] = (char) (size >> 8);
com_buf[4] = (char) (size << 4);
com_buf[5] = flags; /* ISO15693 flags */
com_buf[6] = 0x20; /* anticollision command code */
com_buf[7] = 0x01;
while(1)
{
IrqReset();
irqCLR; /* PORT2 interrupt flag clear */
irqON;
RAWwrite(&com_buf[0], 8); /* writing to FIFO */
i_reg = 0x01;
while(i_reg != 0xFF)
{
k++;
if(k == 0xc000)
{
i_reg = 0x00;
RXErrorFlag = 0x00;
RXTXstate = 0;
LED_OFF;
buf[1] = 0x00;
command[0] = Reset; /* FIFO has to be reset before recieving the next response */
DirectCommand(command);
break;
}
}
if(i_reg == 0xff)
{
DisableInterrupts;
RXTXstate = 0;
Put_byte(buf[1] );
LED_ON;
EnableInterrupts;
}
command[0] = Reset; /* FIFO has to be reset before recieving the next response */
DirectCommand(command);
irqOFF;
}
}
//-------------write data to TRF796X's FIFO----------------------
void RAWwrite(unsigned char *pbuf, unsigned char lenght)
{
STARTcondition();
while(lenght > 0)
{
TRFWrite = *pbuf; /* send command */
clkON;
clkOFF;
pbuf++;
lenght--;
} /* while */
STOPcont();
}
//-------------set TRF7960's mode---------------------------------
void SetTRF(void)
{
unsigned char command[2];
command[0] = ModulatorControl;
command[1] = 0x60;
WriteSingle(command, 2);
}
//-------------reset the irq register-----------------------------
void IrqReset(void)
{
command[0] = IRQStatus;
command[1] = IRQMask;
ReadCont(command, 2);
}
//-------------turn on RF signal----------------------------------
void TurnOnRF(void)
{
command[0] = ChipStateControl; // turn on RF driver
//command[1] = 0x21;
command[1] = 0x29;
WriteSingle(command, 2);
}
//-------------turn off RF signal---------------------------------
void TurnOffRF(void)
{
command[0] = ChipStateControl; // turn off RF driver
command[1] = 0x01;
WriteSingle(command, 2);
}
//--------------generate the opcode--------------------------------
unsigned char Command(unsigned char command)
{
unsigned char Opcode;
Opcode = 0x80 | command;
Opcode = 0x9f & Opcode;
return Opcode;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -