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

📄 em4095.c

📁 是采用基站芯片读卡号
💻 C
字号:
			  /*----------------头文件------------------*/
/******************************************/
#include "reg52.h"
#include "intrins.h"
//#include "absacc.h"
//#include "math.h"
#include "string.h"
#include "stdio.h"
#include "EM4100.h"
#include "em4095.h"

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

/********************定义特殊功能寄存器*************************/
/***************************************************************/

sfr AUXR=0x8e ;      /*ALE控制寄存器*/
/***************************************************************/
/*uchar bdata  x_byte;

sbit  x_bit0=x_byte^0;
sbit  x_bit1=x_byte^1;
sbit  x_bit2=x_byte^2;
sbit  x_bit3=x_byte^3;
sbit  x_bit4=x_byte^4;
sbit  x_bit5=x_byte^5;
sbit  x_bit6=x_byte^6;
sbit  x_bit7=x_byte^7; 	  */


/****************************************************************************
* 文件名:em4095.c
* 功能描述:  电子门禁的实现:
                 识别RFID卡,读取其ID号, 并结合输入的按键密码,进行身份认证,
                 认证通过后使蜂鸣器鸣叫一声,并驱动电磁门锁实现开锁功能,
                 存储此次开锁时间,以便以后查询和考证。
*****************************************************************************/

                                 
//#include"em4095.h"                     
/*********************************************/
/************************************************
*函数 :DelayMs()
*调用函数:
*参数:
*功能描述: 延时子程序X*ms
by:
**************************************************/

void DelayMs(uint number)
{
    uint temp;
    for(;number!=0;number--)
    {
        for(temp=228;temp!=0;temp--)
        {
        ;
        }
    }
}

/************************************************
*函数 :InitQ()
*调用函数:
*参数:
*功能描述: 系统初始化接收缓冲区
by:
**************************************************/
void InitQ()
{
    RecCtn=0;               /*接收数据数 */
    In=Out=GetChar;

}
/************************************************
*函数 :Uart_Init() 
*调用函数:
*参数:
*功能描述: Uart初始化函数
by:
**************************************************/
void Uart_Init()   
{
   PCON=0X00;
   SCON = 0x50;    /*   设置串行口控制寄存器SCON*/   
   TMOD = 0x20;    /*   定时器T1产生11.0592M时钟时波特率为9600   */   
   //TCON   = 0x69;    /*   TCON   */   
   TH1 =  0xfd;     /*   TH1   */
   TL1 =  0XFd;
   TR1=1;
    
   
}   
/************************************************
*函数 :System_init()
*调用函数:
*参数:
*功能描述: 系统初始化函数
by:
**************************************************/
void System_init()
{
  LED=0;
  DelayMs(10);
  Uart_Init(); 
  	
  InitQ();
  
 // GetIndex=0;
  IE=0X90;
  PS=1;
  MOD=0;
  SHD=1;
  DelayMs(35);
  SHD=0;
 
 
}
/************************************************
*函数 :Send_Byte() 
*调用函数:
*参数:
*功能描述: 向串口发送一个字节的数据
by:
**************************************************/
void Send_Byte(uchar a) 
{
  //SBUF=a;
 
   TI=0; 
   SBUF=a;
    while(TI==0);
    TI=0;  


}
/************************************************
*函数 :Send_String() 
*调用函数:
*参数:
*功能描述: 向串口发送一字符串
by:
**************************************************/
void Send_String(uchar *a,uchar str_lenght)
{
   uchar i;
   for(i=0;i<str_lenght;i++)
   {
    Send_Byte(*a);
    a++;
   }
}
/************************************************
*函数名:Read_Byte() 
*调用函数:
*参数:
*功能描述: 从缓冲区取一个字节的数据
by:
**************************************************/
uchar  Read_Byte(void)
{
    uchar ReadByte;
    
    ReadByte=*Out;
    RecCtn--;
    Out++;
    return(ReadByte) ;

  
}
 /************************************************
*函数名:LED_Flash() 
*调用函数:
*参数:
*功能描述:led闪烁程序
by:
**************************************************/
void LED_Flash(uchar LEDTimes )
{
uchar  LED_Times;
   	for(LED_Times=0;LED_Times<LEDTimes;LED_Times++)
  {
    LED=1;
    DelayMs(200);
	LED=0;
	DelayMs(200);
   }
  }
/************************************************
*函数名:Get_Manma() 
*调用函数:
*参数:
*功能描述: 射频接受程序
by:
**************************************************/
/*Get_Manma() 
{
  MOD=0;

  SHD=1;
  DelayMs(1);
  SHD=0;
  DelayMs(35);


}


*/
/************************************************
*函数 :main()
*调用函数:
*参数:
*功能描述: 主控
by:
**************************************************/
void main()
{
  //uchar LED_Times;  
  ulong GetCode=0;  
   MOD=0;
    SHD=1;
	LED=1;  
	Manchester_IN=1;
	                                                                                                                                             
   	 LED_Flash(3);
   System_init();
	  
   while(1)
   {
      if(RecCtn==0)
      {	  ES=0;
	      InitQ();
		  ES=1;
      }
      else
      {
        if(Read_Byte()==0x02)
        {	  DelayMs(35);
            if(Read_Byte()==0x04)
            {
			  /*Send_Byte('Y');
			  Send_Byte('U');
			  Send_Byte('!');
			  				  */
			  GetCode=Read_Card();
			  if(GetCode)
		      {
		   	     			   	     
				// Send_Byte('H');
			    // printf("\nSN:%ld",GetCode);
			    // LED_Flash(1);
				;
			     
		      }				  	
              Send_String("Com Test OK!\n",13);
            }
			else ;
        }
		else ;
        
      }
      
      

   }  
     
}
/************************************************
*函数 :Uart_Int() 
*调用函数:
*参数:
*功能描述: 串口中断函数
by:
**************************************************/
void Uart_Int(void) interrupt 4
{
  if(RI==1)
  {
     
    *In=SBUF;
    RecCtn++;
    In++;
    RI=0;
	//LED_Flash(1);
  }
}
/************************************************
*函数 :INT1_Int() 
*调用函数:
*参数:
*功能描述: 外部中断函数
by:
**************************************************/
/*void INT1_Int(void) 
{

   TR0=1;
   while(DEMOD_OUT==0);
   TR0=0;
   if((TL0)>32)
   {
     
   }

}*/

⌨️ 快捷键说明

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