#include "reg52.h" #include "main.h" #include "mfrc522.h" #include <string.h> #include"X24C02.h" #include "LCD1602.h" #include "STCEEPROM.h" #define uchar unsigned char #define uint unsigned int sbit Speak = P2^7; sbit RED = P3^4; sbit GREEN = P3^3; sbit Relay = P3^2; sbit KEY1 = P1^3; sbit KEY2 = P1^4; sbit KEY3 = P1^5; sbit KEY4 = P1^6; sbit KEY5 = P1^7; unsigned char idata RevBuffer[30]; unsigned char Card_Num; void iccardcode(); //系统初始化 void InitializeSystem() { PcdReset(); PcdAntennaOff(); PcdAntennaOn(); M500PcdConfigISOType( 'A' ); } unsigned char idata UID[4],Temp[4]; unsigned char Table[3]; unsigned char Num; unsigned char Count,Countf,Count1,Count2,Count3,Count4,Count5,C_flag; void Auto_Reader(void) { if(PcdRequest(0x52,Temp)==0) { if(PcdAnticoll(UID)==0) { Speak=0;delay_10ms(20);Speak=1; Table[0]=UID[0]/100+0x30; Table[1]=UID[0]/10%10+0x30; Table[2]=UID[0]%10+0x30; LCD1602_Disp_ZF(0x80+0x40,"Num: ",16); LCD1602_Disp_ZF(0x84+0x40,Table,3); Count = UID[0]; if((Count==Count1)||(Count==Count2)||(Count==Count3)||(Count==Count4)||(Count==Count5)) { LCD1602_Disp_ZF(0x8a+0x40,"OK ",5); GREEN = 0;Relay=0;delay_10ms(200);Relay=1;GREEN = 1; C_flag=1; } else { LCD1602_Disp_ZF(0x8a+0x40,"Error",5); RED = 0;delay_10ms(200);RED = 1; C_flag=2; } delay_10ms(200); LCD1602_Disp_ZF(0x80+0x40,"Please Swipecard",16); } } } uchar DS1302_Table[7]={0}; //读取时间值 void Display_LCD2(uchar Dis_Hour,uchar Dis_Min,uchar Dis_Sec) { uchar Dis_Table[8]="11:22:33"; Dis_Table[0] = Dis_Hour/10+0x30; Dis_Table[1] = Dis_Hour%10+0x30; Dis_Table[3] = Dis_Min/10+0x30; Dis_Table[4] = Dis_Min%10+0x30; Dis_Table[6] = Dis_Sec/10+0x30; Dis_Table[7] = Dis_Sec%10+0x30; LCD1602_Disp_ZF(0x85,Dis_Table,8); } void main(void) { unsigned char i; InitializeSystem(); LCD1602_init(); x24c02_init(); //Money_1=x24c02_read(0X01); //x24c02_write(0X03,Money_3); LCD1602_Disp_ZF(0x80,"Time:",5); //0123456789abcdef LCD1602_Disp_ZF(0x80+0x40,"Please Swipecard",16); //LCD1602_Disp_ZF(0x80+0x40,"Num:",4); //ISP_ERASE(0x2c00); //注意:字节编程时必须要先要擦除整个扇区 //for(i=0;i<255;i++) // ISP_PROGRAM(0x2c00+i, 0x00); Countf=ISP_READ(0x2c00); Count1=ISP_READ(0x2c01); Count2=ISP_READ(0x2c02); Count3=ISP_READ(0x2c03); Count4=ISP_READ(0x2c04); Count5=ISP_READ(0x2c05); while (1) { //////////////////////////////// iccardcode(); Auto_Reader(); //////////////////////////////// Run_DS1302(); //delay_10ms(200); if(!KEY1) { delay_10ms(50); if(!KEY1) { DS1302_Table[4]++; Write_DS1302Init(0,0,0,0,DS1302_Table[4],DS1302_Table[5],0); } } if(!KEY2) { delay_10ms(50); if(!KEY2) { DS1302_Table[4]--; Write_DS1302Init(0,0,0,0,DS1302_Table[4],DS1302_Table[5],0); } } ////////////////////////////////// if(!KEY3) { delay_10ms(50); if(!KEY3) { DS1302_Table[5]++; Write_DS1302Init(0,0,0,0,DS1302_Table[4],DS1302_Table[5],0); } } if(!KEY4) { delay_10ms(50); if(!KEY4) { DS1302_Table[5]--; Write_DS1302Init(0,0,0,0,DS1302_Table[4],DS1302_Table[5],0); } } if(!KEY5) { delay_10ms(50); if(!KEY5) { if(C_flag==2) { //0123456789abcdef LCD1602_Disp_ZF(0x80+0x40," Register Card! ",16); Countf++; if(Countf==6)Countf=1; if(Countf==1) Count1 = Count; if(Countf==2) Count2 = Count; if(Countf==3) Count3 = Count; if(Countf==4) Count4 = Count; if(Countf==5) Count5 = Count; } if(C_flag==1) { //0123456789abcdef LCD1602_Disp_ZF(0x80+0x40," Clean Card! ",16); if(Count==Count1)Count1=0; if(Count==Count2)Count2=0; if(Count==Count3)Count3=0; if(Count==Count4)Count4=0; if(Count==Count5)Count5=0; } Speak=0;delay_10ms(200);Speak=1; LCD1602_Disp_ZF(0x80+0x40,"Please Swipecard",16); ISP_ERASE(0x2c00); ISP_PROGRAM(0x2c00, Countf); ISP_PROGRAM(0x2c01, Count1); ISP_PROGRAM(0x2c02, Count2); ISP_PROGRAM(0x2c03, Count3); ISP_PROGRAM(0x2c04, Count4); ISP_PROGRAM(0x2c05, Count5); C_flag =0; while(!KEY5); } } ////////////////////// } } void iccardcode() { unsigned char cmd; unsigned char status; cmd = RevBuffer[0]; switch(cmd) { case 1: // Halt the card //终止卡的操作 status= PcdHalt();; RevBuffer[0]=1; RevBuffer[1]=status; break; case 2: // Request,Anticoll,Select,return CardType(2 bytes)+CardSerialNo(4 bytes) // 寻卡,防冲突,选择卡 返回卡类型(2 bytes)+ 卡系列号(4 bytes) status= PcdRequest(RevBuffer[1],&RevBuffer[2]); if(status!=0) { status= PcdRequest(RevBuffer[1],&RevBuffer[2]); if(status!=0) { RevBuffer[0]=1; RevBuffer[1]=status; break; } } RevBuffer[0]=3; RevBuffer[1]=status; break; case 3: MLastSelectedSnr status = PcdAnticoll(&RevBuffer[2]); if(status!=0) { RevBuffer[0]=1; RevBuffer[1]=status; break; } //memcpy(MLastSelectedSnr,&RevBuffer[2],4); RevBuffer[0]=5; RevBuffer[1]=status; break; case 4: // 选择卡 Select Card //status=PcdSelect(MLastSelectedSnr); if(status!=MI_OK) { RevBuffer[0]=1; RevBuffer[1]=status; break; } RevBuffer[0]=3; RevBuffer[1]=status; break; case 5: // Key loading into the MF RC500's EEPROM //status = PcdAuthState(RevBuffer[1], RevBuffer[3], DefaultKey, MLastSelectedSnr); RevBuffer[0]=1; RevBuffer[1]=status; break; case 6: RevBuffer[0]=1; RevBuffer[1]=status; break; case 7: RevBuffer[0]=1; RevBuffer[1]=status; break; case 8: // Read the mifare card status=PcdRead(RevBuffer[1],&RevBuffer[2]); if(status==0) {RevBuffer[0]=17;} else {RevBuffer[0]=1;} RevBuffer[1]=status; break; case 9: // Write the mifare card status=PcdWrite(RevBuffer[1],&RevBuffer[2]); RevBuffer[0]=1; RevBuffer[1]=status; break; case 10: PcdValue(RevBuffer[1],RevBuffer[2],&RevBuffer[3]); RevBuffer[0]=1; RevBuffer[1]=status; break; case 12: PcdBakValue(RevBuffer[1], RevBuffer[2]); RevBuffer[0]=1; //contact RevBuffer[1]=0; break; } }
|