标题:
关于M1卡的stm32源码与资料分享
[打印本页]
作者:
HelloPan111
时间:
2017-12-6 14:22
标题:
关于M1卡的stm32源码与资料分享
见附件
0.jpg
(35.57 KB, 下载次数: 58)
下载附件
2017-12-6 19:37 上传
单片机源程序如下:
#include "stm32f10x.h"
#include "bsp_SysTick.h"
#include "bsp_usart1.h"
#include "rc522_config.h"
#include "rc522_function.h"
#include <stdbool.h>
#include "bsp_lcd.h"
unsigned char DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char data[16] = {0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x01,0xFE,0x01,0xFE};
unsigned char data1[16] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
unsigned char money_ok[4]={0x00,0x00,0x01,0x00};
char cStr [ 30 ];
char cStr1 [ 30 ]={1,2,3,4,5,6,7,8,9};
u8 ucArray_ID [ 20 ]; //先后存放IC卡的类型和UID(IC卡序列号)
u8 ucStatusReturn; //返回状态
static u8 ucLineCount = 0;
static u8 ucLineCount1 = 0;
unsigned char status;
int Display(void){
printf ( "%s\r\n",cStr );
sprintf ( cStr, " %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X"//%02X%02X%02X%02X"
,ucArray_ID [ 0 ], ucArray_ID [ 1 ], ucArray_ID [ 2 ], ucArray_ID [ 3 ] , ucArray_ID [ 4 ]
,ucArray_ID [ 5 ], ucArray_ID [ 6 ], ucArray_ID [ 7 ], ucArray_ID [ 8 ] , ucArray_ID [ 9 ]
,ucArray_ID [ 10 ], ucArray_ID [ 11 ], ucArray_ID [ 12 ], ucArray_ID [ 13 ] , ucArray_ID [ 14 ]
,ucArray_ID [ 15 ]
//, ucArray_ID [ 16 ], ucArray_ID [ 17 ], ucArray_ID [ 18 ] , ucArray_ID [ 19 ]
);
if ( ucLineCount == 0 )
ILI9341_Clear ( 0, 0, 240, 271, macBACKGROUND);
ILI9341_DispString_EN ( 0, ucLineCount * 32, cStr, macBACKGROUND, macBLUE );
ucLineCount ++;
if ( ucLineCount == 8 ) ucLineCount = 0;
}
void IC_test ( void )
{
while(1){
ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID );//寻卡
if (ucStatusReturn != MI_OK){
continue;}
/******************************屏蔽******************************/
status = PcdAnticoll ( ucArray_ID );//防碰撞
// if (status != MI_OK){
// continue;}
status = PcdSelect(ucArray_ID);//选定卡片
// if (status != MI_OK){
// continue;}
status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, ucArray_ID);//验证卡片密码
// if (status != MI_OK){
// continue;}
// if(ucLineCount%2==1){
// status = PcdWrite(1, data1);//写块1,数据为1122
// if (status != MI_OK)
// { continue; }}
// else
// {
// status = PcdWrite(1, data);//写块1,数据为00FF,钱包模式
// if (status != MI_OK)
// { continue; }
// status = PcdWrite(2, data);//写块2,数据为00FF,钱包模式
// if (status != MI_OK)
// { continue; }
// status = PcdRead(1, ucArray_ID);//读块
// Display();
// status = PcdRead(2, ucArray_ID);//读块
// Display();
/******************************************************************************************************
printf ( "%s\r\n",cStr );
sprintf ( cStr, " %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X"//%02X%02X%02X%02X"
,ucArray_ID [ 0 ], ucArray_ID [ 1 ], ucArray_ID [ 2 ], ucArray_ID [ 3 ] , ucArray_ID [ 4 ]
,ucArray_ID [ 5 ], ucArray_ID [ 6 ], ucArray_ID [ 7 ], ucArray_ID [ 8 ] , ucArray_ID [ 9 ]
,ucArray_ID [ 10 ], ucArray_ID [ 11 ], ucArray_ID [ 12 ], ucArray_ID [ 13 ] , ucArray_ID [ 14 ]
,ucArray_ID [ 15 ]
//, ucArray_ID [ 16 ], ucArray_ID [ 17 ], ucArray_ID [ 18 ] , ucArray_ID [ 19 ]
);
if ( ucLineCount == 0 )
ILI9341_Clear ( 0, 0, 240, 271, macBACKGROUND);
ILI9341_DispString_EN ( 0, ucLineCount * 32, cStr, macBACKGROUND, macBLUE );
ucLineCount ++;
if ( ucLineCount == 6 ) ucLineCount = 0;
******************************************************************************************************/
status = PcdValue(PICC_INCREMENT,2,money_ok);//充值
// status = PcdValue(PICC_INCREMENT,1,money_ok);//充值
// status = PcdValue(PICC_DECREMENT,1,money_ok);//扣款
// if (status != MI_OK)
// { continue; }
// status = PcdRead(1, ucArray_ID);//读块1
// if (status != MI_OK)
// { continue; }
// Display();
status = PcdRead(2, ucArray_ID);//读块2
if (status != MI_OK)
{ continue; }
Display();
PcdHalt(); //休眠,无效,为自动寻卡模式;
}
}
/********************************************************
void IC_test ( void )
{
char cStr [ 30 ];
u8 ucArray_ID [ 4 ]; //先后存放IC卡的类型和UID(IC卡序列号)
u8 ucStatusReturn; //返回状态
static u8 ucLineCount = 0;
while ( 1 )
{
if ( ( ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ) ) != MI_OK ) //寻卡
ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ); //若失败再次寻卡
if ( ucStatusReturn == MI_OK )
{
if ( PcdAnticoll ( ucArray_ID ) == MI_OK ) //防冲撞(当有多张卡进入读写器操作范围时,防冲突机制会从其中选择一张进行操作)
{
sprintf ( cStr, "The Card ID is: %02X%02X%02X%02X", ucArray_ID [ 0 ], ucArray_ID [ 1 ], ucArray_ID [ 2 ], ucArray_ID [ 3 ] );
printf ( "%s\r\n",cStr );
if ( ucLineCount == 0 )
ILI9341_Clear ( 0, 0, 240, 271, macBACKGROUND);
ILI9341_DispString_EN ( 0, ucLineCount * 16, cStr, macBACKGROUND, macBLUE );
ucLineCount ++;
if ( ucLineCount == 17 ) ucLineCount = 0;
}
}
}
}
********************************************************/
void ELE_money ( void )
{
while(1){
ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID );//寻卡
if (ucStatusReturn != MI_OK){
continue;}
status = PcdAnticoll ( ucArray_ID );//防碰撞
if (status != MI_OK){
continue;}
status = PcdSelect(ucArray_ID);//选定卡片
if (status != MI_OK){
continue;}
status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, ucArray_ID);//验证卡片密码
if (status != MI_OK){
continue;}
if(ucLineCount%2==1){
status = PcdWrite(1, data1);//写块1,数据为1122
if (status != MI_OK)
{ continue; }}
else
{
status = PcdWrite(1, data);//写块1,数据为00FF,钱包模式
if (status != MI_OK)
{ continue; }
status = PcdWrite(2, data);//写块2,数据为00FF,钱包模式
if (status != MI_OK)
{ continue; }
status = PcdRead(1, ucArray_ID);//读块
Display();
status = PcdRead(2, ucArray_ID);//读块
Display();
}}
}
void IC_test1 ( void )
{
while ( 1 )
{
if ( ( ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ) ) != MI_OK ) //寻卡
ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ); //若失败再次寻卡
if ( ucStatusReturn == MI_OK )
{
if ( PcdAnticoll ( ucArray_ID ) == MI_OK ) //防冲撞(当有多张卡进入读写器操作范围时,防冲突机制会从其中选择一张进行操作)
{
if(PcdSelect(ucArray_ID)==MI_OK)
{
if(PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, ucArray_ID))
{
status = PcdValue(PICC_INCREMENT,2,money_ok);//充值
status = PcdValue(PICC_DECREMENT,1,money_ok);//扣款
if(PcdRead(1, ucArray_ID)==MI_OK)
{
Display();
}
if(PcdRead(2, ucArray_ID)==MI_OK)
{
Display();
}
}
}
}
}
}
}
/**
* @brief 主函数
* @param 无
* @retval 无
*/
int main ( void )
{
SysTick_Init (); //滴答时钟初始化
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
RFID.rar
(324.74 KB, 下载次数: 27)
2017-12-6 19:37 上传
点击文件名下载附件
程序
下载积分: 黑币 -5
M1卡介绍.pdf
(409.84 KB, 下载次数: 21)
2017-12-6 14:21 上传
点击文件名下载附件
手册
下载积分: 黑币 -5
作者:
upczap
时间:
2019-1-8 20:40
谢谢分享
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1