|
#include "reg52.h"
#include "main.h"
#include "mfrc522.h"
#define DataPort P0 //定義數(shù)據(jù)端口
unsigned char UID[5],Temp[4];
unsigned char UID1[4]={188,96,184,121}; //鑰匙1
unsigned char UID2[4]={158,101,169,84};
unsigned char mn,num;
unsigned char KeyScan(void);//鍵盤掃描
sbit KEY1=P3^5;
sbit KEY2=P3^6;
sbit KEY3=P3^7;
void feeb() //蜂鳴器函數(shù)
{
ff=0;
delay_10ms(1);
ff=1;
delay_10ms(1);
}
void Auto_Reader(void)
{
while(1)
{
num=KeyScan();
switch(num)
{
case 1:LED6=1; break;//觸發(fā)KEY1關(guān)閉到位
case 2:LED6=1; break;
case 3:LED6=1; break;
default:break;
}
if(PcdRequest(0x52,Temp)==MI_OK) //尋卡,成功后Temp數(shù)組為卡類型
{
if(PcdAnticoll(UID)==MI_OK) //防沖突,UID數(shù)組數(shù)據(jù)為卡序列號(hào)
{
CALL_isr_UART(); //開串口中斷將UID數(shù)組前四個(gè)字節(jié)上傳到串口調(diào)試助手
feeb();
if (mn==4)
{
LED6=0;
mn=0;
}
}
}
}
}
void InitializeSystem() //祲始化
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;
SM0=0;
SM1=1;
EA=1;
ES=1;
PcdReset(); //復(fù)位RC522
PcdAntennaOff(); //關(guān)閉天線
PcdAntennaOn(); //開啟天線
M500PcdConfigISOType( 'A' ); //設(shè)置RC632的工作方式
}
void isr_UART(void) interrupt 4 using 1
{
unsigned char i;
if(TI)
{
TI=0;
for(i=0;i<4;i++)
{
SBUF=UID[i];
while(!TI);
TI=0;
if (UID[i]==UID1[i]||UID[i]==UID2[i])
{
mn++;
}
}
REN=1;
}
}
/*------------------------------------------------
按鍵掃描函數(shù),返回掃描鍵值
------------------------------------------------*/
unsigned char KeyScan(void)
{
if(!KEY1)
{
delay_10ms(1);
if(!KEY1)
{
while(!KEY1);
{
return 1;
}
}
}
else if(!KEY2)
{
delay_10ms(1);
if(!KEY2)
{
while(!KEY2);
{
return 2;
}
}
}
else if(!KEY3)
{
delay_10ms(1);
if(!KEY3)
{
while(!KEY3);
{
return 3;
}
}
}
return 0;
}
void main( )
{
InitializeSystem( );
Auto_Reader();
}
|
|