图上这几个定义的有的不是很懂,有的能够猜出来。还望大佬解答这几个定义的是什么
完成程序如下
#include "reg52.h"
#include "main.h"
#include "mfrc522.h"
#include <string.h>
#include "LCD1602.h"
#include "DS1302.h"
#include "STCEEPROM.h"
#define uchar unsigned char
#define uint unsigned int
sbit Speak = P2^7;
sbit RED = P3^3;
sbit GREEN = P3^4;
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);
}
/********************************************************************
* 名称 : Run_DS1302(void)
* 功能 : 读出DS1302中的数据,并进行显示
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Run_DS1302(void)
{
uchar sec, min, hour, day, month, week, year;
v_W1302(0x8f, 0);
sec = bcdtodec(uc_R1302(0x61)); //读出DS1302中的秒
v_W1302(0x8f, 0);
min = bcdtodec(uc_R1302(0x73)); //读出DS1302中的分
v_W1302(0x8f, 0);
hour = bcdtodec(uc_R1302(0x85)); //读出DS1302中的小时
v_W1302(0x8f, 0);
day = bcdtodec(uc_R1302(0x87)); //读出DS1302中的日
v_W1302(0x8f, 0);
month = bcdtodec(uc_R1302(0x89)); //读出DS1302中的月
v_W1302(0x8f, 0);
week = bcdtodec(uc_R1302(0x8b)); //读出DS1302中的星期
v_W1302(0x8f, 0);
year = bcdtodec(uc_R1302(0x8d)); //读出DS1302中的年
DS1302_Table[0]=year;
DS1302_Table[1]=month;
DS1302_Table[2]=day;
DS1302_Table[3]=week;
DS1302_Table[4]=hour;
DS1302_Table[5]=min;
DS1302_Table[6]=sec;
Display_LCD2(DS1302_Table[4],DS1302_Table[5],DS1302_Table[6]);
}
void main(void)
{
InitializeSystem();
LCD1602_init();
LCD1602_Disp_ZF(0x80,"Time:",5);
//0123456789abcdef
LCD1602_Disp_ZF(0x80+0x40,"Please Swipecard",16);
Countf=ISP_READ(0x2c00);
Count1=ISP_READ(0x2c01);
Count2=ISP_READ(0x2c02);
Count3=ISP_READ(0x2c04);
Count4=ISP_READ(0x2c06);
Count5=ISP_READ(0x2c08);
while (1)
{
////////////////////////////////
iccardcode();
Auto_Reader();
////////////////////////////////
Run_DS1302();
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! ",12);
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! ",11);
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",10);
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[1]);
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]=2;
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]=34;
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[7],&RevBuffer[3]);
RevBuffer[0]=1;
RevBuffer[1]=status;
break;
case 12: // 参数设置
PcdBakValue(RevBuffer[1], RevBuffer[2]);
RevBuffer[0]=1; //contact
RevBuffer[1]=0;
break;
}
}
|