標(biāo)題:
MF RC522測(cè)試程序與電路原理圖資料
[打印本頁(yè)]
作者:
qxl
時(shí)間:
2018-5-12 12:29
標(biāo)題:
MF RC522測(cè)試程序與電路原理圖資料
電路原理圖如下:
0.png
(62.5 KB, 下載次數(shù): 79)
下載附件
2018-5-13 00:13 上傳
0.jpg
(27.47 KB, 下載次數(shù): 68)
下載附件
2018-5-13 00:13 上傳
單片機(jī)源程序如下:
/**********************RC522實(shí)驗(yàn)開(kāi)發(fā)板例程************************
* CPU:STC89C52RC
* 晶振:11.0592MHZ
******************************************************************/
//實(shí)驗(yàn)?zāi)康模?br />
/*-----------------------------------------------
名稱(chēng):MF RC522
內(nèi)容:通過(guò)標(biāo)準(zhǔn)程序靜態(tài)顯示字符
引腳定義如下:
sbit MF522_NSS = P1^7; //SDA
sbit MF522_SCK = P1^6;
sbit MF522_SI = P1^5;
sbit MF522_SO = P1^4;
sbit MF522_RST = P1^3;
//蜂鳴器OR指示燈
sbit LED_GREEN = P2^3;
------------------------------------------------*/
#include "lpcreg.h"
#include "main.h"
#include "mfrc522.h"
#include <STDIO.H>
#include <string.h>
unsigned char code data1[16] = {0x12,0x34,0x56,0x78,0xED,0xCB,0xA9,0x87,0x12,0x34,0x56,0x78,0x01,0xFE,0x01,0xFE};
//M1卡的某一塊寫(xiě)為如下格式,則該塊為錢(qián)包,可接收扣款和充值命令
//4字節(jié)金額(低字節(jié)在前)+4字節(jié)金額取反+4字節(jié)金額+1字節(jié)塊地址+1字節(jié)塊地址取反+1字節(jié)塊地址+1字節(jié)塊地址取反
unsigned char code data2[4] = {0,0,0,0x01};
unsigned char code DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char g_ucTempbuf[20];
void delay1(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main( )
{
unsigned char status,i;
unsigned int temp;
InitializeSystem( );
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
while ( 1 )
{
status = PcdRequest(PICC_REQALL, g_ucTempbuf);//尋卡
if (status != MI_OK)
{
InitializeSystem( );
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
continue;
}
printf("卡的類(lèi)型:");
for(i=0;i<2;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
status = PcdAnticoll(g_ucTempbuf);//防沖撞
if (status != MI_OK)
{ continue; }
////////以下為超級(jí)終端打印出的內(nèi)容////////////////////////
printf("卡序列號(hào):"); //超級(jí)終端顯示,
for(i=0;i<4;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
///////////////////////////////////////////////////////////
status = PcdSelect(g_ucTempbuf);//選定卡片
if (status != MI_OK)
{ continue; }
status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);//驗(yàn)證卡片密碼
if (status != MI_OK)
{ continue; }
status = PcdWrite(1, data1);//寫(xiě)塊
if (status != MI_OK)
{ continue; }
while(1)
{
status = PcdRequest(PICC_REQALL, g_ucTempbuf);//尋卡
if (status != MI_OK)
{
InitializeSystem( );
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
continue;
}
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);//驗(yàn)證卡片密碼
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; }
printf("卡讀塊:"); //超級(jí)終端顯示,
for(i=0;i<16;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
printf("\n");
LED_GREEN = 0;
delay1(100);
LED_GREEN = 1;
delay1(100);
LED_GREEN = 0;
delay1(200);
LED_GREEN = 1;
PcdHalt();
}
}
}
/////////////////////////////////////////////////////////////////////
//系統(tǒng)初始化
/////////////////////////////////////////////////////////////////////
void InitializeSystem()
{
P0M1 = 0x0; P0M2 = 0x0;
P1M1 = 0x0; P1M2 = 0x0;
P3M1 = 0x0; P3M2 = 0xFF;
P0 = 0xFF; P1 = 0xFF; P3 = 0xFF;P2 = 0xFF;
TMOD=0x21; //設(shè)T0為方式1,GATE=1;
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
MFRC522測(cè)試程序_20140411173219.rar
(104.75 KB, 下載次數(shù): 65)
2018-5-12 12:27 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
weitongguo
時(shí)間:
2021-1-17 15:35
資料已下載,謝謝分享!
作者:
huaqiang766
時(shí)間:
2021-1-20 00:19
謝謝分享,好資料
作者:
tarchen
時(shí)間:
2024-10-1 09:21
謝謝分享,有空看看了.
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1