资源描述:
《51门禁系统源程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.#include"reg52.h"#include"main.h"#include"uart.h"#include"timer.h"#include"rc522.h"#include"ctrl.h"#include"lcd12864.h"#include"beep.h"#include"key.h"#include"EEPROM.h"voidinit_all(void)//初始化{EA=0;//关总中断init_timer();//定时器初始化init_uart();//串口初始化init_rc522();//RC522初始化lcd_init();
2、//LCD初始化EEPROM_READ(0,Card_SN_BUF,4);//EEPROM初始化,取出记录的卡号EEPROM_READ(7,KEY_BUF,8);//EEPROM初始化,取出记录的密码send_bytes(Card_SN_BUF,4);EA=1;//开总中断}voidmain(void)//主函数{INT8Ukey;Delay_ms(50);//让硬件稳定init_all();//执行初始化函数relay_OFF();//关继电器LED_BLINK_1();//ledtestbeep1();//beeptestdisplay(0,0,
3、0);//显示初始化while(1){key=key_scan();//按键操作if(key==12)if(states>0)states--;elsestates=0;//上一功能if(key==13)if(++states>3)states=3;//下一功能ctrl_process();//进入RC522操作..}}#include"reg52.h"#include"string.h"#include"main.h"#include"uart.h"#include"rc522.h"#include"ctrl.h"#include"beep.h"#
4、include"lcd12864.h"#include"timer.h"#include"EEPROM.h"#include"key.h"INT8Ustates=0;//状态机INT8UCard_type[2],//卡片类型Card_SN[4]={0},//IC卡号Card_SN_BUF[4]={0xff,0xff,0xff,0xff},//卡号登记缓冲区KEY_BUF[8]={'0','0','0','0','0','0','0','0'};INT8UbPass=0;bWarn=0;voiduart_over(void)//串口数据还原{UartC
5、ount=0;UartStart=FALSE;UartComp=FALSE;}voidpass(void){beep1();Delay_ms(2000);//让卡片离开LED_BLINK_1();}voidwarn(void){LED_BLINK_2();}INT8UIC_READ(void)..{INT8UID_ASC[8],i;if(PcdRequest(PICC_REQIDL,Card_type)!=MI_OK)//寻天线区内未进入休眠状态的卡,返回卡片类型2字节{if(PcdRequest(PICC_REQIDL,Card_type)!=MI
6、_OK)//寻天线区内未进入休眠状态的卡,返回卡片类型2字节{returnFALSE;}}if(PcdAnticoll(Card_SN)!=MI_OK)//防冲撞,返回卡的序列号4字节{bWarn=1;returnFALSE;}bPass=1;send_bytes(Card_type,2);send_bytes(Card_SN,4);for(i=0;i<4;i++)//卡ID号转化成ASCII{if(Card_SN[i]/16>9)ID_ASC[i*2]=Card_SN[i]/16+'7';elseID_ASC[i*2]=Card_SN[i]/16+
7、'0';if(Card_SN[i]%16>9)ID_ASC[i*2+1]=Card_SN[i]%16+'7';elseID_ASC[i*2+1]=Card_SN[i]%16+'0';}display2(3,0,"ID:",4);//显示卡号display2(3,2,ID_ASC,8);returnTRUE;}voidctrl_process(void){INT8Ui,key_count,key_value=16,table[8]="--------",statesbuf;if(states!=statesbuf)//状态改变,清屏..{display
8、_clear_line(2);display_clear_line(3);statesbuf=states;