#include "sys.h"
#include "delay.h"
#include "lcd.h"
#include "led.h"
#include "usart.h"
#include "dht11.h"
#include "key.h"
#include "beep.h"
#include
#include "stmflash.h"
#include "timer.h"
#include "exit.h"
#include "rc522.h"
void show1(void);
void show2(void);
void show3(void);
void show4(void);
void show5(void);
void show21(void);
void show31(void);
void show8(void);
u8 read_up=1;
u8 set1=1;
/*这三个标志位是用于按键的扫描程序*/
u8 key0_flag=0;
u8 key1_flag=0;
u8 key2_flag=0;
u8 beep_switch=0;
u8 beep_num=0;
u8 beepup_num=0;
u8 open_flag=0;
u8 down_flag=0;
u8 err_beepnum=0;
u8 table1[]="Please Bash Card";
u8 table11[]=" (()) ";
u8 table2[]=" Register Mode ";
u8 table22[]=" (()) ";
u8 table222[]="Register Success";
u8 table3[]=" Clear Mode ";
u8 table33[]=" Logout Success ";
u8 table5[]=" Door open ";
u8 table6[]=" Door close ";
u8 table8[]=" Dead Lock s ";
u8 err_num=0;
u8 eee_flag=0;
int kg_flag=0;//定时器4累加标志位,用于当RFID扫描到了并对门做出了相应的动作后,返回到扫描ID卡的计时标志位
u8 tim2_flag=0;//定时器2累加标志位,用于当按键按下之后,并完成了注册或注销卡之后,返回到扫描ID卡的计时标志位
u8 show_flag=0;//记录显示那个界面的标志位
unsigned char num;
unsigned char key_flag;//用于标识当前系统处于,扫描ID卡状态还是注册ID卡状态还是注销ID卡状态
unsigned char i;
unsigned int temp;
unsigned char status;
unsigned char g_ucTempbuf[20];
unsigned char g_ucTempbufid[20];//用于记录下来当前扫描到的ID
unsigned char lcd[]="0123456789ABCDEF";//用于显示ID时的16进制
unsigned char dataerr[16] = {0x11,0x11,0x11,0x78,0xED,0xCB,0xA9,0x87,0x12,0x34,0x56,0x78,0x01,0xFE,0x01,0xFE};//ID卡中错误的密码数据
unsigned char data1[16] = {0x12,0x34,0x56,0x78,0xED,0xCB,0xA9,0x87,0x12,0x34,0x56,0x78,0x01,0xFE,0x01,0xFE};//ID卡中正确的密码数据
unsigned char data2[4] = {0,0,0,0x01};
unsigned char DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
u8 RC522_flag=1;
u8 RC522_flag1=1;
u8 RC522_flag2=1;
u8 RC522_flag3=0;
/*按键的扫描函数*/
void key(void)
{
if(KEY0==0)
{
if(key0_flag==1)
{
key0_flag=0;
key_flag=1;
}
}
else
{
key0_flag=1;
}
if(KEY1==0)
{
if(key1_flag==1)
{
key1_flag=0;
key_flag=2;
}
}
else
{
key1_flag=1;
}
}
/*用于判断系统应该显示哪一个界面*/
void show_num(void)
{
if(show_flag==1)
{
show1();
}
else if(show_flag==2)
{
show2();
}
else if(show_flag==3)
{
show3();
}
else if(show_flag==4)
{
show4();
}
else if(show_flag==5)
{
show5();
}
else if(show_flag==6)
{
show21();
}
else if(show_flag==7)
{
show31();
}
else if(show_flag==8)
{
show8();
}
}
int main(void)
{
unsigned char status,i;
unsigned int temp;
delay_init();
LCD1602_Init();
KEY_Init();
BEEP_Init();
LED_Init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(115200);
RC522_Init();
PcdReset();
PcdAntennaOff();
delay_ms(10);
PcdAntennaOn();
delay_ms(10);
TIM2_Int_Init(4999,7199);//10Khz的计数频率,计数到5000为500ms
TIM3_Int_Init(499,7199);//10Khz的计数频率,计数到5000为500ms
TIM4_Int_Init(4999,7199);//10Khz的计数频率,计数到5000为500ms
printf("Start \r\n");
key_flag=0;
show_flag=1;
beep_switch=0;
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
while(1)
{
// printf("%d",RC522_flag1);
show_num();
down_flag=0;
if(kg_flag==6 && err_num<3)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
kg_flag=0;
TIM_Cmd(TIM4, DISABLE); //使能TIMx
GPIO_ResetBits(GPIOB,GPIO_Pin_11);
key_flag=0;
show_flag=1;
open_flag=0;
down_flag=0;
}
else if(kg_flag==360 && err_num==3)
{
kg_flag=0;
err_beepnum=0;
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
TIM_Cmd(TIM4, DISABLE); //使能TIMx
key_flag=0;
show_flag=1;
err_num=0;
}
if(tim2_