锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

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

时间:2024-05-16 09:07:10

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

发送时间间隔是1.2秒 指示灯:接收灯上电后变红,收到数据后变绿,在3秒内未接收到数据则变红 发送灯上电后变红,发送数据变绿 *==================================================================================================*/ // Comment out the following line for nRF24E1 //#define NRF9E5 1 //卡号是916d47 #ifdef NRF9E5 #include < \reg9e5.h> #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 A _INDEX 8 // Index to address bytes in RFConfig.buf #define ADDR_COU 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); } } /*void rst_wdog() { if((REGX_ L&0x10)!=0x10) { REGX_MSB=0x75; REGX_LSB=0x30; // REGX_CTRL=0x08; } }*/ unsigned char SpiReadWrite(unsigned char b) { EXIF &= ~0x20; // Clear I interrupt SPI_DATA = b; // Move byte to send to SPI data register while((EXIF & 0x20) == 0x00) // Wait until SPI hs finished transmitting ; return SPI_DATA; } void TransmitPacket() { unsigned char i; CE = 1; Delay100us(0); // All packets start with the receiver address: for(i=0;i 3ms InitTimer(); EA = 1; for(j=0;j<2;j++) { LED=1; for(i=0;i<10;i++) { Delay100us(250); Delay100us(250); } LED=0; for(i=0;i<10;i++) { Delay100us(250); Delay100us(250); } } } void main(void) { Init(); /*f((REGX_CTRL&0x10)!=0x10) { REGX_MSB=0x75; REGX_LSB=0x30; REGX_CTRL=0x08; } */ //Receiver(); Transmitter(); }
-电子元器件采购网(www.ruidan.com)是本土元器件目录分销商,采用“小批量、现货、样品”销售模式,致力于满足客户多型号、高质量、快速交付的采购需求。 自建高效智能仓储,拥有自营库存超过50,000种,提供一站式正品现货采购、个性化解决方案、选型替代等多元化服务。
锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章