标题: mfrc522门禁系统的单片机代码 [打印本页]

作者: 2275053010    时间: 2018-7-18 13:30
标题: mfrc522门禁系统的单片机代码
学校暑期课设用的代码,非常简单,网上也比较好找,给大家分享一下


单片机源程序如下:
  1. #include "lpcreg.h"
  2. #include "main.h"
  3. #include "mfrc522.h"

  4. unsigned char code data1[16] = {0x12,0x34,0x56,0x78,0xED,0xCB,0xA9,0x87,0x12,0x34,0x56,0x78,0x01,0xFE,0x01,0xFE};
  5. //M1卡的某一块写为如下格式,则该块为钱包,可接收扣款和充值命令
  6. //4字节金额(低字节在前)+4字节金额取反+4字节金额+1字节块地址+1字节块地址取反+1字节块地址+1字节块地址取反
  7. unsigned char code data2[4]  = {0x12,0,0,0};
  8. unsigned char code DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};


  9. unsigned char g_ucTempbuf[20];                        

  10. void main( )
  11. {   
  12.      unsigned char status;
  13.      InitializeSystem( );
  14.          LED_GREEN = 0;
  15. //    while(1){}
  16.      PcdReset();
  17.      PcdAntennaOff();
  18.      PcdAntennaOn();  
  19.               M500PcdConfigISOType( 'A' );
  20.      while ( 1 )
  21.      {   
  22.    //    PcdAntennaOff();
  23.         //    status = 23 ;
  24.          status = PcdRequest(PICC_REQALL, g_ucTempbuf);
  25.          if (status != MI_OK)
  26.          {   
  27.                       LED_GREEN = 1; //!LED_GREEN;
  28.                           continue;
  29.          }
  30.          LED_GREEN = 0;
  31.          
  32.          status = PcdAnticoll(g_ucTempbuf);
  33.          if (status != MI_OK)
  34.          {    continue;    }
  35.          
  36.          status = PcdSelect(g_ucTempbuf);
  37.          if (status != MI_OK)
  38.          {    continue;    }
  39.          
  40.          status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);
  41.          if (status != MI_OK)
  42.          {    continue;    }
  43.          
  44.          status = PcdWrite(1, data1);
  45.          if (status != MI_OK)
  46.          {    continue;    }
  47.          
  48.          status = PcdValue(PICC_DECREMENT,1,data2);
  49.          if (status != MI_OK)
  50.          {    continue;    }
  51.          
  52.          status = PcdBakValue(1, 2);
  53.          if (status != MI_OK)
  54.          {    continue;    }
  55.          
  56.          status = PcdRead(2, g_ucTempbuf);
  57.          if (status != MI_OK)
  58.          {    continue;    }
  59.          
  60.                  PcdHalt();
  61.   //            PcdAntennaOff();

  62.     }
  63. }


  64. /////////////////////////////////////////////////////////////////////
  65. //系统初始化
  66. /////////////////////////////////////////////////////////////////////
  67. void InitializeSystem()
  68. {
  69.     P0M1 = 0x0; P0M2 = 0x0;
  70.     P1M1 = 0x0;        P1M2 = 0x0;                     
  71.     P3M1 = 0x0; P3M2 = 0xFF;
  72.     P0 = 0xFF; P1 = 0xFF; P3 = 0xFF;
  73. }

  74. /////////////////////////////////////////////////////////////////////
  75. //用T2做延时子程序
  76. /////////////////////////////////////////////////////////////////////
  77. void DelayMs(unsigned int _MS)
  78. {
  79.     TH1 = (unsigned char)(RCAP2_1ms>>8);
  80.     TL1 = (unsigned char)(RCAP2_1ms);

  81.     ET1     = 0;                                            // Disable timer2 interrupt
  82.     TR1     = 1;
  83.     while (_MS--)
  84. ……………………

  85. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
程序电路.zip (13.26 MB, 下载次数: 80)



作者: sk5201314    时间: 2018-12-27 10:45
学习一下
作者: yaole1314    时间: 2019-5-19 19:44
大神 求教我最近也在研究这个




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1