⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 射频芯片RC500的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************

*                                                                           *

* File:         MAIN.C                                                      *

*                                                                           *

* Version:      1.0                                       	       		    *

*                                                                           *

* Created:      21.06.2002                 
                                 *

* Last Change:  22.06.2002                                                  *

*                                                                           *

* Author:       Steven Jiang Chang                                               *

*                                                                           *

* Compiler:     KEIL C51 uVision2 V2.23                                              *

*                                                                           *

* Description:  89C52RD2-Firmware for MFRC500 Demo Serial Reader            *

*                                                                           *

****************************************************************************/



#define __SRC

#include "main.h"

#undef  __SRC



#include <string.h>

#include <intrins.h>

#include <stdio.h>

#include <m500a.h>

#include <p89c51rx.h>



#define MIS_CHK_OK              (0)

#define MIS_CHK_FAILED          (-1)

#define MIS_CHK_COMPERR         (-2)



// Function: mifs_request

#define IDLE                    0x00    

#define ALL                     0x01



sbit    RC500RST        	= P3^5;

sbit    RC500_CS         	= P2^7;

sbit    LED	        	= P3^4;

//sbit    LED	        	= P3^4;



// Release Number of the Firmware

uchar code SW_Rel[] = "\n\r MFRC500 V1.0 22.06.02 \n\r";



// Serial Number of the MFRC500 

uchar Snr_RC500[4];



static uint Crc;



// Local Prototypes

void init(void);





 code Nkey_a[6]    = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};

 code Nkey_b[6]    = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};





/****************************************************************************

*                                                                           *

* Function:     main                                                        *

*                                                                           *

* Input:        -                                                           *

* Output:       -                                                           *

*                                                                           *

* Description:                                                              *

*                                                                           *

*                                                                           *

****************************************************************************/

void 	main (void)

{

  unsigned char counter,counter2;

  unsigned char mfout=2;//readbuf[16];

  unsigned char tt1[2];

  unsigned char status1;

  unsigned char cardserialno[4];

  unsigned char *sak1;

  unsigned char blockdata[16];

  init();

  M500PcdConfig();  	// Initialise the RC500

	                // must be call in the in
itialisation

  PcdReadE2(8,4,Snr_RC500); // Read out the MFRC500 serial number and store it

    M500PcdMfOutSelect(mfout);



  for (counter=0;counter<20;counter++)

 {

  	status1 = M500PiccRequest(PICC_REQALL, tt1);

  	if (status1==MI_OK)

		status1=M500PiccAnticoll(0,cardserialno);

  	if (status1==MI_OK)

    	status1=M500PiccSelect(cardserialno,sak1);

  	if (status1==MI_OK)

	  	status1 = M500PiccAuth(PICC_AUTHENT1A, cardserialno, 1, 4);

  	if (status1 ==MI_OK)

      	status1=M500PiccRead(4, blockdata);

  	for ( counter2=0;counter2<16;counter2++)

       	blockdata[counter2]=counter;

  	if (status1 ==MI_OK)

	  	status1 = M500PiccWrite(4,blockdata);                

     	

  }

}





/****************************************************************************

*                                                                           *

* Function:     init                                                        *

*                                                                           *

* Input:        -                                                           *

* Output:       -                                                           *

*                                                                           *

* Description:                                                              *

*                                                                           
*

*                                                                           *

****************************************************************************/



void 	init (void)

{

  RC500RST    = FALSE;

  RC500_CS    = TRUE;	// Enable the CS for RC500

			

  CmdReceived = FALSE;

  CmdValid    = FALSE;

  Quit        = FALSE;

  LLfReady    = TRUE;

  SendReady   = TRUE;

  Idle        = TRUE;



  RepCnt      = 0;



  RecvState   = RECV_STX;



  EnableTransferCmd = FALSE;



  CheckByteCnt = BCC_CHECKBYTECNT;



#ifdef AUTODELAY

  DelayRate = 0;

  DelayRateLocked = TRUE;

#endif



  PCON = 0x80;              	// SMOD = 1;

  SCON = 0x50;              	// Mode 1, 8-bit UART, enable receiption

  

  AutoBaud = TRUE;

  TMOD     = 0x20;      	// Timer 1, mode 2, 8-bit auto reload,

  		  		// Timer 0, mode 0, 13-bit counter

  Capt_L   = 0;

  Capt_H   = 0;

  

  LED = OFF;

  delay_10ms(50);

  LED = ON;



  IT0 = 1;    			// Config ext0 as edge trigger for RC500

  EX0 = 1; 			// Enable ext0 interrupt for RC500



  EA = TRUE;			// Enable all interrupts



}







/****************************************************************************

*                                                                           *

* Function:     delay_50us                                                  *

*                                                                           *

* Input:        _50us                                                       *

* Output:       -                                                           *

*                                                                           *

* Description:                                                              *

*                                                                           *

* Time delay with a resolution of 50 us.                                    *

*                                                                           *

****************************************************************************/



void 	delay_50us (uchar _50us)

{



  RCAP2LH = RCAP2_50us;

  T2LH    = RCAP2_50us;

  ET2 = 0; 	// Disable timer2 interrupt

  T2CON = 0x04;	// 16-bit auto-reload, clear TF2, start timer

  

  while (_50us--)

  {

	while (!TF2);

	TF2 = FALSE;

  }



  TR2 = FALSE;



}





/****************************************************************************

*                                                                           *

* Function:     delay_1ms                                                   *

*                                                                           *

* Input:        _1ms                                                        *

* Output:       -                                                           *

*                                                                           *

* Description:                                                              *

*                                                                           *

* Time delay with a resolution of 1 ms.                                     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -