新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > NRF9E51讀IC卡卡號,并把讀取到的數據傳送出去

        NRF9E51讀IC卡卡號,并把讀取到的數據傳送出去

        作者: 時間:2016-11-30 來源:網絡 收藏
        /*================================================================================================
        發送時間間隔是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);
        }
        }
        上一頁 1 2 下一頁

        關鍵詞: NRF9E51IC卡卡

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 鲜城| 淮阳县| 太和县| 泽州县| 手游| 德州市| 民丰县| 教育| 静乐县| 彭泽县| 广州市| 仁化县| 乐昌市| 绥阳县| 万盛区| 阳春市| 商城县| 洪洞县| 白河县| 银川市| 都匀市| 宁国市| 元氏县| 正阳县| 建昌县| 嘉黎县| 七台河市| 疏附县| 宁津县| 丁青县| 辽宁省| 兰州市| 双鸭山市| 宜宾市| 霍城县| 无极县| 城市| 怀来县| 平遥县| 凤城市| 宁城县|