#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 //存放卡个数的地址
#define CaedAddr 0x700 //存放卡号的地址
#define CipherNumAddr 0x1234 //存放密码个数的地址
#define CipherAddr 0x2000 //存放密码的地址
#define RootCipherAddr 0x4567 //存放系统管理密码的地址
#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[];
/*******************************************************
* 函数名称:Init_Timer()
* 函数功能:
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
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;
}
/*******************************************************
* 函数名称:Time0_INT()
* 函数功能:
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
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;
}
/*******************************************************
* 函数名称:Time1_INT()
* 函数功能:
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
void Time1_INT(void) interrupt 3
{
ET1=0;
TR1=0;
TL1=0x00;
TH1=0x70;
TR1=1;
ET1=1;
}
/*******************************************************
* 函数名称:
* 函数功能:
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
void SystemInit(void)
{
uint dat;
// Lock = Open;
LCDInit();
Init_Timer();
DS18B20Init(0x7f,0x64,0x8a);
DS18B20StartConvert();
dat = ReadEEPROM(SelfCheckAddr+1); //读系统自检标饰位
dat = (dat<<8) | ReadEEPROM(SelfCheckAddr);
if(dat == 0xAA55) //系统已经初始化过
{
CardNum = ReadEEPROM(CardNumAddr);
CipherNum = ReadEEPROM(CipherNumAddr);
Mode = ReadEEPROM(ModeAddr);
}
else //系统第一次使用
{
WriteEEPROM(SelfCheckAddr,0xAA55); //标记系统已设置过
WriteEEPROM(CipherAddr,0x5678); //初始化系统管理员密码为 12345678
WriteEEPROM(CipherAddr,0x1234);
CardNum = 0;
WriteEEPROM(CardNumAddr,CardNum);
CipherNum = 0;
WriteEEPROM(CipherNumAddr,CipherNum);
Mode = 0x88;
WriteEEPROM(ModeAddr,Mode); //默认为密码模式
}
TimeInterface();
EA = 1;
}
/*******************************************************
* 函数名称:
* 函数功能:
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
void Beep(uchar num,bit state)
{
while(BITbeepwait);
BeepNum = (num<<1)-1; //蜂鸣器响的次数
if(state) //鸣叫时间=BeepCopyTime*20ms
BeepCopyTime = 10; //短鸣
else
BeepCopyTime = 30; //长鸣
BeepTimeCon = BeepCopyTime;
BITbeep = 1;
BITbeepwait = 1;
}
/*******************************************************
* 函数名称:
* 函数功能:
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
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;
}
/*******************************************************
* 函数名称:
* 函数功能:
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
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);
}
}
}
/*******************************************************
* 函数名称:
* 函数功能:输入密码
* 入口参数:无
* 出口参数:无
* 函数说明:
********************************************************/
void InputCipher(cph)
{
InputCipherInterface(); //输入密码的界面
if(BITinputing == 0)
BITinputing = 1;
Cipher = Cipher<<4 | cph;
if(CipherBitNum < 8)
CipherBitNum += 1;
KeyTimeCon = 0x400; //8S回主界面
}
/*******************************************************
* 函数名称:
* 函数功能:确认或重输密码
* 入口参数:无
* 出口参数:无
* 函数说明:将输入的密码和已设定的多个密码相比较
********************************************************/
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
{
Ciph
门禁系统源码,门禁系统源码
4星 · 超过85%的资源 需积分: 5 134 浏览量
2012-06-27
18:58:23
上传
评论 9
收藏 583KB RAR 举报
dy27591947
- 粉丝: 1
- 资源: 9
最新资源
- 基于CarNet实现裂缝检测python源码+文档说明+数据+图片(课程设计)
- 课程设计-基于耐火材料裂缝剥落检测python源码+课件
- 基于OpenCV的视频道路车道检测python源码+文档说明+实验演示+图片+使用方法(高分毕业设计)
- 基于OpenCV的案例:图像边缘、角点和轮廓检测,图像分割,图像增强;图片拼接;运动目标检测,颜色直方图比较,三帧帧差法,抠图
- SmartPlug-html大一笔记
- SmartPlug-proteusdemo
- Preliminary Findings on Handmade Rattan Baby Crib andBassinet Designs Regarding.zip
- aveebfq_v1.2.83_downyi.com.apk
- 基于有机发光二极管(OLED)的建模优化算法的matlab仿真源码+数据+文档说明+项目说明(高分课程设计)
- hash01-test.c 本人哈希表(一)的示例代码,仅供参考!
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页