资源描述:
《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();//LCD初始化EEP
2、ROM_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,0);//显示初始化while(1){key=
3、key_scan();//按键操作if(key==12)if(states>0)states--;elsestates=0;//上一功能if(key==13)if(++states>3)states=3;//下一功能ctrl_process();//进入RC522操作..word.zl...}}#include"reg52.h"#include"string.h"#include"main.h"#include"uart.h"#include"rc522.h"#include"ctrl.h"#include"beep.h"#include"lcd12864.h"#inclu
4、de"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)//串口数据复原{UartCount=0;UartStart=FALSE;Uartp=FALSE;}v
5、oidpass(void){beep1();Delay_ms(2000);//让卡片离开LED_BLINK_1();}voidwarn(void){LED_BLINK_2();}INT8UIC_READ(void)..word.zl...{INT8UID_ASC[8],i;if(PcdRequest(PICC_REQIDL,Card_type)!=MI_OK)//寻天线区未进入休眠状态的卡,返回卡片类型2字节{if(PcdRequest(PICC_REQIDL,Card_type)!=MI_OK)//寻天线区未进入休眠状态的卡,返回卡片类型2字节{returnFALSE;}
6、}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+'0';if(Card_SN[i]%16>9)ID_ASC[i*2+1]=Card_SN[i]%16+'7';e
7、lseID_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)//状态改变,清屏..word.zl...{display_clear_line(2);display_clear