|
- #include "stm32f10x.h"
- #include "./usart/bsp_usart.h"
- #include "./lcd/bsp_ili9341_lcd.h"
- #include "./flash/bsp_spi_flash.h"
- #include "./SysTick/bsp_SysTick.h"
- #include "rc522_config.h"
- #include "rc522_function.h"
- #include <stdbool.h>
- #define READ_WRITE_ENABLE 1 // 1:使能讀寫卡測試相關代碼 0:禁用讀寫卡測試相關代碼
- void IC_CMT ( uint8_t * UID, uint8_t * KEY, uint8_t RW, uint8_t * Dat );
- /**
- * @brief IC測試函數
- * @param 無
- * @retval 無
- */
- uint8_t buffer[100];
- uint8_t buff2[]={0xFF ,0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // 卡A密鑰
- uint8_t buff3[]={0x55 ,0xBA, 0xA9, 0x89, 0x50 ,0xBA, 0xA9, 0x89, 0x50 ,0xBA, 0xA9, 0x89, 0x50 ,0xBA, 0xA9, 0x89}; // 寫入的數據
- void IC_test ( void )
- {
- char cStr [ 30 ];
- uint8_t ucArray_ID [ 4 ]; /*先后存放IC卡的類型和UID(IC卡序列號)*/
- uint8_t ucStatusReturn; /*返回狀態*/
- static uint8_t ucLineCount = 0;
- int i;
- 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 )
- LCD_SetTextColor(RED);
- ILI9341_DispStringLine_EN(LINE(ucLineCount) , (char* )cStr );
- #if READ_WRITE_ENABLE
- /*******************卡片扇區讀寫測試****************************/
- buff3[0]++;
- printf ("開始讀寫卡測試:\n");
- IC_CMT(ucArray_ID, buff2, 0, buff3); // 寫卡
- IC_CMT(ucArray_ID, buff2, 1, buffer); // 讀卡
- printf ("讀到的數據為:\n");
- for( i=0; i<16; i++)
- {
- printf ("0x%X ", buffer[i]); // 打印讀到的數據
- }
- printf ("\n");
- memset(buffer, 0, sizeof(buffer));
- IC_CMT(ucArray_ID, buff2, 1, buffer); // 需要在讀一次下次再能寫進去(不知道為什么這樣,應該是這樣能改變某種模式吧)
- /*******************卡片扇區讀寫測試 END****************************/
- #endif
- ucLineCount ++;
- if ( ucLineCount == 17 ) ucLineCount = 0;
- }
- }
- }
- }
- char PcdComMF522 ( uint8_t ucCommand,
- uint8_t * pInData,
- uint8_t ucInLenByte,
- uint8_t * pOutData,
- uint32_t * pOutLenBit ) ;
- uint8_t buff[] = {0x06, 0x61, 0x1, 0x2, 0x3, 0x4 ,0x6, 0x1, 0x2, 0x3, 0x4};
- uint32_t bufferlen;
- /**
- * @brief 主函數
- * @param 無
- * @retval 無
- */
- int main(void)
- {
- /*滴答時鐘初始化*/
- SysTick_Init ();
- /*LCD 初始化*/
- ILI9341_Init ();
- /* USART config */
- USART_Config();
- /*RC522模塊所需外設的初始化配置*/
- RC522_Init ();
-
- printf ( "WF-RC522 Test\n" );
-
- /*其中0、3、5、6 模式適合從左至右顯示文字,*/
- ILI9341_GramScan ( 6 );
- LCD_SetFont(&Font8x16);
- LCD_SetColors(BLACK,BLACK);
- /* 清屏,顯示全黑 */
- ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);
- /********顯示字符串示例*******/
- LCD_SetTextColor(RED);
- ILI9341_DispStringLine_EN(LINE(18),
- (char* )"Please put the IC card on WF-RC522 antenna area ...");
- LCD_SetTextColor(YELLOW);
- PcdReset ();
- /*設置工作方式*/
- M500PcdConfigISOType ( 'A' );
- while(1)
- {
- /*IC卡檢測 */
- IC_test ();
- }
- }
- /* ------------------------------------------end of file---------------------------------------- */
- /*設置工作方式*/
- M500PcdConfigISOType ( 'A' );
-
- while ( 1 )
- {
- /*IC卡檢測*/
- IC_test ();
- }
- }
- /**************
復制代碼 |
-
-
F103_霸道開發板.7z
2019-12-23 13:27 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
223.51 KB, 下載次數: 83, 下載積分: 黑幣 -5
|