在學習RFID-RC522過程中總總結一些歷程,希望對大家有所幫助。
所有資料51hei提供下載:
RFID-RC522各大開發板配套例程.rar
(2.46 MB, 下載次數: 231)
2018-11-2 15:18 上傳
點擊文件名下載附件
stm32單片機源程序如下:
- #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>
- /**
- * @brief IC測試函數
- * @param 無
- * @retval 無
- */
- void IC_test ( void )
- {
- char cStr [ 30 ];
- uint8_t ucArray_ID [ 4 ]; /*先后存放IC卡的類型和UID(IC卡序列號)*/
- uint8_t ucStatusReturn; /*返回狀態*/
- static uint8_t 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 )
- LCD_SetTextColor(RED);
-
- ILI9341_DispStringLine_EN(LINE(ucLineCount) , (char* )cStr );
-
-
- ucLineCount ++;
-
- if ( ucLineCount == 17 ) ucLineCount = 0;
- }
- }
- }
- }
- /**
- * @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---------------------------------------- */
復制代碼
|