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

📄 main.#2

📁 RFID 使用C8051F020和周立功RC500开发模块
💻 #2
字号:
#define __SRC
#include "main.h"
#undef  __SRC

#include "zlg500B.h"

#define MF1_S50		0
#define MF1_S70		1
#define MF0_ULIGHT	2
#define MF1_LIGHT	3


sbit zlg500B_RST=P1^0;		//change

uchar baud_num;				//波特率选择序号

uchar card_snr[8];			//卡的序列号		//进行两轮验证,

void serial_init(void);
void F020Config(void);

uchar code Nkey_a[6]={0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};		//密码
uchar code Nkey_b[6]={0xff, 0xff, 0xff, 0xff, 0xff, 0xff};

main()
{	
	
	
	uchar cardtype=MF1_S50;		//我们也是用的这种卡,因为有一个种S70
	uchar i,j=40;
	uchar databuf[16];			//从卡中一个段的数据
	long value=1;
	
	F020Config();				//仅仅完成引脚分配
	
	for(i=255;i>0;i--)
		for(j=10;j>0;j--);
	zlg500B_RST=0;					//对整个系统进行复位
	for(i=255;i>0;i--)
		for(j=20;j>0;j--);	

	baud_num=2;					//选择9600的波特率
	serial_init();	
	EA=1;						//开总中断

	i=mifs_config();			//进行RC50配置

	while(1)
	{	
		while(mifs_request(IDLE,databuf)!=MI_OK);		//一直在查有没有卡
		{
		
			break;
		 }
	
	}

	

	
}

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

void 	serial_init (void)
{
	PCON = 0x80;              	// SMOD = 1;
	SCON0 = 0x50;              	// Mode 1, 8-bit UART, enable receiption
	TMOD&=0x0f;					//定时器1进行全清零,不管定时器0
	TMOD|=0x20;	      		// Timer 1, mode 2, 8-bit auto reload,
	
	switch(baud_num)				//由于实际对波特率进行设置		
	{	
		case 0:	TH1=BAUD_2400;	break;
		case 1:	TH1=BAUD_4800;	break;
		case 2:	TH1=BAUD_9600;	break;
		case 3:	TH1=BAUD_19200;	break;
		case 4:	TH1=BAUD_28800;	break;
		case 5:	TH1=BAUD_57600;	break;
	}
	
	CON_485=0;						//平时为低,
	ES0 = 1;							//开串口中断					
	ET1 = 0;						//禁定时器1中断
	TR1 = 1;						//开外部中断
}

#pragma noaregs

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

void 	delay_50us (uchar _50us)			//延时50US
{

  RCAP2LH = RCAP2_50us;
  T2LH    = RCAP2_50us;
  ET2 = 0; 	// Disable timer2 interrupt
  T2CON = 0x04;	// 16-bit auto-reload, clear TF2, start timer
  				//开定时器2
				//89C51中并没有定时器2  只有在89C52中才有
  while (_50us--)
  {
	while (!TF2);		//溢出标志:等待溢出标志
	TF2 = FALSE;			//溢出标志清零
  }

  TR2 = FALSE;			//关定时器2

}


/****************************************************************************
*                                                                           *
* Function:     delay_1ms                                                   *
*                                                                           *
* Input:        _1ms                                                        *
* Output:       -                                                           *
*                                                                           *
* Description:                                                              *
*                                                                           *
* Time delay with a resolution of 1 ms.                                     *
*                                                                           *
****************************************************************************/

void 	delay_1ms (uint _1ms)
{

  RCAP2LH = RCAP2_1ms;
  T2LH    = RCAP2_1ms;
  ET2 = 0; 	// Disable timer2 interrupt
  T2CON = 0x04;	// 16-bit auto-reload, clear TF2, start timer
  
  while (_1ms--)
  {
	while (!TF2);
	TF2 = FALSE;
  }
  TR2 = FALSE;

}


/****************************************************************************
*                                                                           *
* Function:     delay_10ms                                                  *
*                                                                           *
* Input:        _10ms                                                       *
* Output:       -                                                           *
*                                                                           *
* Description:                                                              *
*                                                                           *
* Time delay with a resolution of 10 ms.                                    *
*                                                                           *
****************************************************************************/

void 	delay_10ms (uint _10ms)
{

  RCAP2LH = RCAP2_10ms;
  T2LH    = RCAP2_10ms;
  ET2 = 0; 	// Disable timer2 interrupt
  T2CON = 0x04;	// 16-bit auto-reload, clear TF2, start timer
  
  while (_10ms--)
  {
	while (!TF2);			//查询方式
	TF2 = FALSE;
  }
  TR2 = FALSE;			//完成指定延时任务,收工

}

void F020Config(void)
{
	int i;                              // delay counter
	WDTCN = 0x07;	// Watchdog Timer Control Register
    WDTCN = 0xDE;   // Disable WDT
    WDTCN = 0xAD;	
   
	OSCXCN = 0x67;                      // start external oscillator with
                                       // 22.1184MHz crystal

   for (i=0; i < 256; i++) ;           // XTLVLD blanking interval (>1ms)

   while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle

   OSCICN = 0x88;                      // select external oscillator as SYSCLK
                                       // source and enable missing clock
                                       // detector
		XBR0 = 0x04;	// XBAR0: Initial Reset Value
	XBR1 = 0x04;	// XBAR1: Initial Reset Value
	XBR2 = 0x44;	// XBAR2: Initial Reset Value

	 P0MDOUT = 0x05; // Output configuration for P0 
    P1MDOUT = 0x00; // Output configuration for P1 
    P2MDOUT = 0x00; // Output configuration for P2 
    P3MDOUT = 0x00; // Output configuration for P3 
    P74OUT = 0x00;  // Output configuration for P4-7

    P1MDIN = 0xFF;  // Input configuration for P1

		// P0.0 = UART TX0        (Push-Pull Output)
		// P0.1 = UART RX0        (Open-Drain Output/Input)
		// P0.2 = UART TX1        (Push-Pull Output)
		// P0.3 = UART RX1        (Open-Drain Output/Input)
		// P0.4 = /INT0           (Open-Drain Output/Input)
}

#pragma aregs



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

⌨️ 快捷键说明

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