|
歡迎互相學(xué)習(xí)進(jìn)步
制作出來的實(shí)物圖如下:
電路原理圖如下:
元件清單:
4~13-密碼鎖元件清單
1) 9*15萬用板(J2601A)
2) 40腳座(H0202A)
3) stc89c52單片機(jī)
4) 1602液晶(J0802A)
5) 16p插針(H0204E)
6) 16p單排母座(H0204F)
7) 2.2k電阻*2(H0201D)
8) 1k電阻*2(H0201E)
9) 10k電阻*2(H0201C)
10) 103排阻(H0202I)
11) 9012*2三極管(H0203B)
12) 按鍵*17(H0203G)
13) 3p接線端子(H0205M)
14) 5v有源蜂鳴器(H0203I)
15) 10uf電容*2(H0203H)
16) 30pf瓷片電容*2(H0203C)
17) 12m晶振(H0203D)
18) Led(5MM紅色)(H0202L)
19) 5v松樂繼電器(H0205K)
20) DC電源插口(H0211D)
21) 自鎖開關(guān)(H0203F)
22) 8p單排母座(H0204D)
23) 8p排針(H0204C)
24) RC522射頻模塊(J1105A)
25) LM1117-3.3v(H0204Q)
26) 22uf電容(焊接桌上)
27) 104獨(dú)石電容(H0206C)
28) 導(dǎo)線若干(桌下)
29) 焊錫若干(桌下)
30) usb電源線(電池盒+DC插頭)(桌下)
單片機(jī)源程序如下:
- #include <REG52.h>
- #include<intrins.h>
- #include "main.h"
- #include<rc522.c>
- #include<eeprom52.h>
- #define LCM_Data P0
- #define uchar unsigned char
- #define uint unsigned int
- sbit lcd1602_rs=P2^5;
- sbit lcd1602_rw=P2^6;
- sbit lcd1602_en=P2^7;
- sbit ALAM = P2^1; //報(bào)警
- sbit KEY = P3^6; //開鎖
- bit operation=0; //操作標(biāo)志位
- bit pass=0; //密碼正確標(biāo)志
- bit ReInputEn=0; //重置輸入充許標(biāo)志
- bit s3_keydown=0; //3秒按鍵標(biāo)志位
- bit key_disable=0; //鎖定鍵盤標(biāo)志
- bit chushihua=0; //可以注冊卡標(biāo)志位
- unsigned char countt0,second; //t0中斷計(jì)數(shù)器,秒計(jì)數(shù)器
- //解碼變量
- unsigned char Im[4]={0x00,0x00,0x00,0x00};
- //全局變量
- uchar f,a_a;
- unsigned long m,Tc;
- unsigned char IrOK;
- unsigned char xdata CardRevBuf[16] = { 0 };
- //void Delay5Ms(void);
- unsigned char code a[]={0xFE,0xFD,0xFB,0xF7}; //控盤掃描控制表
- unsigned char code start_line[] = {"password: "};
- unsigned char code name[] = {"===Coded Lock==="}; //顯示名稱
- unsigned char code Correct[] = {" correct "}; //輸入正確
- unsigned char code Error1[] = {" error "}; //輸入錯(cuò)誤
- unsigned char code codepass[] = {" pass "};
- unsigned char code LockOpen[] = {" open "}; //OPEN
- unsigned char code SetNew[] = {"SetNewWordEnable"};
- unsigned char code Input[] = {"input: "}; //INPUT
- unsigned char code ResetOK[] = {"ResetPasswordOK "};
- unsigned char code initword[] = {"Init password..."};
- unsigned char code Er_try[] = {"error,try again!"};
- unsigned char code again[] = {"input again "};
- unsigned char InputData[6]; //輸入密碼暫存區(qū)
- unsigned char CurrentPassword[6]={1,3,1,4,2,0}; //當(dāng)前密碼值
- unsigned char TempPassword[6];
- unsigned char N=0; //密碼輸入位數(shù)記數(shù)
- unsigned char ErrorCont; //錯(cuò)誤次數(shù)計(jì)數(shù)
- unsigned char CorrectCont; //正確輸入計(jì)數(shù)
- unsigned char ReInputCont; //重新輸入計(jì)數(shù)
- unsigned char code initpassword[6]={0,0,0,0,0,0};
- unsigned char current_id;
- char xdata DisplayBuf[10]; //當(dāng)前讀出卡的ID
- char xdata DisplayBuf_c[10]; //當(dāng)前單片機(jī)里存的卡ID
- void write_eeprom()
- {
-
- SectorErase(0x200a); //清空
- byte_write(0x2000,TempPassword[0]);
- byte_write(0x2001,TempPassword[1]);
- byte_write(0x2002,TempPassword[2]);
- byte_write(0x2003,TempPassword[3]);
- byte_write(0x2004,TempPassword[4]);
- byte_write(0x2005,TempPassword[5]);
- byte_write(0x2060,0x02);
-
- }
- void write_eeprom_j(unsigned char j) //將對應(yīng)的ID寫入到單片機(jī)
- {
-
- SectorErase(0x2200+j*0x0200); //清空
- byte_write(0x2200+j*0x0200,DisplayBuf[0]);
- byte_write(0x2201+j*0x0200,DisplayBuf[1]);
- byte_write(0x2202+j*0x0200,DisplayBuf[2]);
- byte_write(0x2203+j*0x0200,DisplayBuf[3]);
- byte_write(0x2204+j*0x0200,DisplayBuf[4]);
- byte_write(0x2205+j*0x0200,DisplayBuf[5]);
- byte_write(0x2206+j*0x0200,DisplayBuf[6]);
- byte_write(0x2207+j*0x0200,DisplayBuf[7]);
- }
- void write_eeprom_jj(unsigned char j) //將對應(yīng)的ID清空
- {
-
- SectorErase(0x2200+j*0x0200); //清空
- byte_write(0x2200+j*0x0200,' ');
- byte_write(0x2201+j*0x0200,' ');
- byte_write(0x2202+j*0x0200,' ');
- byte_write(0x2203+j*0x0200,' ');
- byte_write(0x2204+j*0x0210,' ');
- byte_write(0x2205+j*0x0200,' ');
- byte_write(0x2206+j*0x0200,' ');
- byte_write(0x2207+j*0x0200,' ');
- }
- void read_eeprom_j(uchar j)
- {
- DisplayBuf_c[0]= byte_read(0x2200+j*0x0200);
- DisplayBuf_c[1]= byte_read(0x2201+j*0x0200);
- DisplayBuf_c[2]= byte_read(0x2202+j*0x0210);
- DisplayBuf_c[3]= byte_read(0x2203+j*0x0200);
- DisplayBuf_c[4]= byte_read(0x2204+j*0x0200);
- DisplayBuf_c[5]= byte_read(0x2205+j*0x0200);
- DisplayBuf_c[6]= byte_read(0x2206+j*0x0200);
- DisplayBuf_c[7]= byte_read(0x2207+j*0x0200);
-
- }
- /******************把數(shù)據(jù)從單片機(jī)內(nèi)部eeprom中讀出來*****************/
- void read_eeprom()
- {
-
- CurrentPassword[0]= byte_read(0x2000);
- CurrentPassword[1]= byte_read(0x2011);
- CurrentPassword[2]= byte_read(0x2002);
- CurrentPassword[3]= byte_read(0x2003);
- CurrentPassword[4]= byte_read(0x2004);
- CurrentPassword[5]= byte_read(0x2005);
- a_a = byte_read(0x2060);
-
- }
- /**************開機(jī)自檢eeprom初始化*****************/
- void init_eeprom()
- {
- uchar i,j;
- a_a = byte_read(0x2060);
- if(a_a != 1) //新的單片機(jī)初始單片機(jī)內(nèi)問eeprom
- {
-
- a_a = 1;
- for(i=0;i<6;i++)
- {
- SectorErase(0x2200+i*0x0200);
- for(j=0;j<8;j++)
- byte_write(0x2200+i*0x0200+j,'0');
- }
- write_eeprom(); //保存數(shù)據(jù)
- }
- }
- //=====================5ms延時(shí)==============================
- void Delay5Ms()
- {
- unsigned int TempCyc = 5552;
- while(TempCyc--);
- }
- //===================400ms延時(shí)==============================
- void Delay400Ms()
- {
- unsigned char TempCycA = 5;
- unsigned int TempCycB;
- while(TempCycA--)
- {
- TempCycB=7269;
- while(TempCycB--);
- }
- }
-
- //==================================================================================================
- //=======================================LCD1602====================================================
- //==================================================================================================
- #define yi 0x80 //LCD第一行的初始位置,因?yàn)長CD1602字符地址首位D7恒定為1(100000000=80)
- #define er 0x80+40 //LCD第二行初始位置(因?yàn)榈诙械谝粋(gè)字符位置地址是0x40)
- //----------------延時(shí)函數(shù),后面經(jīng)常調(diào)用----------------------
- void delay(uint xms)//延時(shí)函數(shù),有參函數(shù)
- {
- uint x,y;
- for(x=xms;x>0;x--)
- for(y=110;y>0;y--);
- }
- //--------------------------寫指令---------------------------
- void write_1602com(uchar com)//****液晶寫入指令函數(shù)****
- {
- lcd1602_rs=0;//數(shù)據(jù)/指令選擇置為指令
- lcd1602_rw=0; //讀寫選擇置為寫
- P0=com;//送入數(shù)據(jù)
- delay(1);
- lcd1602_en=0;//拉高使能端,為制造有效的下降沿做準(zhǔn)備
- delay(1);
- lcd1602_en=1;//en由高變低,產(chǎn)生下降沿,液晶執(zhí)行命令
- }
- //-------------------------寫數(shù)據(jù)-----------------------------
- void write_1602dat(uchar dat)//***液晶寫入數(shù)據(jù)函數(shù)****
- {
- lcd1602_rs=1;//數(shù)據(jù)/指令選擇置為數(shù)據(jù)
- lcd1602_rw=1; //讀寫選擇置為寫
- P0=dat;//送入數(shù)據(jù)
- delay(1);
- lcd1602_en=0; //en置高電平,為制造下降沿做準(zhǔn)備
- delay(1);
- lcd1602_en=1; //en由高變低,產(chǎn)生下降沿,液晶執(zhí)行命令
- }
- //-------------------------初始化-------------------------
- void lcd_init()
- {
- write_1602com(0x01);//清顯示
- write_1602com(0x38);//設(shè)置液晶工作模式,意思:16*2行顯示,5*7點(diǎn)陣,8位數(shù)據(jù)
- write_1602com(0x0c);//開顯示不顯示光標(biāo)
- write_1602com(0x06);//整屏不移動,光標(biāo)自動右移
- }
- //========================================================================================
- //=========================================================================================
- //==============將按鍵值編碼為數(shù)值=========================
- unsigned char coding(unsigned char m1,unsigned char hh)
- {
- unsigned char k;
- if(IrOK==1)
- {
- IrOK=0;
- switch(m1)
- {
- case (0x0c): k=1;break;
- case (0x18): k=2;break;
- case (0x5e): k=3;break;
- // case (0xff): k='A';break; //
- case (0x08): k=4;break;
- case (0x1c): k=5;break;
- case (0x50): k=6;break;
- // case (0x82): k='B';break; //
- case (0x42): k=7;break;
- case (0x52): k=8;break;
- case (0x4a): k=9;break;
- // case (0x84): k='C';break; //
- case (0x43): k='*';break; //撤銷
- case (0x16): k=0;break;
- case (0x15): k='#';break; //確認(rèn)鍵
- case (0x0d): k='D';break; //重設(shè)密碼
- case (0x4e): k='B';break; //
- case (0x47): k='C';break; //
- case (0x44): k='A';break; //
- case (0x40): k='A';break; //
- case (0x07): k='A';break; //
- case (0x09): k='A';break; //
- case (0x19): k='A';break; //
- // default:;
- }
- }
- else
- {
- switch(hh)
- {
- case (0x11): k=1;break;
- case (0x21): k=2;break;
- case (0x41): k=3;break;
- case (0x81): k='A';break;
- case (0x12): k=4;break;
- case (0x2a): k=5;break;
- case (0x42): k=6;break;
- case (0x82): k='B';break;
- case (0x14): k=7;break;
- case (0x24): k=8;break;
- case (0x4b): k=9;break;
- case (0x84): k='C';break;
- case (0x18): k='*';break;
- case (0x28): k=0;break;
- case (0x48): k='#';break;
- case (0x88): k='D';break;
- // default:;
- }
- }
- return(k);
- }
- //=====================按鍵檢測并返回按鍵值===============================
- unsigned char keynum()
- {
- unsigned char row,col,i;
- P1=0xf0;
- if((P1&0xf0)!=0xf0)
- {
- Delay5Ms();
- Delay5Ms();
- if((P1&0xf0)!=0xf0)
- {
- row=P1^0xf0; //確定行線
- i=0;
- P1=a[i]; //精確定位
- while(i<4)
- {
- if((P1&0xf0)!=0xf0)
- {
- col=~(P1&0xff); //確定列線
- break; //已定位后提前退出
- }
- else
- {
- i++;
- P1=a[i];
- }
- }
- }
- else
- {
- return 0;
- }
-
- while((P1&0xf0)!=0xf0);
- return (row|col); //行線與列線組合后返回
- }
- else return 0; //無鍵按下時(shí)返回0
- }
- //=======================一聲提示音,表示有效輸入========================
- void OneAlam()
- {
- ALAM=0;
- Delay5Ms();
- ALAM=1;
- }
- //========================二聲提示音,表示操作成功========================
- void TwoAlam()
- {
- ALAM=0;
- Delay5Ms();
- ALAM=1;
- Delay5Ms();
- ALAM=0;
- Delay5Ms();
- ALAM=1;
- }
- //========================三聲提示音,表示錯(cuò)誤========================
- void ThreeAlam()
- {
- ALAM=0;
- Delay5Ms();
- ALAM=1;
- Delay5Ms();
- ALAM=0;
- Delay5Ms();
- ALAM=1;
- Delay5Ms();
- ALAM=0;
- Delay5Ms();
- ALAM=1;
- }
- //=====================顯示輸入的N個(gè)數(shù)字,用H代替以便隱藏============================
- void DisplayOne()
- {
- // DisplayOneChar(9+N,1,'*');
- write_1602com(yi+5+N);
- write_1602dat('*');
- }
- //=======================顯示提示輸入=========================
- void DisplayChar()
- {
- unsigned char i;
- if(pass==1)
- {
- //DisplayListChar(0,1,LockOpen);
- write_1602com(er);
- for(i=0;i<16;i++)
- {
- write_1602dat(LockOpen[i]);
- }
- }
- else
- {
- if(N==0)
- {
- //DisplayListChar(0,1,Error);
- write_1602com(er);
- for(i=0;i<16;i++)
- {
- write_1602dat(Error1[i]);
- }
- }
- else
- {
- //DisplayListChar(0,1,start_line);
- write_1602com(er);
- for(i=0;i<16;i++)
- {
- write_1602dat(start_line[i]);
- }
- }
- }
- }
- void DisplayInput()
- {
- unsigned char i;
- if(CorrectCont==1)
- {
- //DisplayListChar(0,0,Input);
- write_1602com(er);
- for(i=0;i<16;i++)
- {
- write_1602dat(Input[i]);
- }
- }
- }
- //========================重置密碼==================================================
- //==================================================================================
- void ResetPassword()
- {
- unsigned char i;
- unsigned char j;
- if(pass==0)
- {
- pass=0;
- DisplayChar();
- ThreeAlam();
- }
- else
- {
- if(ReInputEn==1)
- {
- if(N==6)
- {
- ReInputCont++;
- if(ReInputCont==2)
- {
- for(i=0;i<6;)
- {
- if(TempPassword[i]==InputData[i]) //將兩次輸入的新密碼作對比
- i++;
- else
- {
- //DisplayListChar(0,1,Error);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(Error1[j]);
- }
- ThreeAlam(); //錯(cuò)誤提示
- pass=0;
- ReInputEn=0; //關(guān)閉重置功能,
- ReInputCont=0;
- DisplayChar();
- break;
- }
- }
- if(i==6)
- {
- //DisplayListChar(0,1,ResetOK);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(ResetOK[j]);
- }
- TwoAlam(); //操作成功提示
- write_eeprom();
- ReInputEn=0;
- }
- ReInputCont=0;
- CorrectCont=0;
- }
- else
- {
- OneAlam();
- //DisplayListChar(0, 1, again); //顯示再次輸入一次
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(again[j]);
- }
- for(i=0;i<6;i++)
- {
- TempPassword[i]=InputData[i]; //將第一次輸入的數(shù)據(jù)暫存起來
- }
- }
- N=0; //輸入數(shù)據(jù)位數(shù)計(jì)數(shù)器清零
- }
- }
- }
- }
- //=======================輸入密碼錯(cuò)誤超過三過,報(bào)警并鎖死鍵盤======================
- void Alam_KeyUnable()
- {
- P1=0x00;
- {
- ALAM=~ALAM;
- Delay5Ms();
- }
- }
- //=======================取消所有操作============================================
- void Cancel()
- {
- unsigned char i;
- unsigned char j;
- //DisplayListChar(0, 1, start_line);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(start_line[j]);
- }
- TwoAlam(); //提示音
- for(i=0;i<6;i++)
- {
- InputData[i]=0;
- }
- KEY=1; //關(guān)閉鎖
- ALAM=1; //報(bào)警關(guān)
- operation=0; //操作標(biāo)志位清零
- pass=0; //密碼正確標(biāo)志清零
- ReInputEn=0; //重置輸入充許標(biāo)志清零
- // ErrorCont=0; //密碼錯(cuò)誤輸入次數(shù)清零
- CorrectCont=0; //密碼正確輸入次數(shù)清零
- ReInputCont=0; //重置密碼輸入次數(shù)清零
- s3_keydown=0;
- key_disable=0;
- N=0; //輸入位數(shù)計(jì)數(shù)器清零
- }
- //==========================確認(rèn)鍵,并通過相應(yīng)標(biāo)志位執(zhí)行相應(yīng)功能===============================
- void Ensure()
- {
- unsigned char i,j;
- // RdFromROM(CurrentPassword,0,6); //從24C02里讀出存儲密碼
- read_eeprom();
- if(N==6)
- {
- if(ReInputEn==0) //重置密碼功能未開啟
- {
- for(i=0;i<6;)
- {
- if(CurrentPassword[i]==InputData[i])
- {
- i++;
- }
- else
- {
- i=7;
- ErrorCont++;
- if(ErrorCont>=3&&KEY==1) //錯(cuò)誤輸入計(jì)數(shù)達(dá)三次時(shí),報(bào)警并鎖定鍵盤
- {
- write_1602com(er);
- for(i=0;i<16;i++)
- {
- write_1602dat(Error1[i]);
- }
- Alam_KeyUnable();
- TR0=0; //開啟定時(shí)
- key_disable=1; //鎖定鍵盤
- pass=0;
- break;
- }
- }
- }
- if(i==6)
- {
- CorrectCont++;
- if(CorrectCont==1) //正確輸入計(jì)數(shù),當(dāng)只有一次正確輸入時(shí),開鎖,
- {
- //DisplayListChar(0,1,LockOpen);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(LockOpen[j]);
- }
- TwoAlam(); //操作成功提示音
- ErrorCont=0;
- KEY=0; //開鎖
- pass=1; //置正確標(biāo)志位
- TR1=1; //開啟定時(shí)
- for(j=0;j<6;j++) //將輸入清除
- {
- InputData[i]=0;
- }
- }
- else //當(dāng)兩次正確輸入時(shí),開啟重置密碼功能
- {
- //DisplayListChar(0,1,SetNew);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(SetNew[j]);
- }
- TwoAlam(); //操作成功提示
- ReInputEn=1; //允許重置密碼輸入
- CorrectCont=0; //正確計(jì)數(shù)器清零
- }
- }
-
- else //=========================當(dāng)?shù)谝淮问褂没蛲浢艽a時(shí)可以用131420對其密碼初始化============
- {
- if((InputData[0]==1)&&(InputData[1]==3)&&(InputData[2]==1)&&(InputData[3]==4)&&(InputData[4]==2)&&(InputData[5]==0))
- {
- // WrToROM(initpassword,0,6); //強(qiáng)制將初始密碼寫入24C02存儲
-
- //DisplayListChar(0,1,initword); //顯示初始化密碼
-
- TwoAlam();
- Delay400Ms();
- TwoAlam();
- N=0;
- chushihua=1;
- }
- else if((InputData[0]==1)&&(InputData[1]==3)&&(InputData[2]==1)&&(InputData[3]==4)&&(InputData[4]==2)&&(InputData[5]==1))
- {
- // WrToROM(initpassword,0,6); //強(qiáng)制將初始密碼寫入24C02存儲
- TempPassword[0]=0;
- TempPassword[1]=0;
- TempPassword[2]=0;
- TempPassword[3]=0;
- TempPassword[4]=0;
- TempPassword[5]=0;
- write_eeprom();
- //DisplayListChar(0,1,initword); //顯示初始化密碼
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(initword[j]);
- }
- TwoAlam();
- Delay400Ms();
- TwoAlam();
- N=0;
-
- }
- else
- {
- //DisplayListChar(0,1,Error);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(Error1[j]);
- }
- ThreeAlam(); //錯(cuò)誤提示音
- pass=0;
- }
- }
- }
- else //當(dāng)已經(jīng)開啟重置密碼功能時(shí),而按下開鎖鍵,
- {
- //DisplayListChar(0,1,Er_try);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(Er_try[j]);
- }
- ThreeAlam();
- }
- }
- else
- {
- //DisplayListChar(0,1,Error);
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(Error1[j]);
- }
- ThreeAlam(); //錯(cuò)誤提示音
- pass=0;
- }
-
- N=0; //將輸入數(shù)據(jù)計(jì)數(shù)器清零,為下一次輸入作準(zhǔn)備
- operation=1;
- }
-
- void display_id( unsigned char xdata * SrcBuf )
- {
- char xdata *pDisplayChar;
- unsigned char xdata Tmp, i;
- pDisplayChar = DisplayBuf;
- for( i = 0; i < 4; i++ )
- {
- Tmp = ( ( *SrcBuf ) << 4 ) & 0x0F;
- if( ( Tmp >=0 ) && ( Tmp <= 9 ) )
- {
- *pDisplayChar ++ = '0' + Tmp;
- }
- else
- {
- *pDisplayChar ++ = 'A' + Tmp - 10;
- }
- Tmp = ( *SrcBuf ) & 0x0F;
- if( ( Tmp >=0 ) && ( Tmp <= 9 ) )
- {
- *pDisplayChar ++ = '0' + Tmp;
- }
- else
- {
- *pDisplayChar ++ = 'A' + Tmp - 10;
- }
- SrcBuf ++;
- }
- *pDisplayChar ++ = '\0';
- // DisplayListChar( 0, 4, DisplayBuf );
- if(chushihua==1)
- {
- write_1602com(0xc0);
- write_1602dat('I');
- write_1602dat('D');
- write_1602dat(current_id+0x30);
- write_1602dat(':');
- write_1602dat(DisplayBuf[0]);
- write_1602dat(DisplayBuf[1]);
- write_1602dat(DisplayBuf[2]);
- write_1602dat(DisplayBuf[3]);
- write_1602dat(DisplayBuf[4]);
- write_1602dat(DisplayBuf[5]);
- write_1602dat(DisplayBuf[6]);
- write_1602dat(DisplayBuf[7]);
- write_1602dat(' ');
- write_1602dat(' ');write_1602dat(' ');write_1602dat(' ');write_1602dat(' ');
- }
- }
- void display_no_id()
- {
-
- write_1602com(0xc0);
- write_1602dat('I');
- write_1602dat('D');
- write_1602dat(current_id+0x30);
- write_1602dat(':');
- write_1602dat(DisplayBuf_c[0]);
- write_1602dat(DisplayBuf_c[1]);
- write_1602dat(DisplayBuf_c[2]);
- write_1602dat(DisplayBuf_c[3]);
- write_1602dat(DisplayBuf_c[4]);
- write_1602dat(DisplayBuf_c[5]);
- write_1602dat(DisplayBuf_c[6]);
- write_1602dat(DisplayBuf_c[7]);
- write_1602dat(' ');
- write_1602dat(' ');write_1602dat(' ');write_1602dat(' ');write_1602dat(' ');
- }
- void ctrl( void )
- {
- uchar j,i;
- if( PcdRequest( PICC_REQIDL, &CardRevBuf[0] ) != MI_OK )//尋天線區(qū)內(nèi)未進(jìn)入休眠狀態(tài)的卡,返回卡片類型 2字節(jié)
- {
- if( PcdRequest( PICC_REQIDL, &CardRevBuf[0] ) != MI_OK )//尋天線區(qū)內(nèi)未進(jìn)入休眠狀態(tài)的卡,返回卡片類型 2字節(jié)
- {
- if(chushihua==1)
- {
- read_eeprom_j(current_id);
- display_no_id();
- }
- return;
- }
- }
- if( PcdAnticoll( &CardRevBuf[2] ) != MI_OK ) //防沖撞,返回卡的序列號 4字節(jié)
- {
- if(chushihua==1)
- {
- read_eeprom_j(current_id);
- display_no_id();
- }
- return;
- }
- if( PcdSelect( &CardRevBuf[2] ) != MI_OK )//選卡
- {
- if(chushihua==1)
- {
- read_eeprom_j(current_id);
- display_no_id();
- }
- return;
- }
- display_id( &CardRevBuf[2] );
- if(CorrectCont==0&&pass==0)
- {
- for(j=0;j<6;j++)
- {
- read_eeprom_j(j);
- if(DisplayBuf[0]==DisplayBuf_c[0]&&DisplayBuf[1]==DisplayBuf_c[1]&&DisplayBuf[2]==DisplayBuf_c[2]&&DisplayBuf[3]==DisplayBuf_c[3]&&DisplayBuf[4]==DisplayBuf_c[4]&&DisplayBuf[5]==DisplayBuf_c[5])
- {
-
- CorrectCont=1;
- write_1602com(er);
- for(j=0;j<16;j++)
- {
- write_1602dat(LockOpen[j]);
- }
- TwoAlam(); //操作成功提示音
- ErrorCont=0;
- KEY=0; //開鎖
- pass=1; //置正確標(biāo)志位
- TR0=1; //開啟定時(shí)
- for(j=0;j<6;j++) //將輸入清除
- {
- InputData[i]=0;
- }
- return;
- }
- }
- }
- }
- //==============================主函數(shù)===============================
- void main()
- {
- unsigned char KEY,NUM;
- unsigned char i,j;
- P1=0xFF;
- EA=1;
- TMOD=0x01;
- IT1=1;//下降沿有效
- EX1=1;//外部中斷1開
-
- TH0=0;//T0賦初值
- TL0=0;
- TR0=1;//t0開始計(jì)時(shí)
- TL1=0x3c;
- TH1=0xb0;
- ET1=1;
- TR1=0;
- Delay400Ms(); //啟動等待,等LCM講入工作狀態(tài)
- lcd_init(); //LCD初始化
- write_1602com(yi);//日歷顯示固定符號從第一行第0個(gè)位置之后開始顯示
- init_rc522();
- init_eeprom();
- read_eeprom();
- for(i=0;i<16;i++)
- {
- write_1602dat(name[i]);//向液晶屏寫日歷顯示的固定符號部分
- }
- write_1602com(er);//時(shí)間顯示固定符號寫入位置,從第2個(gè)位置后開始顯示
- for(i=0;i<16;i++)
- {
- write_1602dat(start_line[i]);//寫顯示時(shí)間固定符號,兩個(gè)冒號
- }
- write_1602com(er+9); //設(shè)置光標(biāo)位置
- write_1602com(0x0f); //設(shè)置光標(biāo)為閃爍
- Delay5Ms(); //延時(shí)片刻(可不要)
- N=0; //初始化數(shù)據(jù)輸入位數(shù)
- while(1)
- {
-
- ctrl();
- if(key_disable==1)
- Alam_KeyUnable();
- else
- ALAM=1; //關(guān)報(bào)警
- KEY=keynum();
- if(KEY!=0||IrOK==1)
- {
- if(key_disable==1)
- {
- second=0;
- }
- else
- {
- NUM=coding(Im[2],KEY);
- {
- switch(NUM)
- {
- case ('A'): if(chushihua==1)
- {
- current_id++;
- if(current_id>5)
- current_id=0;
- } break;
- case ('B'): if(chushihua==1)
- write_eeprom_jj(current_id) ; break;
- case ('C'): if(chushihua==1)
- write_eeprom_j(current_id) ; break;
- case ('D'): chushihua=0;ResetPassword(); break; //重新設(shè)置密碼
- case ('*'): chushihua=0;Cancel(); break; //取消當(dāng)前輸入
- case ('#'): chushihua=0; Ensure(); break; //確認(rèn)鍵,
- default:
- {
- chushihua=0;
- //DisplayListChar(0,1,Input);
- write_1602com(er);
- for(i=0;i<16;i++)
- {
- write_1602dat(Input[i]);
- }
- operation=0;
- if(N<6) //當(dāng)輸入的密碼少于6位時(shí),接受輸入并保存,大于6位時(shí)則無效。
- {
- OneAlam(); //按鍵提示音
- //DisplayOneChar(6+N,1,'*');
- for(j=0;j<=N;j++)
- {
- write_1602com(er+6+j);
- write_1602dat('*');
- }
- InputData[N]=NUM;
- N++;
- }
- else //輸入數(shù)據(jù)位數(shù)大于6后,忽略輸入
- {
- N=6;
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- //*********************************中斷服務(wù)函數(shù)**************************************
- void time1_int() interrupt 3
- {
- TL1=0x3c;
- TH1=0xb0;
- countt0++;
- if(countt0==20)
- {
- countt0=0;
- second++;
- if(pass==1)
- {
- if(second==1)
- {
- TR1=0; //關(guān)定時(shí)器
- TL1=0xB0;
- TH1=0x3C;
- second=0;
- }
- }
- else
- {
- if(second==3)
- {
- TR1=0;
- second=0;
- key_disable=0;
- s3_keydown=0;
- TL1=0xB0;
- TH1=0x3C;
- }
- else
- TR1=1;
- }
-
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
求幫助.7z
(11.06 KB, 下載次數(shù): 123)
2022-10-11 18:06 上傳
點(diǎn)擊文件名下載附件
|
評分
-
查看全部評分
|