久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3398|回復(fù): 0
收起左側(cè)

stm32f103開發(fā)板RC522讀寫程序親測可用

[復(fù)制鏈接]
ID:386213 發(fā)表于 2019-12-23 11:36 | 顯示全部樓層 |閱讀模式
  1. #include "stm32f10x.h"
  2. #include "./usart/bsp_usart.h"        
  3. #include "./lcd/bsp_ili9341_lcd.h"
  4. #include "./flash/bsp_spi_flash.h"
  5. #include "./SysTick/bsp_SysTick.h"
  6. #include "rc522_config.h"
  7. #include "rc522_function.h"
  8. #include <stdbool.h>

  9. #define READ_WRITE_ENABLE    1    // 1:使能讀寫卡測試相關(guān)代碼    0:禁用讀寫卡測試相關(guān)代碼

  10. void IC_CMT ( uint8_t * UID, uint8_t * KEY, uint8_t RW, uint8_t * Dat );
  11. /**
  12.   * @brief  IC測試函數(shù)
  13.   * @param  無
  14.   * @retval 無
  15.   */
  16. uint8_t buffer[100];
  17. uint8_t buff2[]={0xFF ,0xFF, 0xFF, 0xFF, 0xFF, 0xFF};   // 卡A密鑰
  18. uint8_t buff3[]={0x55 ,0xBA, 0xA9, 0x89, 0x50 ,0xBA, 0xA9, 0x89, 0x50 ,0xBA, 0xA9, 0x89, 0x50 ,0xBA, 0xA9, 0x89};    // 寫入的數(shù)據(jù)
  19. void IC_test ( void )
  20. {
  21.         char cStr [ 30 ];
  22.   uint8_t ucArray_ID [ 4 ];    /*先后存放IC卡的類型和UID(IC卡序列號)*/                                                                                         
  23.         uint8_t ucStatusReturn;      /*返回狀態(tài)*/                                                                                          
  24.   static uint8_t ucLineCount = 0;
  25.   int i;

  26.   while ( 1 )
  27.   {
  28.     /*尋卡*/
  29.                 if ( ( ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ) ) != MI_OK )  
  30.        /*若失敗再次尋卡*/
  31.                         ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID );                                                               

  32.                 if ( ucStatusReturn == MI_OK  )
  33.                 {
  34.       /*防沖撞(當(dāng)有多張卡進入讀寫器操作范圍時,防沖突機制會從其中選擇一張進行操作)*/
  35.                         if ( PcdAnticoll ( ucArray_ID ) == MI_OK )                                                                  
  36.                         {
  37.                                 sprintf ( cStr, "The Card ID is: %02X%02X%02X%02X",
  38.                   ucArray_ID [ 0 ],
  39.                   ucArray_ID [ 1 ],
  40.                   ucArray_ID [ 2 ],
  41.                   ucArray_ID [ 3 ] );

  42.                 printf ( "%s\r\n",cStr );

  43.           if ( ucLineCount == 0 )
  44.             LCD_SetTextColor(RED);         

  45.           ILI9341_DispStringLine_EN(LINE(ucLineCount) , (char* )cStr );

  46. #if READ_WRITE_ENABLE
  47.           /*******************卡片扇區(qū)讀寫測試****************************/
  48.           buff3[0]++;

  49.           printf ("開始讀寫卡測試:\n");

  50.           IC_CMT(ucArray_ID, buff2, 0, buff3);    // 寫卡

  51.           IC_CMT(ucArray_ID, buff2, 1, buffer);   // 讀卡

  52.           printf ("讀到的數(shù)據(jù)為:\n");

  53.           for( i=0; i<16; i++)
  54.           {
  55.             printf ("0x%X  ", buffer[i]);    // 打印讀到的數(shù)據(jù)
  56.           }
  57.           printf ("\n");
  58.           memset(buffer, 0, sizeof(buffer));

  59.           IC_CMT(ucArray_ID, buff2, 1, buffer);   // 需要在讀一次下次再能寫進去(不知道為什么這樣,應(yīng)該是這樣能改變某種模式吧)
  60.           /*******************卡片扇區(qū)讀寫測試 END****************************/  
  61. #endif

  62.           ucLineCount ++;

  63.           if ( ucLineCount == 17 ) ucLineCount = 0;            
  64.                         }               
  65.                 }               
  66.   }        
  67. }
  68. char PcdComMF522 ( uint8_t ucCommand,
  69.                     uint8_t * pInData,
  70.                     uint8_t ucInLenByte,
  71.                     uint8_t * pOutData,
  72.                     uint32_t * pOutLenBit )        ;
  73. uint8_t buff[] = {0x06, 0x61, 0x1, 0x2, 0x3, 0x4 ,0x6, 0x1, 0x2, 0x3, 0x4};

  74. uint32_t bufferlen;
  75. /**
  76.   * @brief  主函數(shù)
  77.   * @param  無
  78.   * @retval 無
  79.   */
  80. int main(void)
  81. {        
  82.   /*滴答時鐘初始化*/
  83.   SysTick_Init ();

  84.         /*LCD 初始化*/
  85.         ILI9341_Init ();  

  86.         /* USART config */
  87.         USART_Config();

  88.   /*RC522模塊所需外設(shè)的初始化配置*/
  89.   RC522_Init ();     
  90.         
  91.   printf ( "WF-RC522 Test\n" );
  92.         
  93.   /*其中0、3、5、6 模式適合從左至右顯示文字,*/
  94.         ILI9341_GramScan ( 6 );
  95.   LCD_SetFont(&Font8x16);
  96.         LCD_SetColors(BLACK,BLACK);

  97.   /* 清屏,顯示全黑 */
  98.   ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);

  99.         /********顯示字符串示例*******/
  100.   LCD_SetTextColor(RED);  

  101.   ILI9341_DispStringLine_EN(LINE(18),
  102.        (char* )"Please put the IC card on WF-RC522 antenna area ...");

  103.   LCD_SetTextColor(YELLOW);

  104.   PcdReset ();

  105.   /*設(shè)置工作方式*/   
  106.         M500PcdConfigISOType ( 'A' );

  107.   while(1)
  108.   {
  109.     /*IC卡檢測        */   
  110.     IC_test ();     

  111.   }

  112. }


  113. /* ------------------------------------------end of file---------------------------------------- */

  114.   /*設(shè)置工作方式*/
  115.         M500PcdConfigISOType ( 'A' );
  116.         
  117.   while ( 1 )
  118.   {
  119.     /*IC卡檢測*/
  120.     IC_test ();                        
  121.   }            
  122. }
  123. /**************
復(fù)制代碼

F103_霸道開發(fā)板.7z

223.51 KB, 下載次數(shù): 83, 下載積分: 黑幣 -5

回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 91高清免费 | 精品日韩一区 | 欧美成人免费电影 | 欧美日韩综合视频 | 在线永久看片免费的视频 | 精品国产欧美一区二区三区成人 | www.亚洲视频 | 欧美日韩精品在线一区 | 成人国产精品免费观看 | 国产传媒在线播放 | 午夜精品视频在线观看 | 草草视频在线免费观看 | 黑人巨大精品 | 九九伦理电影 | 日本电影韩国电影免费观看 | 精品一区视频 | 日韩毛片中文字幕 | 国产专区免费 | 一二三四在线视频观看社区 | 91成人在线| 亚洲免费视频一区 | 久久免费视频2 | 日本久久网 | 99国产精品99久久久久久 | 99精品九九 | 成人在线免费观看av | 中文字幕在线电影观看 | 国产91精品久久久久久久网曝门 | 欧美成人高清 | 91av视频在线 | 国产一区二区影院 | 伊大人久久 | 精品一级 | 蜜桃视频一区二区三区 | 成人av观看 | 欧美视频 亚洲视频 | 国产午夜在线 | 国产精品18hdxxxⅹ在线 | 亚洲视频免费在线播放 | jlzzjlzz国产精品久久 | 激情的网站 |