欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: RC522的讀寫卡程序,可以讀寫1~16扇區(qū)的任意數(shù)據(jù)塊 [打印本頁]

作者: wzw199610    時(shí)間: 2018-8-8 15:58
標(biāo)題: RC522的讀寫卡程序,可以讀寫1~16扇區(qū)的任意數(shù)據(jù)塊
//讀寫扇區(qū)的例子:
#include <SPI.h>
#include <RFID.h>

RFID rfid(53,49);    //D10--讀卡器MOSI引腳、D5--讀卡器RST引腳

//4字節(jié)卡序列號(hào),第5字節(jié)為校驗(yàn)字節(jié)
unsigned char serNum[5];
//寫卡數(shù)據(jù),3為數(shù)據(jù)塊012,16為長度
unsigned char writeDate[3][16] ={
{'1', '2', '3', '4', '-', '5', '6', '7', '8', '9', 'a', 'b', 'c','d', 'e', 0},
{'1', '1', '3', '4', '-', '5', '6', '7', '8', '9', 'a', 'b', 'c','d', 'e', 0},
{'1', '1', '1', '4', '-', '5', '6', '7', '8', '9', 'a', 'b', 'c','d', 'e', 0},
};
//原扇區(qū)A密碼,16個(gè)扇區(qū),每個(gè)扇區(qū)密碼6Byte
unsigned char sectorKeyA[16][16] = {
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},//0~16扇區(qū)原密碼
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},


        };
//新扇區(qū)A密碼,16個(gè)扇區(qū),每個(gè)扇區(qū)密碼6Byte,一行代表一個(gè)扇區(qū)
//改密碼只要改前面6個(gè)ff任意一個(gè), 0xff,0x07,0x80,0x69, 千萬不能動(dòng)否則可能報(bào)廢扇區(qū)
unsigned char sectorNewKeyA[16][16] = {
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},//1-16扇區(qū)新密碼
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},



        };
//char aa[16];
void setup()
{
  Serial.begin(9600);
  SPI.begin();
  rfid.init();
}

void loop()
{
  //unsigned char i,tmp;//i為數(shù)據(jù)塊號(hào)0.1.2
  unsigned tmp;
  unsigned char status;
  unsigned char str[MAX_LEN];
// unsigned char RC_size;
  unsigned char blockAddr;        //選擇操作的塊地址0~63。但只能寫4的倍數(shù)+3;比如7,11,15,19---

  //找卡
  rfid.isCard();

  //讀取卡序列號(hào)
  if (rfid.readCardSerial())
  {
    Serial.print("The card's number is  : ");
    Serial.print(rfid.serNum[0],HEX);
    Serial.print(rfid.serNum[1],HEX);
    Serial.print(rfid.serNum[2],HEX);
    Serial.print(rfid.serNum[3],HEX);
    Serial.print(rfid.serNum[4],HEX);
    Serial.println(" ");
  }

  //選卡,返回卡容量(鎖定卡片,防止多次讀寫)
rfid.selectTag(rfid.serNum);



  //寫數(shù)據(jù)卡
//  for(int i=0;i<3;i++)//循環(huán)寫入數(shù)據(jù)塊012,不循環(huán)就單獨(dú)寫i值
//    {
//  blockAddr = 15;                //扇區(qū)3,控制塊3
//  if (rfid.auth(PICC_AUTHENT1A, blockAddr, sectorKeyA[ blockAddr/4], rfid.serNum) == MI_OK)  //認(rèn)證
//  {
////    寫密碼
//    status = rfid.write(blockAddr, sectorNewKeyA[blockAddr/4]);   
//    //寫數(shù)據(jù)
//   
//    blockAddr = blockAddr - 3+i; //數(shù)據(jù)塊i
//    tmp=(blockAddr+3-i)/4;
//    status = rfid.write(blockAddr, writeDate[i]);
//    if(status == MI_OK)
//    {
//      
//      Serial.print("扇區(qū):");
//      Serial.print(tmp,DEC);
//      Serial.print("數(shù)據(jù)塊:");
//      Serial.println(i);
//      Serial.println("Write card OK!");
//    }
//  }
//    }




  //讀卡
  for(int i=2;i<3;i++)
    {
  blockAddr = 15;                ////扇區(qū)3,控制塊3
  status = rfid.auth(PICC_AUTHENT1A, blockAddr, sectorNewKeyA[blockAddr/4], rfid.serNum);
  if (status == MI_OK)  //認(rèn)證
  {
    //讀數(shù)據(jù)
    blockAddr = blockAddr - 3+i;
    if( rfid.read(blockAddr, str) == MI_OK)
    {
      Serial.print("Read from the card ,the data is : ");
      Serial.println((char *)str);
    Serial.print("扇區(qū):");
    Serial.print(blockAddr/4,DEC);
    Serial.print("數(shù)據(jù)塊:");
    Serial.println(i);
    }
    }
  }


  rfid.halt();//去掉本行連續(xù)讀寫

}



//驗(yàn)證密碼+數(shù)據(jù)后,再對(duì)arduino設(shè)定的sj進(jìn)行減5操作
#include <SPI.h>
#include <RFID.h>

RFID rfid(53,49);    //D10--讀卡器MOSI引腳、D5--讀卡器RST引腳

//4字節(jié)卡序列號(hào),第5字節(jié)為校驗(yàn)字節(jié)
unsigned char serNum[5];
//寫卡數(shù)據(jù)
unsigned char writeDate[16]={'1', '2', '3', '4', '-', '5', '6', '7', '8', '9', 'a', 'b', 'c','d', 0, 0};
unsigned char aa[16]=        {'1', '2', '3', '4', '-', '5', '6', '7', '8', '9', 'a', 'b', 'c','d', 0, 0};
char dy;
unsigned int sj=1000;
//原扇區(qū)A密碼,16個(gè)扇區(qū),每個(gè)扇區(qū)密碼6Byte
unsigned char sectorKeyA[16][16] = {
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},

// {0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
// {0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
// {0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
        };
//新扇區(qū)A密碼,16個(gè)扇區(qū),每個(gè)扇區(qū)密碼6Byte
//改密碼只要改第3行前面6個(gè)ff任意一個(gè), 0xff,0x07,0x80,0x69, 千萬不能動(dòng)負(fù)責(zé)報(bào)廢扇區(qū)
unsigned char sectorNewKeyA[16][16] = {
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},//讀改密碼只要改前面6個(gè)ff任意一個(gè)
        {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},//寫改密碼只要改前面6個(gè)ff任意一個(gè)
        };

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  rfid.init();
}

void loop()
{
  unsigned char i,tmp;
  unsigned char status;
  unsigned char str[MAX_LEN];
  unsigned char RC_size;
  unsigned char blockAddr;        //選擇操作的塊地址0~63

  //找卡
  rfid.isCard();
  //讀取卡序列號(hào)
  if (rfid.readCardSerial())
  {
    Serial.print("The card's number is  : ");
    Serial.print(rfid.serNum[0],HEX);
    Serial.print(rfid.serNum[1],HEX);
    Serial.print(rfid.serNum[2],HEX);
    Serial.print(rfid.serNum[3],HEX);
    Serial.print(rfid.serNum[4],HEX);
    Serial.println(" ");
  }

  //選卡,返回卡容量(鎖定卡片,防止多次讀寫)
  rfid.selectTag(rfid.serNum);

  //寫數(shù)據(jù)卡
  blockAddr = 7;                //數(shù)據(jù)塊7//報(bào)廢扇區(qū)2,1,16
  if (rfid.auth(PICC_AUTHENT1A, blockAddr, sectorKeyA[ blockAddr/4], rfid.serNum) == MI_OK)  //認(rèn)證
  {
//    寫數(shù)據(jù)
    status = rfid.write(blockAddr, sectorNewKeyA[blockAddr/4]);
    Serial.print("set the new card password, and can modify the data of the Sector: ");
    Serial.println(blockAddr/4,DEC);
    //寫數(shù)據(jù)
    blockAddr = blockAddr - 3 ; //數(shù)據(jù)塊4
    status = rfid.write(blockAddr, writeDate);
    if(status == MI_OK)
    {
      Serial.println("Write card OK!");
    }
  }

  //讀卡
  blockAddr = 7;               
  status = rfid.auth(PICC_AUTHENT1A, blockAddr, sectorNewKeyA[blockAddr/4], rfid.serNum);
  if (status == MI_OK)  //認(rèn)證
  {
    //讀數(shù)據(jù)
    blockAddr = blockAddr - 3 ;
    if( rfid.read(blockAddr, str) == MI_OK)
    {
      Serial.print("Read from the card ,the data is : ");
      Serial.println((char *)str);
for(int a=0;a<15;a++)
{
  dy=1;
  if(aa[a]!=str[a])
  {
dy=0;
break;

  }
}
if(dy==1)
{
  sj-=5;
  Serial.println(sj);
}
    }
  }


  rfid.halt();
}
















RFID.zip

9.02 KB, 下載次數(shù): 146, 下載積分: 黑幣 -5


作者: rainbowyu    時(shí)間: 2018-9-5 16:28
怎么那個(gè)庫函數(shù)一直添加不了

作者: 春風(fēng)電子    時(shí)間: 2019-12-13 15:37
好資料
作者: 水煮涼白開    時(shí)間: 2021-4-5 22:28
是stc89c52能用的嗎
作者: 白色暴躁    時(shí)間: 2021-4-26 21:37
水煮涼白開 發(fā)表于 2021-4-5 22:28
是stc89c52能用的嗎

兄弟,我也想知道這是用什么板子控制的,你知道了能否也告訴一下我啊,非常感謝!

作者: qzyhlf    時(shí)間: 2021-6-17 15:48

是stc89c52能用的嗎
作者: dzc3458    時(shí)間: 2021-9-11 09:54
水煮涼白開 發(fā)表于 2021-4-5 22:28
是stc89c52能用的嗎

不可以,語言不一樣
作者: LPB2021    時(shí)間: 2021-9-16 09:33
RC522初始化語句太多了,有沒有辦法減小點(diǎn),減少休眠喚醒時(shí)間
作者: csmyldl    時(shí)間: 2021-9-16 11:30
單片機(jī)不能直接用,加一個(gè)使用環(huán)境說明就好了
作者: dzc3458    時(shí)間: 2021-10-27 08:32
水煮涼白開 發(fā)表于 2021-4-5 22:28
是stc89c52能用的嗎

不能直接用,雖然和c51很像,但很多地方都不一樣,比如入口函數(shù),定時(shí)器,函數(shù)名
作者: dzc3458    時(shí)間: 2021-12-13 00:29
白色暴躁 發(fā)表于 2021-4-26 21:37
兄弟,我也想知道這是用什么板子控制的,你知道了能否也告訴一下我啊,非常感謝!

arduino的都能控制,我用的是Arduino Nano v3,自己寫了個(gè)讀卡號(hào)和計(jì)算水卡密碼的,現(xiàn)在差了個(gè)把數(shù)據(jù)寫進(jìn)去 。不過我看他們都是用UNO




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1