标题:
mfrc522门禁系统的单片机代码
[打印本页]
作者:
2275053010
时间:
2018-7-18 13:30
标题:
mfrc522门禁系统的单片机代码
学校暑期课设用的代码,非常简单,网上也比较好找,给大家分享一下
0.png
(42.63 KB, 下载次数: 22)
下载附件
2018-7-18 22:29 上传
单片机源程序如下:
#include "lpcreg.h"
#include "main.h"
#include "mfrc522.h"
unsigned char code data1[16] = {0x12,0x34,0x56,0x78,0xED,0xCB,0xA9,0x87,0x12,0x34,0x56,0x78,0x01,0xFE,0x01,0xFE};
//M1卡的某一块写为如下格式,则该块为钱包,可接收扣款和充值命令
//4字节金额(低字节在前)+4字节金额取反+4字节金额+1字节块地址+1字节块地址取反+1字节块地址+1字节块地址取反
unsigned char code data2[4] = {0x12,0,0,0};
unsigned char code DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char g_ucTempbuf[20];
void main( )
{
unsigned char status;
InitializeSystem( );
LED_GREEN = 0;
// while(1){}
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
M500PcdConfigISOType( 'A' );
while ( 1 )
{
// PcdAntennaOff();
// status = 23 ;
status = PcdRequest(PICC_REQALL, g_ucTempbuf);
if (status != MI_OK)
{
LED_GREEN = 1; //!LED_GREEN;
continue;
}
LED_GREEN = 0;
status = PcdAnticoll(g_ucTempbuf);
if (status != MI_OK)
{ continue; }
status = PcdSelect(g_ucTempbuf);
if (status != MI_OK)
{ continue; }
status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);
if (status != MI_OK)
{ continue; }
status = PcdWrite(1, data1);
if (status != MI_OK)
{ continue; }
status = PcdValue(PICC_DECREMENT,1,data2);
if (status != MI_OK)
{ continue; }
status = PcdBakValue(1, 2);
if (status != MI_OK)
{ continue; }
status = PcdRead(2, g_ucTempbuf);
if (status != MI_OK)
{ continue; }
PcdHalt();
// PcdAntennaOff();
}
}
/////////////////////////////////////////////////////////////////////
//系统初始化
/////////////////////////////////////////////////////////////////////
void InitializeSystem()
{
P0M1 = 0x0; P0M2 = 0x0;
P1M1 = 0x0; P1M2 = 0x0;
P3M1 = 0x0; P3M2 = 0xFF;
P0 = 0xFF; P1 = 0xFF; P3 = 0xFF;
}
/////////////////////////////////////////////////////////////////////
//用T2做延时子程序
/////////////////////////////////////////////////////////////////////
void DelayMs(unsigned int _MS)
{
TH1 = (unsigned char)(RCAP2_1ms>>8);
TL1 = (unsigned char)(RCAP2_1ms);
ET1 = 0; // Disable timer2 interrupt
TR1 = 1;
while (_MS--)
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
程序电路.zip
(13.26 MB, 下载次数: 80)
2018-7-18 13:28 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
sk5201314
时间:
2018-12-27 10:45
学习一下
作者:
yaole1314
时间:
2019-5-19 19:44
大神 求教我最近也在研究这个
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1