學校暑期課設用的代碼,非常簡單,網上也比較好找,給大家分享一下
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
|