找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2467|回复: 2
收起左侧

mfrc522门禁系统的单片机代码

[复制链接]
ID:374007 发表于 2018-7-18 13:30 | 显示全部楼层 |阅读模式
学校暑期课设用的代码,非常简单,网上也比较好找,给大家分享一下
0.png

单片机源程序如下:
  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)
回复

使用道具 举报

ID:320444 发表于 2018-12-27 10:45 | 显示全部楼层
学习一下
回复

使用道具 举报

ID:542293 发表于 2019-5-19 19:44 | 显示全部楼层
大神 求教我最近也在研究这个
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表