標題: msp430單片機rc522射頻的程序和與電路圖 [打印本頁]

作者: yy0115    時間: 2018-11-29 09:42
標題: msp430單片機rc522射頻的程序和與電路圖
rc522射頻刷卡


單片機源程序如下:
  1. #include  <msp430x41x.h>
  2. #include "main.h"
  3. #include "mfrc522.h"

  4. #pragma memory = constseg(TAB)
  5. unsigned char data1[16] = {0x12,0x34,0x56,0x78,0xED,0xCB,0xA9,0x87,0x12,0x34,0x56,0x78,0x01,0xFE,0x01,0xFE};
  6. //M1卡的某一塊寫為如下格式,則該塊為錢包,可接收扣款和充值命令
  7. //4字節(jié)金額(低字節(jié)在前)+4字節(jié)金額取反+4字節(jié)金額+1字節(jié)塊地址+1字節(jié)塊地址取反+1字節(jié)塊地址+1字節(jié)塊地址取反
  8. unsigned char data2[4]  = {0x12,0,0,0};
  9. unsigned char DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};               
  10. #pragma memory=default
  11.             
  12. unsigned char g_ucTempbuf[20];

  13. void main(void)
  14. {
  15.      unsigned char status;
  16.      InitializeSystem();
  17.      PcdReset();
  18.      PcdAntennaOff();
  19.      PcdAntennaOn();  
  20.      while ( 1 )
  21.      {   
  22.          status = PcdRequest(PICC_REQALL, g_ucTempbuf);
  23.          if (status != MI_OK)
  24.          {   
  25.              LED_GREEN_OFF;
  26.              continue;
  27.          }
  28.          LED_GREEN_ON;     //檢測到有卡存在
  29.          
  30.          status = PcdAnticoll(g_ucTempbuf);
  31.          if (status != MI_OK)
  32.          {    continue;    }
  33.          
  34.          status = PcdSelect(g_ucTempbuf);
  35.          if (status != MI_OK)
  36.          {    continue;    }
  37.          
  38.          status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);
  39.          if (status != MI_OK)
  40.          {    continue;    }
  41.          
  42.          status = PcdWrite(1, data1);
  43.          if (status != MI_OK)
  44.          {    continue;    }
  45.          
  46.          status = PcdValue(PICC_DECREMENT,1,data2);
  47.          if (status != MI_OK)
  48.          {    continue;    }
  49.          
  50.          status = PcdBakValue(1, 2);
  51.          if (status != MI_OK)
  52.          {    continue;    }
  53.          
  54.          status = PcdRead(2, g_ucTempbuf);
  55.          if (status != MI_OK)
  56.          {    continue;    }
  57.          
  58.          PcdHalt();
  59.     }
  60. }


  61. /////////////////////////////////////////////////////////////////////
  62. //功能:系統(tǒng)初始化
  63. /////////////////////////////////////////////////////////////////////       
  64. void InitializeSystem(void)
  65. {
  66.     WDTCTL = WDTPW + WDTHOLD;             //Stop watchdog timer
  67.     _DINT();
  68.      
  69.     P1DIR = 0xE8;
  70.     P1OUT = 0xFF;
  71.       
  72.     P6DIR = 0x08;
  73.     P6OUT = 0xFF;
  74. }   
復制代碼

所有資料51hei提供下載:
51單片機rc522 射頻的程序和與電路圖.rar (2.66 MB, 下載次數(shù): 25)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1