📄 rfcard.h
字号:
//******************************************************************************
#define CEon() P1OUT|=BIT2 //ce:p1.2
#define CEof() P1OUT&=0xfb //BIT3
#define CSon() P1OUT|=BIT0 //cs:p1.0
#define CSof() P1OUT&=0xfe //BIT0
#define CKon() P2OUT|=BIT4 //ck:p2.4
#define CKof() P2OUT&=0xef //BIT1
#define DAon() P2OUT|=BIT3 //din:p2.3
#define DAof() P2OUT&=0xf7 //BIT2
#define PWon() P1OUT|=BIT3 //pow:p1.3
#define PWof() P1OUT&=0xf7 //BIT4
//*****************************????******************************************
const unsigned char RFConfig[3]={0x07,0xf7,0x88};
//unsigned char CardNo[4]={0x55,0x99,0x00,0x0f};
unsigned char TXData[9]={0x10,0x10,0x00,0x00,0x01,0x01,0x55,0x55,0x99};
//__no_init unsigned char test[4] @ 0xFFD0;
//******************************************************************************
// Function prototypes
//******************************************************************************
void DELAY100US(unsigned int num); //长延时
void Dltime(unsigned int aum);
void InitnRF2402(void);
void TXDataPacket(void);
void runatmode1(void);
void runatmode3(void);
//******************************************************************************
//******************************************************************************
void DELAY100US(unsigned int num) //延时num*100US程序
{
do
{
Dltime(84); //168/F2101
}
while(--num);
}
void Dltime(unsigned int aum)
{
unsigned char d=aum;
do{
_NOP();
}while(--d);
}
//******************************************************************************
// ------2402????
//******************************************************************************
void TXDataPacket(void)
{
unsigned char tempi;
unsigned char ByteCnt;
unsigned char BitCnt;
unsigned char databit;
CSof(); //ChipCS=0;
CEon(); //ChipCE=1; ShockBurst mode
Dltime(10);
for (ByteCnt=0;ByteCnt<9;ByteCnt++)
{
tempi=TXData[ByteCnt];
for (BitCnt=0;BitCnt<8;BitCnt++)
{
databit=tempi&0x80;
if (databit==0x80) //Check if first bit is HIGH
DAon(); //Set Data high
else
DAof(); //Set Data low
tempi=tempi<<1; //Left Shift to get next bit
CKon();
_NOP();
CKof(); //generate a clock pulse
_NOP();
}
}
CEof(); //Disable CE (TX Starts!)--standby mode
}
//******************************************************************************
// ------2402设置程序
//******************************************************************************
void InitnRF2402(void)
{
unsigned char ByteCnt;
unsigned char BitCnt;
unsigned char databit;
unsigned char tempi;
PWon();
CEof();
CSon();
DELAY100US(10);
for (ByteCnt=0;ByteCnt<3;ByteCnt++)
{
tempi=RFConfig[ByteCnt];
for (BitCnt=0;BitCnt<8;BitCnt++)
{
databit=tempi&0x80;
if (databit==0x80) //Check if first bit is HIGH
DAon(); //Set Data high
else DAof(); //Set Data low
tempi=tempi<<1; //Left Shift to get next bit
CKon();
CKof(); //generate a clock pulse
}
}
CSof(); //Disable CS--standby mode
}
//******************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -