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

📄 main.c

📁 RC500 MF1 非接触读卡器 开发板 资料
💻 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^4;
sbit    RC500_CS         	= P2^7;
sbit    LED	            	= P3^2;
sbit    BZ                  = P1^1;
//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);


unsigned char  Nkey_a[6]    = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};
unsigned char  Nkey_b[6]    = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};


/****************************************************************************
*                                                                           *
* Function:     inim500,setpassword,                                                        *
*                                                                           *
* Input:        -                                                           *
* Output:       -                                                           *
*                                                                           *
* Description:                                                              *
*                                                                           *
*                                                                           *
****************************************************************************/

  unsigned char   retry,sector,counter2;
  unsigned char   mfout=2;//readbuf[16];
  unsigned char    tt1[2];
  extern unsigned char   status1;
  unsigned char   cardserialno[4];
  unsigned char    sak1;
  unsigned char   blockdata[16];
	
  extern char initm500()
  {
   
  init();
  if(M500PcdConfig()==MI_OK)printf("\nM500 inter face ok"); 
  if((status1=M500PcdMfInOutSlaveConfig())==MI_OK)printf("\nRewire 531-E2");else printf("preset=%b02X",status1);
  	
  if(M500PcdConfig()==MI_OK)printf("\nM500 inter face ok"); 
  								        	// Initialise the RC500
	                          // must be call in the initialisation
  status1=PcdReadE2(8,4,Snr_RC500); // Read out the MFRC500 serial number and store it
  if(status1==MI_OK)printf("\nSnrno==%b02X%b02X%b02X%b02X",Snr_RC500[3],Snr_RC500[2],Snr_RC500[1],Snr_RC500[0]); 
  M500PcdMfOutSelect(mfout);
    return status1;

  } 
   
    //set password// 
extern char setpassword (authent_mod, char sector,char *Nkey_b)
    {
  	   status1 = M500PiccRequest(PICC_REQALL,tt1);
 	if (status1==MI_OK)
		status1=M500PiccAnticoll(0,cardserialno),
		printf("\nATQ=%b02X%b02X",tt1[1],tt1[0]);
  	if (status1==MI_OK)
       printf("\nCardSerialno=%b02X%b02X%b02X%b02X",cardserialno[0],cardserialno[1],cardserialno[2],cardserialno[3]);
    if (status1==MI_OK)
        status1=M500PiccSelect(cardserialno,&sak1),
	     printf("\nSecect status%b02X=",status1);
	if (status1==MI_OK) 
        status1= M500PcdLoadKeyE2(authent_mod, sector,Nkey_b);
    if (status1 ==MI_OK)printf("\nLoad KeyE2 Err=%b02X",status1),
		status1= M500PiccAuthE2(authent_mod,cardserialno,sector,sector*4);
    return status1;
	}
		//Read N bloCk //
extern char readblock(char blocknum,char *_data)  

{
if (status1==MI_OK)
        // printf("\nSector %b02X PW=%b02X%b02X%b02X%b02X%b02X%b02X",sector,
        // MKeys[retry][0],MKeys[retry][1],MKeys[retry][2],MKeys[retry][3],MKeys[retry][4],MKeys[retry][5]),
		status1=M500PiccRead(blocknum,_data),
        printf("Read ERR=%b02X",status1);  
	if (status1==MI_OK)
	for ( counter2=0;counter2<16;counter2++)
 	{ 
	printf("%b02X",blockdata[counter2]);
 	
	} else printf("\nstatus1=%b02X",status1);
}   
           //Write Block //
extern  char writeblock (char blocknum ,char *blockdata)

	{
		   if (status1 ==MI_OK)
	return (status1 = M500PiccWrite(blocknum,blockdata));
    }
   
 
/****************************************************************************
*                                                                           *
* Function:     main                                                          *
*                                                                           *
* Input:        -                                                           *
* Output:       -                                                           *
*                                                                           *
* Description:                                                              *
*                                                                           *
*                                                                           *
****************************************************************************/



/****************************************************************************
*                                                                           *
* Function:     init                                                        *
*                                                                           *
* Input:        -                                                           *
* Output:       -                                                           *
*                                                                           *
* Description:                                                              *
*                                                                           *
*                                                                           *
****************************************************************************/

void 	init (void)
{
  
  
  P1=0xff,P2=0xFF,P3=0xFF;
  openio();

  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 = 0x00;              	// SMOD = 1;
   SCON = 0x50;              	// Mode 1, 8-bit UART, enable receiption

   
    AutoBaud = FALSE;	
    TMOD     = 0x20;      	// Timer 1, mode 2, 8-bit auto reload,
  	TH1		=0xFA;               /* TH1:  reload value for 9600 baud @ 22MHz   */
	TL1 	=0xFA;
    TR1   = 1;                  /* TR1:  timer 1 run                          */
    TI    = 1;                  /* TI:   set TI to send first char of UART    */


   printf ("\ncom port ok");
  
  		  		// Timer 0, mode 0, 13-bit counter
  Capt_L   = 0;
  Capt_H   = 0;

  LED = OFF;
  //BZ=0;
  delay_10ms(50);
  LED = ON;
  //BZ=1;

  IT1 = 1;    			// Config ext1 as edge trigger for RC500
  EX1 = 1; 			  // Enable ext1 interrupt for RC500

  EA = 1;			// Enable all interrupts

}



/****************************************************************************
*                                                                           *
* Function:     delay_50us                                                  *
*                                                                           *
* Input:        _50us                                                       *
* Output:       -                                                           *
*                                                                           *
* Description:                                                              *
*                                                                           *
* Time delay with a resolution of 50 us.                                    *

⌨️ 快捷键说明

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