1256 views|0 replies

1668

Posts

0

Resources
The OP
 

MSP340F149 card number reading reference routine [Copy link]

MSP340F149 drives RC522 card reader

  1. //
  2. //===========================================================================//
  3. #include "msp430x14x.h"
  4. #include "PIN_DEF.H"
  5. #include "RC522.H"
  6. #include "UART0_Func.c"
  7. #include "ctype.h"
  8. #include "BoardConfig.h"
  9. unsigned char UID[5],Temp[4] ;
  10. unsigned char RF_Buffer[18] ;
  11. unsigned char Password_Buffer[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; // Mifare One default password
  12. char MBRX[30] ;
  13. char MBKeyTP[30] ;
  14. char Event ;
  15. unsigned char DISP_MODE,i; // Edit control display mode
  16. unsigned char des_on = 0 ; // DES encryption flag
  17. void Key_TP_Task(void) ;
  18. //***************************************************************************//
  19. // //
  20. // Initialize the main clock: MCLK = XT1×(FLL_FACTOR+1) //
  21. // //
  22. //***************************************************************************//
  23. void Init_CLK(void)
  24. {
  25. unsigned int qq;
  26. WDTCTL = WDTPW + WDTHOLD; // Turn off the watchdog
  27. BCSCTL1 &= ~XT2OFF; //Turn on XT2 high speed crystal oscillator
  28. do
  29. {
  30. IFG1 &= ~OFIFG; //Clear oscFault flag Clear oscillator failure flag
  31. for(qq=0xff;qq>0;qq--);
  32. }while((IFG1&OFIFG)); //oscFault flag still set
  33. BCSCTL2 |= SELM_2; //MCLK=XT2
  34. //BCSCTL2 |= DIVM_0; //Control MCLK without frequency division, default
  35. BCSCTL2 |= SELS; //SMCLK=XT2
  36. //BCSCTL2 |= DIVS_0; //Control SMCLK without frequency division, default
  37. }
  38. void Delay(unsigned int time)
  39. {
  40. unsigned int i,k ;
  41. for(i=0;i<255;i++)
  42. for(k=0;k<time;k++)
  43. _NOP() ;
  44. }
  45. void Auto_Reader(void)
  46. {
  47. while(1)
  48. {
  49. if(PcdRequest(0x52,Temp)==MI_OK)
  50. {
  51. if(Temp[0]==0x04&&Temp[1]==0x00)
  52. PutString("MFOne-S50");
  53. else if(Temp[0]==0x02&&Temp[1]==0x00)
  54. PutString("MFOne-S70");
  55. else if(Temp[0]==0x44&&Temp[1]==0x00)
  56. PutString("MF-UltraLight");
  57. else if(Temp[0]==0x08&&Temp[1]==0x00)
  58. PutString("MF-Pro");
  59. else if(Temp[0]==0x44&&Temp[1]==0x03)
  60. PutString("MF Desire");
  61. else
  62. PutString("Unknown");
  63. if(PcdAnticoll(UID)==MI_OK)
  64. {
  65. PutString0("Card Id is:");
  66. attribute(UID[0]);
  67. attribute(UID[1]);
  68. get(UID[2]);
  69. get(UID[3]);
  70. while (!(IFG1 & UTXIFG0));
  71. TXBUF0 = '\n'; //Send line break instruction
  72. RED_LED_ON ;
  73. Delay(200) ;
  74. RED_LED_OFF ;
  75. Delay(200) ;
  76. }
  77. }
  78. else GRE_LED_OFF ;
  79. }
  80. }
  81. void Find_Card(void)
  82. {
  83. if(PcdRequest(0x52,Temp)==MI_OK)
  84. {
  85. if(Temp[0]==0x04&&Temp[1]==0x00)
  86. PutString("MFOne-S50");
  87. else if(Temp[0]==0x02&&Temp[1]==0x00)
  88. PutString("MFOne-S70");
  89. else if(Temp[0]==0x44&&Temp[1]==0x00)
  90. PutString("MF-UltraLight");
  91. else if(Temp[0]==0x08&&Temp[1]==0x00)
  92. PutString("MF-Pro");
  93. else if(Temp[0]==0x44&&Temp[1]==0x03)
  94. PutString("MF Desire");
  95. else
  96. PutString("Unknown");
  97. PutString("SUCCESS!");
  98. }
  99. else PutString("Faile!");
  100. }
  101. void Init_Port(void)
  102. {
  103. P4DIR = RF_LPCTL + RF_SS + RF_SCLK+ RF_DATA_OUT ;
  104. P2DIR |= BIT0+RF_LPCTL + RF_SS + RF_SCLK+ RF_DATA_OUT;
  105. P1DIR = RF_LPCTL + RF_SS + RF_SCLK+ RF_DATA_OUT ;
  106. }
  107. /*******************************************
  108. Function name: HandleConfigMenu
  109. Function: Processing PC configuration functions
  110. Parameter: inputvalue--the characters received from the PC
  111. Return value: None
  112. ********************************************/
  113. void HandleConfigMenu(uchar inputvalue)
  114. {
  115. switch(toupper(inputvalue))
  116. {
  117. case 'A':
  118. Auto_Reader();
  119. break;
  120. case 'F':
  121. Find_Card();
  122. break;
  123. default:
  124. DisplayConfigMenu();
  125. }
  126. }
  127. void main( void )
  128. {
  129. WDTCTL = WDTPW + WDTHOLD; // Turn off the watchdog
  130. BoardConfig(0xf0);
  131. Init_Port();
  132. InitUART();
  133. _EINT() ;
  134. PcdReset(); //Reset RC522
  135. PcdAntennaOn(); //Turn on antenna transmission
  136. DisplayConfigMenu();
  137. while(1)
  138. {
  139. Send1Char('>');
  140. Send1Char('\n');
  141. i=Get1Char();
  142. HandleConfigMenu(i);
  143. }
  144. }
This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list