|
簡單門禁系統(tǒng)電路圖及C++源碼
0.png (71.84 KB, 下載次數(shù): 91)
下載附件
2016-6-26 14:07 上傳
門禁系統(tǒng)的電路原理圖:
0.png (70.17 KB, 下載次數(shù): 98)
下載附件
2016-6-26 14:08 上傳
門禁系統(tǒng)的單片機(jī)程序源碼(部分預(yù)覽):
- #include <reg51.h>
- #include <intrins.h>
- #include "system.h"
- #include "interface.h"
- #include "IDCard.h"
- #include "display.h"
- #include "eeprom.h"
- #include "DS18B20.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- #define On 0
- #define Off 1
- #define Open 1
- #define Close 0
- #define Short 1
- #define Long 0
- #define KeyPort P2 //鍵盤接口
- sbit BEEP = P3^2;
- sbit Lock = P3^7; //鎖控制端
- #define CardNumAddr 0x123 //存放卡個數(shù)的地址
- #define CaedAddr 0x700 //存放卡號的地址
- #define CipherNumAddr 0x1234 //存放密碼個數(shù)的地址
- #define CipherAddr 0x2000 //存放密碼的地址
- #define RootCipherAddr 0x4567 //存放系統(tǒng)管理密碼的地址
- #define SelfCheckAddr 0x3868 //自檢地址
- uchar CardNum;
- uchar CipherNum;
- uchar Mode;
- #define ModeAddr 0x5678
- bit bdata BITinputing = 0;
- ulong xdata Cipher = 0;
- uchar xdata CipherBitNum = 0;
- uchar xdata InputCipherNum = 0;
- bit bdata BITinputnum0ut = 0;
- bit bdata BITcipherOK = 0;
- extern bit GetOneCard;
- extern uchar Card[];
- uint xdata Temperature = 0; //溫度值
- bit bdata BITtemp = 0;
- uint TempTimeCon = 48;
- uchar SecondCon = 0x25; //0.5S
- bit bdata BITdispsec = 0;
- uint xdata KeyTimeCon = 0;
- bit bdata BITkeyout = 0;
- bit bdata BITbeep = 0;
- bit bdata BITbeepwait = 0;
- uchar xdata BeepTimeCon;
- uchar xdata BeepCopyTime;
- uchar xdata BeepNum;
- extern uchar code mimacuowu[];
- /*******************************************************
- * 函數(shù)名稱:Init_Timer()
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void Init_Timer(void)
- {
- TMOD = TMOD|0x01; //定時器0: 20ms定時
- TL0 = 0x00;
- TH0 = 0x70;
- ET0 = 1; //開定時器0中斷
- TR0 = 1; //開是始定時器0計時
- TMOD = TMOD|0x10; //定時器1: 20ms定時
- TL1 = 0x00;
- TH1 = 0x70;
- ET1 = 0; //禁止定時器1中斷
- TR1 = 0;
- }
- /*******************************************************
- * 函數(shù)名稱:Time0_INT()
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void Time0_INT(void) interrupt 1
- {
- ET0 = 0;
- TR0 = 0;
- TL0 = 0x00;
- TH0 = 0x70;
-
- if(KeyTimeCon)
- {
- KeyTimeCon -= 1;
- if(KeyTimeCon == 0)
- BITkeyout = 1;
- }
- if(TempTimeCon)
- {
- TempTimeCon -= 1;
- if(TempTimeCon == 0)
- BITtemp = 1;
- }
- if(SecondCon)
- {
- SecondCon -= 1;
- if(SecondCon == 0)
- {
- SecondCon = 0x25;
- BITdispsec = 1;
- }
- }
-
- if(BITbeep)
- {
- if(BeepTimeCon == BeepCopyTime)
- {
- BEEP = ~BEEP;
- }
- BeepTimeCon -= 1;
- if(BeepTimeCon == 0)
- {
- BeepNum -= 1;
- BeepTimeCon = BeepCopyTime;
- }
-
- if(BeepNum == 0)
- {
- BITbeep = 0;
- BITbeepwait = 0;
- BEEP = Off;
- }
- }
-
- TR0=1;
- ET0=1;
- }
- /*******************************************************
- * 函數(shù)名稱:Time1_INT()
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void Time1_INT(void) interrupt 3
- {
- ET1=0;
- TR1=0;
- TL1=0x00;
- TH1=0x70;
-
- TR1=1;
- ET1=1;
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void SystemInit(void)
- {
- uint dat;
- // Lock = Open;
- LCDInit();
- Init_Timer();
- DS18B20Init(0x7f,0x64,0x8a);
- DS18B20StartConvert();
- dat = ReadEEPROM(SelfCheckAddr+1); //讀系統(tǒng)自檢標(biāo)飾位
- dat = (dat<<8) | ReadEEPROM(SelfCheckAddr);
- if(dat == 0xAA55) //系統(tǒng)已經(jīng)初始化過
- {
- CardNum = ReadEEPROM(CardNumAddr);
- CipherNum = ReadEEPROM(CipherNumAddr);
- Mode = ReadEEPROM(ModeAddr);
- }
- else //系統(tǒng)第一次使用
- {
- WriteEEPROM(SelfCheckAddr,0xAA55); //標(biāo)記系統(tǒng)已設(shè)置過
- WriteEEPROM(CipherAddr,0x5678); //初始化系統(tǒng)管理員密碼為 12345678
- WriteEEPROM(CipherAddr,0x1234);
- CardNum = 0;
- WriteEEPROM(CardNumAddr,CardNum);
- CipherNum = 0;
- WriteEEPROM(CipherNumAddr,CipherNum);
- Mode = 0x88;
- WriteEEPROM(ModeAddr,Mode); //默認(rèn)為密碼模式
- }
- TimeInterface();
- EA = 1;
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void Beep(uchar num,bit state)
- {
- while(BITbeepwait);
- BeepNum = (num<<1)-1; //蜂鳴器響的次數(shù)
- if(state) //鳴叫時間=BeepCopyTime*20ms
- BeepCopyTime = 10; //短鳴
- else
- BeepCopyTime = 30; //長鳴
- BeepTimeCon = BeepCopyTime;
- BITbeep = 1;
- BITbeepwait = 1;
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- uchar CheckKey(void)
- {
- uchar key;
- KeyPort = 0x0f;
- key = KeyPort;
- if(key&0x0f != 0x0f)
- {
- DelayMS(10);
- if(KeyPort == key)
- {
- KeyPort = 0xf0;
- key = (key&0x0f) | (KeyPort&0xf0);
- // Beep(1,Short);
- switch(key)
- {
- case 0x00: return 1; break;
- case 0x01: return 2; break;
- case 0x02: return 3; break;
- case 0x03: return 4; break;
- case 0x04: return 5; break;
- case 0x05: return 6; break;
- case 0x06: return 7; break;
- case 0x07: return 8; break;
- case 0x08: return 9; break;
- case 0x09: return 10; break;
- case 0x0a: return 11; break;
- case 0x0b: return 12; break;
- case 0x0c: return 13; break;
- case 0x0d: return 14; break;
- case 0x0e: return 15; break;
- case 0x0f: return 16; break;
- default : return 0; break;
- }
- }
- return 0;
- }
- return 0;
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void KeyWork(uchar key)
- {
- if(key)
- {
- if(key == 1)
- SetupMode();
-
- else if(key>=0 && key<=9)
- InputCipher(key);
- else if(key==12 || key==13)
- {
- if(BITinputing)
- ValidateCipher(key);
- }
- }
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:輸入密碼
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void InputCipher(cph)
- {
- InputCipherInterface(); //輸入密碼的界面
- if(BITinputing == 0)
- BITinputing = 1;
- Cipher = Cipher<<4 | cph;
- if(CipherBitNum < 8)
- CipherBitNum += 1;
- KeyTimeCon = 0x400; //8S回主界面
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:確認(rèn)或重輸密碼
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:將輸入的密碼和已設(shè)定的多個密碼相比較
- ********************************************************/
- void ValidateCipher(uchar key)
- {
- uchar i,j;
- uint cphaddr=CipherAddr;
- ulong cph=0;
- if(key == 12) //確定鍵
- {
- InputCipherNum += 1;
- for(j=0;j<CipherNum+1;j++)
- {
- for(i=0;i<4;i++)
- cph = cph<<8 + ReadEEPROM(cphaddr+i);
- if(cph == Cipher) //密碼正確
- {
- Lock = Open;
- Cipher = 0;
- CipherBitNum = 0;
- InputCipherNum = 0;
- BITinputnum0ut = 0;
- BITinputing = 0;
- KeyTimeCon = 0;
- BITcipherOK = 1;
- TimeInterface();
- Beep(1,Long);
- return;
- }
- cphaddr += 0x100;
- }
-
- if(j > CipherNum) //密碼不正確
- {
- Cipher = 0;
- CipherBitNum = 0;
- DisplayMoreWord(3,28,mimacuowu,16,0,5); //密碼錯誤!
- KeyTimeCon = 200;
- if(InputCipherNum == 3)
- {
- BITinputnum0ut = 1;
- InputCipherNum = 0;
- }
- Beep(2,Short);
- }
- }
- else //取消鍵
- {
- if(CipherBitNum == 0) //連按兩次取消鍵則返回主界面
- {
- Cipher = 0;
- BITinputing = 0;
- KeyTimeCon = 0;
- TimeInterface();
- Beep(1,Long);
- }
- else
- {
- CipherBitNum = 0;
- Cipher = 0;
- ClearRect(5,32,6,96);
- }
- }
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- uchar ValidateIDCard(void)
- {
- uchar i,j,idH,idM,idL,RidH,RidM,RidL;
- uint idaddr=CaedAddr;
- EX1 = 0;
- for(i=0;i<6;i++)
- {
- Card[i+5] -= 0x30;
- if(Card[i+5]>0x10)
- Card[i+5] -= 0x07;
- }
- idH = (Card[5]<<4) | Card[6];
- idM = (Card[7]<<4) | Card[8];
- idL = (Card[9]<<4) | Card[10];
- for(j=0;j<CardNum;j++)
- {
- RidL = ReadEEPROM(idaddr);
- RidM = ReadEEPROM(idaddr+1);
- RidH = ReadEEPROM(idaddr+2);
- if((idL == RidL) && (idM == RidM) && (idH == RidH))
- {
- Lock = Open;
- Beep(1,Long);
- EX1 = 1;
- return 1;
- }
- idaddr + 0x100;
- }
- if(j == CardNum)
- Beep(2,Short);
- EX1 = 1;
-
- return 0;
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:密碼模式主循環(huán)
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void CipherMode(void)
- {
- EX1 = 0; //關(guān)閉刷卡功能
- while(Mode == 0x88)
- {
- KeyWork(CheckKey());
- if(_testbit_(BITdispsec) && !BITinputing)
- RefurbishTime();
-
- if(_testbit_(BITtemp) && !BITinputing)
- RefurbishTemp();
- if(_testbit_(BITkeyout))
- {
- Cipher = 0;
- BITinputing = 0;
- CipherBitNum = 0;
- TimeInterface();
- }
- }
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:ID卡模式主循環(huán)
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void IDCardMode(void)
- {
- EX1 = 1;
- while(Mode == 0x44)
- {
- if(_testbit_(BITdispsec))
- RefurbishTime();
-
- if(_testbit_(BITtemp))
- RefurbishTemp();
- if(_testbit_(GetOneCard))
- ValidateIDCard();
- if(CheckKey() == 1)
- SetupMode();
- }
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:雙保險模式
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:先刷卡在輸密碼
- ********************************************************/
- void TwoSafetyMode(void)
- {
- EX1 = 1;
- while(Mode == 0x22)
- {
- if(_testbit_(BITdispsec))
- RefurbishTime();
-
- if(_testbit_(BITtemp))
- RefurbishTemp();
- if(_testbit_(GetOneCard))
- {
- if(ValidateIDCard() == 1)
- {
- KeyTimeCon = 500; //10S
- while(!BITkeyout && !BITinputnum0ut)
- KeyWork(CheckKey());
- if(!_testbit_(BITcipherOK))
- {
- BITinputnum0ut = 0;
- BITkeyout = 0;
- KeyTimeCon = 0;
- Cipher = 0;
- BITinputing = 0;
- CipherBitNum = 0;
- TimeInterface();
- }
- }
- }
- if(CheckKey() == 1)
- SetupMode();
- }
- }
- /*******************************************************
- * 函數(shù)名稱:
- * 函數(shù)功能:系統(tǒng)設(shè)置模式
- * 入口參數(shù):無
- * 出口參數(shù):無
- * 函數(shù)說明:
- ********************************************************/
- void SetupMode(void)
- {
-
- }
復(fù)制代碼
|
評分
-
查看全部評分
|