📄 main.c
字号:
///////////////////////////////////////////////////////////////////////////
/*************************************************************************/
#include <string.h>
#include <m500a.h>
#include <main.h>
#include <reg52.h>
sbit LED = P2^6;
sbit WARN = P2^7;
unsigned char length = 0,type = 1;
unsigned char rcvdata[16] = {" "};
unsigned char timerout = 0;
////////////////////////////////////////////////////////////////////
void main (void)
{
// unsigned char counter;
unsigned char status1,x;
unsigned char Snr_RC500[4]; // Serial Number of the MFRC500
unsigned char cardserialno[4];
unsigned char cardtype[2];
P2 = 0x00;
LED = 1;WARN = 1;
init_lcd();
clrram();
timer_init();
rs232_init();
line_disp(0,"*** 考勤系统 ***");
line_disp(1,"----------------");
line_disp(2,"-- 指导老师 --");
line_disp(3," 刘盾 副教授 ");
RC500Config();
PcdReadE2(8,4,Snr_RC500);
// rs232_send(Snr_RC500,4);
delay_1s(1200);
clrram();
time_disp1(0);
line_disp(1,"----------------");
line_disp(2," 初始完成 ");
line_disp(3,"----------------");
delay_1s(1200);
clrram();
time_disp2();
line_disp(2,"----------------");
line_disp(3," 请放入卡 ");
LED = 0;
while(1)
{
while(CardRequest(PICC_REQALL, cardtype)==MI_OK)
{
status1=ReadCardNum(0,cardserialno);
if (status1 == MI_OK)
{
rs232_send(cardserialno,4);
LED = 1;
clrram();
time_disp1(1);
line_disp(2,"----------------");
TL0 = 0; TH0 = 0; ET0 = 1; TR0 = 1;
while(type != 3)
{
if (timerout == 1)
{
TR0 = 0;ET0 = 0;
WARN = 0;LED = 1;
line_disp(0,"----------------");
line_disp(1,"请检查串口连接情");
line_disp(2,"况以及软件设置!");
line_disp(3,"----------------");
}
}
line_disp(1,rcvdata);
while(type != 1);line_disp(3,rcvdata);
TR0 = 0; ET0 = 0;
if(!strcmp(rcvdata,"数据库无此卡信息"))
{
WARN = 0;
delay_1s(1000);
WARN = 1;
}
for (x=0;x<16;x++)
rcvdata[x] = ' ';
}
delay_1s(500);
LED = 0;
delay_1s(500);
WARN = 1;
clrram();
time_disp2();
line_disp(2,"----------------");
line_disp(3," 请放入卡 ");
}
time_disp2();
delay_1s(50);
}
}
extern unsigned char sendflag;
void rs232_rev(void) interrupt 4
{
if ( TI == 1 )
{
TI = 0;
sendflag = 1;
}
if ( RI == 1 )
{
if (SBUF == 0x30)
{
type ++;
if (type == 4)
{
type = 1;
length = 0;
}
if( type == 2 )
length = 10;
else
length = 0;
}
else
rcvdata[length++] = SBUF;
RI = 0;
}
}
unsigned char count=50;
void timer0(void) interrupt 1
{
TH0 = 0; TL0 = 0;
count --;
if (!count)
{
timerout = 1;
count = 20;
}
else TR0 = 1;
}
//////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -