#include<reg51.h>
#include <string.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
/////////////////////////////////////////////////////////////////////
//MF522Ãüáî×Ö
/////////////////////////////////////////////////////////////////////
#define PCD_IDLE 0x00 //è¡Ïûμ±Ç°Ãüáî
#define PCD_AUTHENT 0x0E //ÑéÖ¤ÃüÔ¿
#define PCD_RECEIVE 0x08 //½óêÕêy¾Y
#define PCD_TRANSMIT 0x04 //·¢Ëíêy¾Y
#define PCD_TRANSCEIVE 0x0C //·¢Ëí2¢½óêÕêy¾Y
#define PCD_RESETPHASE 0x0F //¸′λ
#define PCD_CALCCRC 0x03 //CRC¼ÆËã
/////////////////////////////////////////////////////////////////////
//Mifare_One¿¨Æ¬Ãüáî×Ö
/////////////////////////////////////////////////////////////////////
#define PICC_REQIDL 0x26 //Ñ°ììÏßÇøÄúÎ′½øèëDYÃß×′ì¬
#define PICC_REQALL 0x52 //Ñ°ììÏßÇøÄúè«2¿¿¨
#define PICC_ANTICOLL1 0x93 //·à3å×2
#define PICC_ANTICOLL2 0x95 //·à3å×2
#define PICC_AUTHENT1A 0x60 //ÑéÖ¤AÃüÔ¿
#define PICC_AUTHENT1B 0x61 //ÑéÖ¤BÃüÔ¿
#define PICC_READ 0x30 //¶á¿é
#define PICC_WRITE 0xA0 //D′¿é
#define PICC_DECREMENT 0xC0 //¿Û¿î
#define PICC_INCREMENT 0xC1 //3äÖμ
#define PICC_RESTORE 0xC2 //μ÷¿éêy¾Yμ½»o3åÇø
#define PICC_TRANSFER 0xB0 //±£′æ»o3åÇøÖDêy¾Y
#define PICC_HALT 0x50 //DYÃß
/////////////////////////////////////////////////////////////////////
//MF522 FIFO3¤¶è¶¨òå
/////////////////////////////////////////////////////////////////////
#define DEF_FIFO_LENGTH 64 //FIFO size=64byte
#define MAXRLEN 18
/////////////////////////////////////////////////////////////////////
//MF522¼Ä′æÆ÷¶¨òå
/////////////////////////////////////////////////////////////////////
// PAGE 0
#define RFU00 0x00
#define CommandReg 0x01
#define ComIEnReg 0x02
#define DivlEnReg 0x03
#define ComIrqReg 0x04
#define DivIrqReg 0x05
#define ErrorReg 0x06
#define Status1Reg 0x07
#define Status2Reg 0x08
#define FIFODataReg 0x09
#define FIFOLevelReg 0x0A
#define WaterLevelReg 0x0B
#define ControlReg 0x0C
#define BitFramingReg 0x0D
#define CollReg 0x0E
#define RFU0F 0x0F
// PAGE 1
#define RFU10 0x10
#define ModeReg 0x11
#define TxModeReg 0x12
#define RxModeReg 0x13
#define TxControlReg 0x14
#define TxAutoReg 0x15
#define TxSelReg 0x16
#define RxSelReg 0x17
#define RxThresholdReg 0x18
#define DemodReg 0x19
#define RFU1A 0x1A
#define RFU1B 0x1B
#define MifareReg 0x1C
#define RFU1D 0x1D
#define RFU1E 0x1E
#define SerialSpeedReg 0x1F
// PAGE 2
#define RFU20 0x20
#define CRCResultRegM 0x21
#define CRCResultRegL 0x22
#define RFU23 0x23
#define ModWidthReg 0x24
#define RFU25 0x25
#define RFCfgReg 0x26
#define GsNReg 0x27
#define CWGsCfgReg 0x28
#define ModGsCfgReg 0x29
#define TModeReg 0x2A
#define TPrescalerReg 0x2B
#define TReloadRegH 0x2C
#define TReloadRegL 0x2D
#define TCounterValueRegH 0x2E
#define TCounterValueRegL 0x2F
// PAGE 3
#define RFU30 0x30
#define TestSel1Reg 0x31
#define TestSel2Reg 0x32
#define TestPinEnReg 0x33
#define TestPinValueReg 0x34
#define TestBusReg 0x35
#define AutoTestReg 0x36
#define VersionReg 0x37
#define AnalogTestReg 0x38
#define TestDAC1Reg 0x39
#define TestDAC2Reg 0x3A
#define TestADCReg 0x3B
#define RFU3C 0x3C
#define RFU3D 0x3D
#define RFU3E 0x3E
#define RFU3F 0x3F
uchar CardRevBuf[16];
/////////////////////////////////////////////////////////////////////
#define MI_NOTAGERR (-1)
#define MI_ERR (-2)
/////////òo¾§¶Ë¿ú/////////////////////////
sbit rs=P1^0;
sbit en=P1^1;
/////////¿¨½óÏ߶˿ú//////////////////////////////
sbit spi_cs=P2^4;
sbit spi_ck=P2^3;
sbit spi_mosi=P2^2;
sbit spi_miso=P2^1;
sbit spi_rst=P2^0;
/////′æ′¢Æ÷½ó¿ú////////////////////
sbit scl=P1^2;
sbit sda=P1^3;
//////°′¼ü½ó¿ú///////////////////////////
sbit key1=P2^5;
sbit key2=P2^6;
///////////////////////////////////
sbit jdq=P1^6;//¼ìμçÆ÷¶Ë¿ú
sbit beep=P1^4;//oìé«
sbit led=P1^5;
unsigned char code table[]={"0123456789abcdef"};
uchar code tab1[]={"Has been stored!"};//òÑ′æ′¢
uchar code tab2[]={" NO Card! "};//ÎT¿¨
uchar ka;//¼ÇÏ¿¨′æ′¢μÄêyá¿
uchar ka1,ka2,ka3,ka4;
uchar time;
//oáÃëÑóê±**************************
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
for(j=0;j<10;j++);
}
void yj1602_write_com(uchar com) //òo¾§D′μØÖ·
{
en=0;delay(1);
en=1;delay(1);
rs=0;delay(1);
P0=com;
en=0;delay(1);
}
void yj1602_write_date(uchar date) //òo¾§D′êy¾Y
{
en=0;delay(1);
en=1;delay(1);
rs=1;delay(1);
P0=date;
en=0;delay(1);
}
void yj1602_init() //òo¾§3õê¼»ˉ
{
yj1602_write_com(0x38);
yj1602_write_com(0x0c);
yj1602_write_com(0x06);
yj1602_write_com(0x01);
}
//°′Ö¸¶¨Î»ÖÃÏÔê¾ò»¸ö×Ö·û
void DisplayOneChar(uchar y, uchar x, uchar dat)
{
y&= 0x1;
x&= 0xF; //ÏTÖÆX2»Äü′óóú15£¬Y2»Äü′óóú1
if (y)x|= 0x40; //μ±òaÏÔê¾μú¶tDDê±μØÖ·Âë+0x40;
x|=0x80; // Ëã3öÖ¸áîÂë
yj1602_write_com(x); //
yj1602_write_date(dat);
}
//°′Ö¸¶¨Î»ÖÃÏÔê¾ò»′®×Ö·û
void display_c(uchar y, uchar x, char *dat)
{
y&= 0x1;
x&= 0xF; //ÏTÖÆX2»Äü′óóú15£¬Y2»Äü′óóú1
while (*dat!='\0') //èôμ½′ï×Ö′®Î2ÔòíË3ö
{
if (y<= 0xF) //X×ø±êó|D¡óú0xF
{
DisplayOneChar(y,x,*dat); //ÏÔê¾μ¥¸ö×Ö·û
dat++;
x++;
}
}
}
void display_id(uchar *SrcBuf)
{
char DisplayBuf[10];
char *pDisplayChar;
uchar Tmp, i;
pDisplayChar = DisplayBuf;
for( i = 0; i < 4; i++ )
{
Tmp = ( ( *SrcBuf ) >> 4 ) & 0x0F;
if( ( Tmp >=0 ) && ( Tmp <= 9 ) )
{
*pDisplayChar ++ = '0' + Tmp;
}
else
{
*pDisplayChar ++ = 'A' + Tmp - 10;
}
Tmp = ( *SrcBuf ) & 0x0F;
if( ( Tmp >=0 ) && ( Tmp <= 9 ) )
{
*pDisplayChar ++ = '0' + Tmp;
}
else
{
*pDisplayChar ++ = 'A' + Tmp - 10;
}
SrcBuf ++;
}
*pDisplayChar ++ = '\0';
display_c( 0,4,DisplayBuf );
}
void delay_ns(uint ns)
{
uint i;
for(i=0;i<ns;i++)_nop_();
}
uchar SPIReadByte()// ¶áSPIêy¾Y
{
uchar i; // Counter used to clock out the data
uchar dat;
// dat=0;
for(i=0;i<8;i++) // Prepare to clock in the data to be read
{
dat<<=1; // Rotate the data
spi_ck=0; // Raise the clock to clock the data out of the MAX7456
if(spi_miso)dat|=0x01;
spi_ck=1; // Drop the clock ready for the next bit
} // and loop back
return dat; // Finally return the read data
}
void SPIWriteByte(uchar dat)// D′SPIêy¾Y
{
uchar i; // Counter used to clock out the data
for(i=0;i<8;i++)
{
if(dat&0x80)spi_mosi=1;
else spi_mosi=0;
_nop_();_nop_();
spi_ck=0;_nop_();_nop_();
spi_ck=1;_nop_();_nop_();
dat<<=1;
}
}
uchar ReadRawRC(uchar address)//¶áRC632¼Ä′æÆ÷Address[IN]:¼Ä′æÆ÷μØÖ·
{
uchar ucAddr;
uchar ucResult=0;
spi_cs=0;
ucAddr=((address<<1)&0x7E)|0x80;
SPIWriteByte(ucAddr);
ucResult=SPIReadByte();
spi_cs=1;
return ucResult;
}
void WriteRawRC(uchar address,uchar value)//D′RC632¼Ä′æÆ÷Address[IN]:¼Ä′æÆ÷μØÖ·
{
uchar ucAddr;
spi_cs=0;
ucAddr = ((address<<1)&0x7E);
SPIWriteByte(ucAddr);
SPIWriteByte(value);
spi_cs=1;
}
void ClearBitMask(uchar reg,uchar mask)//ÇåRC522¼Ä′æÆ÷λreg[IN]:¼Ä′æÆ÷μØÖ·mask[IN]:ÇåλÖμ
{
char tmp = 0x00;
tmp = ReadRawRC(reg);
WriteRawRC(reg, tmp & ~mask); // clear bit mask
}
void SetBitMask(uchar reg,uchar mask) //ÖÃRC522¼Ä′æÆ÷λ reg[IN]:¼Ä′æÆ÷μØÖ· mask[IN]:ÖÃλÖμ
{
char tmp = 0x00;
tmp = ReadRawRC(reg);
WriteRawRC(reg,tmp | mask); // set bit mask
}
void CalulateCRC(uchar *pIndata,uchar len,uchar *pOutData)//óÃMF522¼ÆËãCRC16oˉêy
{
unsigned char i,n;
ClearBitMask(0x05,0x04);
WriteRawRC(0x01,0x00);//è¡Ïûμ±Ç°Ãüáî
SetBitMask(0x0a,0x80);
for (i=0; i<len; i++)
{ WriteRawRC(0x09, *(pIndata+i)); }
WriteRawRC(0x01,0x03);////CRC¼ÆËã
i = 0xFF;
do
{
n= ReadRawRC(0x05);
i--;
}
while ((i!=0) && !(n&0x04));
pOutData[0] = ReadRawRC(0x22);
pOutData[1] = ReadRawRC(0x21);
}
//1| Äü£oí¨1yRC522oíISO14443¿¨í¨Ñ¶
//2ÎêyËμÃ÷£oCommand[IN]:RC522Ãüáî×Ö
// pInData[IN]:í¨1yRC522·¢Ëíμ½¿¨Æ¬μÄêy¾Y
// InLenByte[IN]:·¢Ëíêy¾YμÄ×Ö½ú3¤¶è
// pOutData[OUT]:½óêÕμ½μÄ¿¨Æ¬·μ»Øêy¾Y
// *pOutLenBit[OUT]:·μ»Øêy¾YμÄλ3¤¶è
char PcdComMF522(uchar Command,uchar *pInData,uchar InLenByte,uchar *pOutData,uint *pOutLenBit)
{
char status=MI_ERR;
uchar irqEn=0x00;
uchar waitFor=0x00;
uchar lastBits;
uchar n;
uint i;
switch (Command)
{
case 0x0E://ÑéÖ¤ÃüÔ¿
irqEn=0x12;
waitFor=0x10;
break;
case 0x0C://·¢Ëí2¢½óêÕêy¾Y
irqEn=0x77;
waitFor=0x30;
break;
default:
break;
}
WriteRawRC(0x02,irqEn|0x80);
ClearBitMask(0x04,0x80);
WriteRawRC(0x01,0x00);
SetBitMask(0x0a,0x80);
for (i=0;i<InLenByte;i++){WriteRawRC(0x09, pInData[i]);}
WriteRawRC(0x01,Command);
if (Command == 0x0c)//·¢Ëí2¢½óêÕêy¾Y
{SetBitMask(0x0d,0x80);}
//i = 600;//¸ù¾Yê±ÖóÆμÂêμ÷Õû£¬2ù×÷M1¿¨×î′óμè′yê±¼ä25ms
i = 2000;
do
{
n = ReadRawRC(0x04);
i--;
}
while ((i!=0) && !(n&0x01) && !(n&waitFor));
ClearBitMask(0x0d,0x80);
if (i!=0)
{
if(!(ReadRawRC(0x06)&0x1B))
{
status = 0;
if (n & irqEn & 0x01)
{ status = MI_NOTAGERR; }
if (Command == PCD_TRANSCEIVE)
{
n = ReadRawRC(FIFOLevelReg);
lastBits = ReadRawRC(ControlReg) & 0x07;
if (lastBits)
{
*pOutLenBit = (n-1)*8 + lastBits;
}
else
{
*pOutLenBit = n*8;
}
if (n == 0)
{
n = 1;
}
if (n > MAXRLEN)
{
n = MAXRLEN;
}
for (i=0; i<n; i++)
{
pOutData[i] = ReadRawRC(FIFODataReg);
}
}
}
else
{
status = MI_ERR;
}
}
SetBitMask(ControlReg,0x80); // stop timer now
WriteRawRC(CommandReg,PCD_IDLE);
return status;
}
//2ÎêyËμÃ÷: req_code[IN]:Ñ°¿¨·½ê½
// 0x52 = Ñ°¸Dó|ÇøÄúËùóD·ûoÏ14443A±ê×¼μÄ¿¨
// 0x26 = Ñ°Î′½øèëDYÃß×′ì¬μÄ¿¨
// pTagType[OUT]£o¿¨Æ¬ààDí′úÂë
// 0x4400 = Mifare_UltraLight
// 0x0400 = Mifare_One(S50)
// 0x0200 = Mifare_One(S70)
// 0x0800 = Mifare_Pro(X)
// 0x4403 = Mifare_DESFire
//·μ »Ø: 3é1|·μ»Ø0
/////////////////////////////////////////////////////////////////////
char PcdRequest(uchar req_code,uchar *pTagType)
{
char status;
uint unLen;
uchar ucComMF522Buf[MAXRLEN];
ClearBitMask(Status2Reg,0x08);
WriteRawRC(BitFramingReg,0x07);
SetBitMask(TxControlReg,0x03);
ucComMF522Buf[0] = req_code;
status = PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,1,ucComMF522Buf,&unLen);
if ((status ==0) && (unLen == 0x10))
{
*pTagType = ucComMF522Buf[0];
*(pTagType+1) = ucComMF522Buf[1];
}
else
{
status = MI_ERR;
}
return status;
}
char PcdAnticoll(unsigned char *pSnr)//·à3å×2pSnr[OUT]:¿¨Æ¬DòáDoÅ£¬4×Ö½ú 3é1|·μ»Ø0
{
char status;
unsigned char i,snr_check=0;
unsigned int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ClearBitMask(Status2Reg,0x08);
WriteRawRC(BitFramingReg,0x00);
ClearBitMask(CollReg,0x80);
ucComMF522Buf[0] = PICC_ANTICOLL1;
ucComMF522Buf[1] = 0x20;
status = PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,2,ucComMF522Buf,&unLen);
if (status ==0)
{
for (i=0; i<4; i++)
{
*(pSnr+i) = ucComMF522Buf[i];
snr_check ^= ucComMF522Buf[i];
}
if (snr_check != ucComMF522Buf[i])
{
status = MI_ERR;
}
}
SetBitMask(CollReg,0x80);
return status;
}
char PcdSelect(unsigned char *pSnr)//Ñ¡¶¨¿¨Æ¬pSnr[IN]:¿¨Æ¬DòáDoÅ£¬4×Ö½ú3é1|·μ»Ø0
{
char status;
unsigned char i;
unsigned int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = PICC_ANTICOLL1;
ucComMF522Buf[1] = 0x70;
ucComMF522Buf[6] = 0;
for (i=0; i<4; i++)
{
ucComMF522Buf[i+2] = *(pSnr+i);
ucComMF522Buf[6] ^= *(pSnr+i);
}
CalulateCRC(ucComMF522Buf,7,&ucComMF522Buf[7]);
ClearBitMask(Status2Reg,0x08);
status = PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,9,ucComMF522Buf,&unLen);
if ((status == 0) && (unLen == 0x18))
{
status =0;
}
else
{
status = MI_ERR;
}
return status;
}
char PcdReset(void)//¸′λRC5223é1|·μ»Ø0
{
spi_rst=1;
delay_ns(10);
spi_rst=0;
delay_ns(10);
spi_rst=1;
delay_ns(10);
WriteRawRC(CommandReg,PCD_RESETPHASE);
delay_ns(10);
WriteRawRC(ModeReg,0x3D); //oíMifare¿¨í¨Ñ¶£¬CRC3õê¼Öμ0x6363
WriteRawRC(TReloadRegL,30);
WriteRawRC(TReloadRegH,0);
WriteRawRC(TModeReg,0x8D);
WriteRawRC(TPrescalerReg,0x3E);
WriteRawRC(TxAutoReg,0x40);//±ØDëòa
return 0;
}
void PcdAntennaOn(void)//ÿ′ÎÆô¶ˉ»ò1رÕììÏÕ·¢éäÖ®¼äó|ÖáéùóD1msμļä¸ô
{
unsigned char i;
i = ReadRawRC(TxControlReg);
if (!(i & 0x03))
{
SetBitMask(TxControlReg, 0x03);
}
}
char M500PcdConfigISOType(unsigned char type)//éèÖÃRC632μÄ1¤×÷·½ê½
{
if (type == 'A') //ISO14443_A
{
ClearBitMask(Status2Reg,0x08);
WriteRawRC(ModeReg,0x3D);//3F
WriteRawRC(RxSelReg,0x86);//84
WriteRawRC(RFCfgReg,0x7F); //4F
WriteRawRC(TReloadRegL,30);//tmoLength);// TReloadVal = 'h6a =tmoLength(dec)
WriteRawRC(TReloadRegH,0);
WriteRawRC(TModeReg,0x8D);
WriteRawRC(TPrescalerReg,0x3E);
delay_ns(1000);
PcdAntennaOn();
}
else{ return -1; }
return 0;
}
void PcdAntennaOff()//1رÕììÏß
{
ClearBitMask(TxControlReg, 0x03);
}
void init_rc522()
{
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
M500PcdConfigISOType( 'A' );
}
//AT24C02¶áD′2ù×÷ê±Dò
void delay_us()
{;;}
void iic_init()//3õê¼»ˉ
{
sda=1;delay_us();
scl=1;delay_us();
}
void start()//¿aê¼
{
sda=1;delay_us();
scl=1;delay_us();
sda=0;delay_us();
}
void response()//ó|′e
{
uchar i=0;
scl=1;delay_us();
while((sda==1)&&(i<250))i++;
scl=0;delay_us();
}
void stop()//í£Ö1
{
sda=0;delay_us();
scl=1;delay_us();
sda=1;delay_us();
}
uchar read_byte()//¶á×Ö½ú
{
uchar i,date;
scl=0;delay_us();
sda=1;delay_us();
for(i=0;i<8;i++)
{
scl=1;delay_us();
date=(date<<1)|sda;
scl=0;delay_us();
}
return date;
}
void write_byte(uchar date)//D′×Ö½ú
{
uchar i;
for(i=0;i<8;i++)
{
date=date<<1;
scl=0;delay_us();
sda=CY;delay_us();
scl=1;delay_us();
}
scl=0;delay_us();
sda=1;delay_us();
}
void write_add(uchar add,uchar date)//D′êy¾Y
{
start();
write_byte(0xa0);
response();
write_byte(add);
response();
write_byte(date);
response();
stop();
}
uchar read_add(uchar add)//¶áêy¾Y
{
uchar date;
start();
write_byte(0xa0);
response();
write_byte(add);
response();
start();
write_byte(0xa1);
response();
date=read_byte();
stop();
return date;
}
void init_iic_data()//3õê¼»ˉiic′æ′¢êy¾Y
{
write_add(0,1);delay(15);//D′êy¾Y
write_add(1,0);delay(15);//¿¨oÅ1
write_add(2,0);delay(15);
write_add(3,0);delay(15);//¿¨oÅ2
write_add(4,0);delay(15);
write_add(13,0);delay(15);//¿¨′æ′¢μÄêyá¿
}
void didi()//μÎμÎéù
{
beep=0;delay(1000);
beep=1;delay(1000);
}
void keyscan()
{
uchar j,k;
uchar j1,k1;
if(key1==0)//°′¼ü°′ÏÂ
{
delay(10);//Ñóê±Ïû3y°′¼ü¶¶¶ˉ
if(key1==0)//°′¼üè·êμ°′ÏÂ
{
didi();//μÎμÎéù
ka=read_add(13);//¶á3ö¿¨êy
ka++;
write_add(13,ka);delay(15);//D′êy¾Y
j=CardRevBuf[2]/16;
k=CardRevBuf[2]%16;
if(ka==1)
{
write_add(1,j);delay(15);//D′êy¾Y
write_add(2,k);delay(15);//D′êy¾Y
}
if(ka==2)
{
write_add(3,j);delay(15);//D′êy¾Y
write_add(4,k);delay(15);//D′êy¾Y
}
if(ka>=3)
{
ka=3;
j1=read_add(3);
k1=read_add(4);
write_add(1,j1);delay(15);//D′êy¾Y
write_add(2,k1);delay(15);//D′êy¾Y
write_add(3,j);delay(15);//D′êy¾Y
write_add(4,k);delay(15);//D′êy¾Y
}
display_c(1,0,"Has been stored!");//òÑ′æ′¢
}while(key1==0);//μè′y°′¼üËéêÖ
}
}
void main()
{
uchar j,k;
iic_init();//′æ′¢Æ÷3õê¼»ˉ
j=read_add(0);
if(j!=1)init_iic_data();//3õê¼»ˉiic′æ′¢êy¾Y
TMOD=0x01;//¶¨ê±Ä£ê½0
TH0=(65536-50000)/256;//×°3õÖμ50000us
TL0=(65536-50000)%256;
EA=1;//¿aÆô×üÖD¶Ï
ET0=1;
TR0=1;
yj1602_init();//òo¾§3õê¼»ˉ
init_rc522();
display_c( 0, 0, " ID:");
while(1)
{ //#define PICC_REQIDL 0x26//Ñ°ììÏßÇøÄúÎ′½øèëDYÃß×′ì¬
PcdRequest(0x26,&CardRevBuf[0]);
PcdAnticoll(&CardRevBuf[2]);
PcdSelect(&CardRevBuf[2]);//return;Ñ¡¿¨
if(CardRevBuf[2]==0)
{
display_c(0,0," ID: ");
display_c(1,0," Close! ");
}
if(CardRevBuf[2]!=0)
{
time=0;
display_id(&CardRevBuf[2] );
ka=read_add(13);//¶á3ö¿¨êy
if(ka>0)//òÑ′æè뿨
{
j=CardRevBuf[2]/16;
k=CardRevBuf[2]%16;
ka1=read_add(1);
ka2=read_add(2);
ka3=read_add(3);
ka4=read_add(4);
//Ë¢¿¨Ö®oó½øDDò»¸ö¿¨oÅóë′æμ½μ¥Ƭ»úμÄ¿¨oÅ×ö¶Ô±è£¬¶Ôó|Ôò′ò¿a
if(((ka1==j)&&(ka2==k))||((ka3==j)&&(ka4==k)))
{
if(jdq==1&&led==1) didi();//μÎμÎéù
jdq=0;
led=0;
display_c(1,0," Jhon ");
display_c(1,0," Open! ");
}
else
{
didi();//μÎμÎéù
display_c(1,0," NO Card! ");
}
}
if(ka==0)display_c(1,0," NO Card! ");didi();
keyscan();//°′¼üé¨Ãèoˉêy
while(PcdSelect(&CardRevBuf[2])>0)time=0;CardRevBuf[2]=0;
}
if(key2==0)//°′¼ü°′ÏÂ
{
delay(10);//Ñóê±Ïû3y°′¼ü¶¶¶ˉ
if(key2==0)//°′¼üè·êμ°′ÏÂ
{
init_iic_data();//3õê¼»ˉiic′æ′¢êy¾Y
display_c(1,0," cleared! ");//òÑÇå3ycleared
}while(key2==0);//μè′y°′¼üËéêÖ
}
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;//1ms¼Æê±
TL0=(65536-50000)%256;
time++;
if(time>15)
{
time=0;
jdq=1;
led=1;
}
}
|