新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > NRF9E51讀IC卡卡號,并把讀取到的數(shù)據(jù)傳送出去

NRF9E51讀IC卡卡號,并把讀取到的數(shù)據(jù)傳送出去

作者: 時間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
/*================================================================================================
發(fā)送時間間隔是1.2秒
指示燈:接收燈上電后變紅,收到數(shù)據(jù)后變綠,在3秒內(nèi)未接收到數(shù)據(jù)則變紅
發(fā)送燈上電后變紅,發(fā)送數(shù)據(jù)變綠
*==================================================================================================*/
// 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個字節(jié)卡號無卡號的校驗和
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的個數(shù)是奇數(shù)
{ 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的個數(shù)是偶數(shù)
{
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);
}
}
上一頁 1 2 下一頁

關(guān)鍵詞: NRF9E51IC卡卡

評論


技術(shù)專區(qū)

關(guān)閉