您的位置 首页 设计

NRF9E51读IC卡卡号,并把读取到的数据传送出去

*================================================================================================发送时

/*================================================================================================

发送时刻距离是1.2秒
指示灯:接纳灯上电后变红,收到数据后变绿,在3秒内未接纳到数据则变红
发送灯上电后变红,发送数据变绿
*==================================================================================================*/
// Comment out the following line for nRF24E1
//#define NRF9E5 1
//卡号是916d47
#ifdef NRF9E5
#include
#define POWER 3 // 0=min power…3 = max power
#define HFREQ 1 // 0=433MHz, 1=868/915MHz
#define CHANNEL 351 // Channel number: f(MHz) = (422.4+CHANNEL/10)*(1+HFREQ)
#else
#include
//#include
//#include
#include
//#include
//#include
#endif
#define uchar unsigned char
#define uint unsigned int
#define nop() _nop_()
sbit LED=P0^5;
sbit data0=P0^4;
sbit data1=P0^3;
sbit fsen=P1^0;
//static volatile uchar timer;
static volatile uchar t0lrel, t0hrel;
static volatile uchar t1lrel, t1hrel;
uchar a[3];
uchar ou_check=0;
uchar ji_check=0;
uchar count=0;
uchar count1=0;
uint count0=0;
bit over_flag=0;
bit over1_flag=0;
//bit over2_flag=0;
uchar code array[3]={0x91,0x6d,0x47};
#ifndef NRF9E5
struct RFConfig
{
unsigned char n;
unsigned char buf[15];
};
typedef struct RFConfig RFConfig;
#define ADDR_INDEX 8 // Index to address bytes in RFConfig.buf
#define ADDR_COUNT 4 // Number of address bytes
//暂时3个字节卡号无卡号的校验和
const RFConfig tconf =
{
15,
0x18, // Payload size transmitter Rx #2 (not used in this example)
0x18, // Payload size transmitter Rx #1 (not used in this example)
0x00, 0x00, 0x00, 0x00, 0x00, // Address of transmitter Rx #2 (not used in this example)
0x00, 0x12, 0x34, 0x56, 0x78, // Address of transmitter Rx #1 (not used in this example)
0x81, 0x6f, 0x04
};
const RFConfig rconf =
{
15,
0x18, // Payload size receiver Rx #2 (not used in this example)
0x18, // Payload size receiver Rx #1
0x00, 0x00, 0x00, 0x00, 0x00, // Address receiver Rx #2 (not used in this example)
0x00, 0x12, 0x34, 0x56, 0x78, // Address receiver Rx #1 (four lower bytes used here)
0x81, 0x6f, 0x05
};
#endif
void Delay100us(volatile unsigned char n)
{
unsigned char i;
while(n–)
for(i=0;i<35;i++)
;
}
void fs()
{ uchar i;
uchar j;
uchar k;
uchar ou_check=0;
uchar ji_check=0;
for(i=0;i<8;i++)
ou_check+=((a[0]>>i)&0x01);
for(i=4;i<8;i++)
ou_check+=((a[1]>>i)&0x01);
if(ou_check&0x01)
ou_check=1;
else
ou_check=0;
for(i=0;i<4;i++)
ji_check+=((a[1]>>i)&0x01);
for(i=0;i<8;i++)
ji_check+=((a[2]>>i)&0x01);
if(ji_check&0x01)
ji_check=0;
else
ji_check=1;
if(ou_check) //1的个数是奇数
{ data1=0;
count1=0;
over1_flag=0;
TR2=1;
while(!over1_flag)
{ nop();
}
//Delay100us(1);
//data1=1;
//Delay100us(10);
}
else
{ data0=0;
count1=0;
over1_flag=0;
TR2=1;
while(!over1_flag)
{ nop();
}
//Delay100us(1);
//data0=1;
//Delay100us(10);
}
for(i=0;i<3;i++)
{ for(j=8;j>0;j–)
{ k=j-1;
k=(a[i]>>k)&0x01;
if(k)
{ data1=0;
over1_flag=0;
count1=0;
TR2=1;
while(!over1_flag)
{;}
//Delay100us(1);
//data1=1;
//Delay100us(10);
}
else
{ data0=0;
count1=0;
over1_flag=0;
TR2=1;
while(!over1_flag)
{;}
// Delay100us(1);
//data0=1;
//Delay100us(10);
}
}
}
if(ji_check) //1的个数是偶数
{
data1=0;
count1=0;
over1_flag=0;
TR2=1;
while(!over1_flag)
{;}
//Delay100us(1);
// data1=1;
//Delay100us(10);
}
else
{ data0=0;
count1=0;
over1_flag=0;
TR2=1;
while(!over1_flag)
{;}
//Delay100us(1);
//data0=1;
//Delay100us(10);
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/sheji/318663.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部