見附件
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
|