找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

msp430單片機(jī)rc522射頻的程序和與電路圖

[復(fù)制鏈接]
ID:435493 發(fā)表于 2018-11-29 09:42 | 顯示全部樓層 |閱讀模式
rc522射頻刷卡
0.png 0.png

單片機(jī)源程序如下:
  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. }   
復(fù)制代碼

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


回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表