📄 main.c
字号:
#define __SRC
#include "main.h"
#undef __SRC
#include "zlg500B.h"
#define MF1_S50 0
#define MF1_S70 1
#define MF0_ULIGHT 2
#define MF1_LIGHT 3
sbit zlg500B_RST=P1^4;
uchar baud_num;
uchar card_snr[8];
void serial_init(void);
uchar code Nkey_a[6] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};
uchar code Nkey_b[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
main()
{
uchar cardtype=MF1_S50;
uchar i,j=40;
uchar databuf[16];
long value=1;
for(i=255;i>0;i--)
for(j=10;j>0;j--);
zlg500B_RST=0;
for(i=255;i>0;i--)
for(j=20;j>0;j--);
baud_num=2;
serial_init();
EA=1;
//i=mifs_config();
i=mifs_get_info(databuf);
// i=mifs_close();
// i=mifs_config();
// i=mifs_load_key(KEYA,15,Nkey_a);
i=mifs_load_key(KEYA,5,Nkey_b);
// i=mifs_read_E2(0x10,16,databuf);
// i=mifs_read_E2(0x20,16,databuf);
// databuf[0]=0x58;
// i=mifs_write_E2(0x11,1,databuf);
i=mifs_write_reg(0x11,0x59);
i=mifs_write_reg(0x12,0x01); //这两个函数可将读卡距离最短,功耗最低
while(1)
{
while(mifs_request(IDLE,databuf)!=MI_OK);
if(mifs_cascanticoll(ANTICOLL1,0,card_snr)!=MI_OK) continue;
if(mifs_cascselect(ANTICOLL1,card_snr,&i)!=MI_OK) continue;
if(i&0x04)
{
if(mifs_cascanticoll(ANTICOLL2,0,card_snr+4)!=MI_OK) continue;
if(mifs_cascselect(ANTICOLL2,card_snr+4,&i)!=MI_OK) continue;
}
if(cardtype == MF1_S50)
{
if(mifs_authentication(KEYA,5)!=0) continue;
databuf[0]=0x10;
databuf[4]=~0x10;
databuf[8]=0x10;
for(i=1;i<4;i++)
{
databuf[i]=0x00;
databuf[4+i]=0xff;
databuf[8+i]=0x00;
}
databuf[12]=0x14;
databuf[13]=~0x14;
databuf[14]=0x14;
databuf[15]=~0x14;
if(mifs_write(0x14,databuf)!=0) continue;
databuf[0]=0;
if(mifs_read(0x14,databuf)!=0) continue;
value=1;
if(mifs_value(PICC_DECREMENT,0x14,&value,0x15)!=0) continue;
if(mifs_read(0x15,databuf)!=0) continue;
if(mifs_value(PICC_INCREMENT,0x14,&value,0x16)!=0) continue;
if(mifs_read(0x16,databuf)!=0) continue;
}
else if(cardtype == MF1_S70)
{
if(mifs_authentication2(KEYA,39,5)!=0) continue;
if(mifs_read(240,databuf)!=0) continue;
}
else if(cardtype == MF0_ULIGHT)
{
databuf[0]=0x11;
databuf[1]=0x22;
databuf[2]=0x33;
databuf[3]=0x44;
if(mifs_ULwrite(15,databuf)!=0) continue;
databuf[0]=0x00;
databuf[1]=0x00;
databuf[2]=0x00;
databuf[3]=0x00;
if(mifs_read(15,databuf)!=0) continue;
}
else if(cardtype == MF1_LIGHT)
{
if(mifs_authKey(KEYA,2,Nkey_b)!=0) continue;
databuf[0]=0x10;
databuf[1]=0x00;
databuf[2]=0xef;
databuf[3]=0xff;
if(mifs_write(4,databuf)!=0) continue;
databuf[0]=0xff;
databuf[1]=0xff;
databuf[2]=0xff;
databuf[3]=0xff;
if(mifs_write(5,databuf)!=0) continue;
if(mifs_read(4,databuf)!=0) continue;
if(databuf[0]!=~databuf[2] || databuf[1]!=~databuf[3])
continue;
value=1;
if(mifs_valuedebit(0xc0,4,&value)!=0) continue;
if(mifs_read(4,databuf)!=0) continue;
}
mifs_halt();
// mifs_reset(1);
// i=mifs_write_E2(0x30,16,databuf);
// if(i!=0) continue;
mifs_clr_control_bit();
mifs_buzzer(250,20,10,3);
while(mifs_set_control_bit()!=0);
}
}
/****************************************************************************
* *
* Function: serial_init *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void serial_init (void)
{
PCON = 0x80; // SMOD = 1;
SCON = 0x50; // Mode 1, 8-bit UART, enable receiption
TMOD&=0x0f;
TMOD|=0x20; // Timer 1, mode 2, 8-bit auto reload,
switch(baud_num)
{
case 0: TH1=BAUD_2400; break;
case 1: TH1=BAUD_4800; break;
case 2: TH1=BAUD_9600; break;
case 3: TH1=BAUD_19200; break;
case 4: TH1=BAUD_28800; break;
case 5: TH1=BAUD_57600; break;
}
CON_485=0;
ES = 1;
ET1 = 0;
TR1 = 1;
}
#pragma noaregs
/****************************************************************************
* *
* Function: delay_50us *
* *
* Input: _50us *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 50 us. *
* *
****************************************************************************/
void delay_50us (uchar _50us)
{
RCAP2LH = RCAP2_50us;
T2LH = RCAP2_50us;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_50us--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
/****************************************************************************
* *
* Function: delay_1ms *
* *
* Input: _1ms *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 1 ms. *
* *
****************************************************************************/
void delay_1ms (uint _1ms)
{
RCAP2LH = RCAP2_1ms;
T2LH = RCAP2_1ms;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_1ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
/****************************************************************************
* *
* Function: delay_10ms *
* *
* Input: _10ms *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 10 ms. *
* *
****************************************************************************/
void delay_10ms (uint _10ms)
{
RCAP2LH = RCAP2_10ms;
T2LH = RCAP2_10ms;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_10ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
#pragma aregs
/***************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -