標(biāo)題:
關(guān)于M1卡的stm32源碼與資料分享
[打印本頁(yè)]
作者:
HelloPan111
時(shí)間:
2017-12-6 14:22
標(biāo)題:
關(guān)于M1卡的stm32源碼與資料分享
見(jiàn)附件
0.jpg
(35.57 KB, 下載次數(shù): 58)
下載附件
2017-12-6 19:37 上傳
單片機(jī)源程序如下:
#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卡序列號(hào))
u8 ucStatusReturn; //返回狀態(tài)
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);//驗(yàn)證卡片密碼
// if (status != MI_OK){
// continue;}
// if(ucLineCount%2==1){
// status = PcdWrite(1, data1);//寫(xiě)塊1,數(shù)據(jù)為1122
// if (status != MI_OK)
// { continue; }}
// else
// {
// status = PcdWrite(1, data);//寫(xiě)塊1,數(shù)據(jù)為00FF,錢(qián)包模式
// if (status != MI_OK)
// { continue; }
// status = PcdWrite(2, data);//寫(xiě)塊2,數(shù)據(jù)為00FF,錢(qián)包模式
// 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(); //休眠,無(wú)效,為自動(dòng)尋卡模式;
}
}
/********************************************************
void IC_test ( void )
{
char cStr [ 30 ];
u8 ucArray_ID [ 4 ]; //先后存放IC卡的類型和UID(IC卡序列號(hào))
u8 ucStatusReturn; //返回狀態(tài)
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 ) //防沖撞(當(dāng)有多張卡進(jìn)入讀寫(xiě)器操作范圍時(shí),防沖突機(jī)制會(huì)從其中選擇一張進(jìn)行操作)
{
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);//驗(yàn)證卡片密碼
if (status != MI_OK){
continue;}
if(ucLineCount%2==1){
status = PcdWrite(1, data1);//寫(xiě)塊1,數(shù)據(jù)為1122
if (status != MI_OK)
{ continue; }}
else
{
status = PcdWrite(1, data);//寫(xiě)塊1,數(shù)據(jù)為00FF,錢(qián)包模式
if (status != MI_OK)
{ continue; }
status = PcdWrite(2, data);//寫(xiě)塊2,數(shù)據(jù)為00FF,錢(qián)包模式
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 ) //防沖撞(當(dāng)有多張卡進(jìn)入讀寫(xiě)器操作范圍時(shí),防沖突機(jī)制會(huì)從其中選擇一張進(jìn)行操作)
{
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 主函數(shù)
* @param 無(wú)
* @retval 無(wú)
*/
int main ( void )
{
SysTick_Init (); //滴答時(shí)鐘初始化
……………………
…………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
RFID.rar
(324.74 KB, 下載次數(shù): 27)
2017-12-6 19:37 上傳
點(diǎn)擊文件名下載附件
程序
下載積分: 黑幣 -5
M1卡介紹.pdf
(409.84 KB, 下載次數(shù): 21)
2017-12-6 14:21 上傳
點(diǎn)擊文件名下載附件
手冊(cè)
下載積分: 黑幣 -5
作者:
upczap
時(shí)間:
2019-1-8 20:40
謝謝分享
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1