資源描述:
《51門禁系統(tǒng)源程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
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;//關(guān)總中斷init_timer();//定時(shí)器初始化init_uart();//串口初始化init_rc522();//RC522初始化lcd_init();
2、//LCD初始化EEPROM_READ(0,Card_SN_BUF,4);//EEPROM初始化,取出記錄的卡號(hào)EEPROM_READ(7,KEY_BUF,8);//EEPROM初始化,取出記錄的密碼send_bytes(Card_SN_BUF,4);EA=1;//開總中斷}voidmain(void)//主函數(shù){INT8Ukey;Delay_ms(50);//讓硬件穩(wěn)定init_all();//執(zhí)行初始化函數(shù)relay_OFF();//關(guān)繼電器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();//進(jìn)入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;//狀態(tài)機(jī)INT8UCard_type[2],//卡片類型Card_SN[4]={0},//IC卡號(hào)Card_SN_BUF[4]={0xff,0xff,0xff,0xff},//卡號(hào)登記緩沖區(qū)KEY_BUF[8]={'0','0','0','0','0','0','0','0'};INT8UbPass=0;bWarn=0;voiduart_over(void)//串口數(shù)據(jù)還原{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)//尋天線區(qū)內(nèi)未進(jìn)入休眠狀態(tài)的卡,返回卡片類型2字節(jié){if(PcdRequest(PICC_REQIDL,Card_type)!=MI
6、_OK)//尋天線區(qū)內(nèi)未進(jìn)入休眠狀態(tài)的卡,返回卡片類型2字節(jié){returnFALSE;}}if(PcdAnticoll(Card_SN)!=MI_OK)//防沖撞,返回卡的序列號(hào)4字節(jié){bWarn=1;returnFALSE;}bPass=1;send_bytes(Card_type,2);send_bytes(Card_SN,4);for(i=0;i<4;i++)//卡ID號(hào)轉(zhuǎn)化成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);//顯示卡號(hào)display2(3,2,ID_ASC,8);returnTRUE;}voidctrl_process(void){INT8Ui,key_count,key_value=16,table[8]="--------",statesbuf;if(states!=statesbuf)//狀態(tài)改變,清屏..{display
8、_clear_line(2);display_clear_line(3);statesbuf=states;