毕业设计(论文)基于单片机的电子密码锁设计TheDesignofElectronicPassword-lockwithSCM:********:电气与信息学院:*****:****:*****:副教授:2008年6月20日学生姓名所在院系所学专业所在班级指导教师教师职称完成时间(论文)摘要随着电子产品向智能化和微型化的不断发展,单片机已成为电子产品研制和开发中首选的控制器。随着人们生活水平的提高,如何实现家庭防盗这一问题也变的尤其的突出,传统的机械锁由于其构造的简单,安全性能低,无法满足人们的需要。本文从经济实用的角度出发,采用美国Atmel公司的单片机AT89S51与低功耗CMOS型E2PROMAT24C02作为主控芯片与数据存储器单元,结合外围的键盘输入、显示、报警、开锁等电路,用汇编语言编写主控芯片的控制程序,设计了一款可以多次更改密码具有报警功能的电子密码锁。经实验证明,该密码锁具有设计方法合理,简单易行,成本低,安全实用等特点,符合住宅、办公室用锁要求,具有推广价值。(论文)目录1引言······························································································11.1电子密码锁简介········································································11.2电子密码锁的发展趋势·······························································11.3本设计所要实现的目标·······························································22设计方案的选择···············································································32.1方案一:采用数字电路控制·························································32.2方案二:采用以单片机为核心的控制方案······································33主要元器件介绍···············································································43.1主控芯片AT89S51····································································43.2存储芯片AT24C02····································································93.3LCD1602显示器·····································································103.4晶体振荡器············································································124系统硬件构成················································································134.1设计原理···············································································134.2电路总体构成·········································································134.3电源输入部分·········································································144.4键盘输入部分·········································································154.5密码存储部分·········································································154.6复位部位···············································································164.7晶振部分···············································································174.8显示部分···············································································184.9报警部分···············································································184.10开锁部分···············································································195系统软件设计················································································206结论····························································································24谢辞·································································································25(论文)参考文献:························································································25附录一······························································································27附录二·····································································错误!未定义书签。(论文)11引言1.1电子密码锁简介电子密码锁是一种通过密码输入来控制电路或是芯片工作,从而控制机械开关的闭合,完成开锁、闭锁任务的电子产品。它的种类很多,有简易的电路产品,也有基于芯片的性价比较高的产品。现在应用较广的电子密码锁是以芯片为核心,通过编程来实现的。其性能和安全性已大大超过了机械锁。其特点如下:1)保密性好,编码量多,远远大于弹子锁。随机开锁成功率几乎为零。2)密码可变,用户可以随时更改密码,防止密码被盗,同时也可以避免因人员的更替而使锁的密级下降。3)误码输入保护,当输入密码多次错误时,报警系统自动启动。4)无活动零件,不会磨损,寿命长。5)使用灵活性好,不像机械锁必须佩带钥匙才能开锁。6)电子密码锁操作简单易行,一学即会]4[。1.2电子密码锁的发展趋势在日常生活和工作中,住宅与部门的安全防范、单位的文件档案、财务报表以及一些个人资料的保存多以加锁的办法来解决。目前门锁主要用弹子锁,其钥匙容易丢失;保险箱主要用机械密码锁,其结构较为复杂,制造精度要求高,成本高,且易出现故障,人们常需携带多把钥匙,使用极不方便,且钥匙丢失后安全性即大打折扣。针对这些锁具给人们带来的不便若使用机械式钥匙开锁,为满足人们对锁的使用要求,增加其安全性,用密码代替钥匙的密码锁应运而生。它的出现为人们的生活带来了很大的方便,有很广阔的市场前景。由于电子器件所限,以前开发的电子密码锁,其种类不多,保密性差,最基本的就是只依靠最简单的模拟电子开关来实现的,制作简单但很不安全,在后为多是基于EDA来实现的,其电路结构复杂,电子元件繁多,也有使用早先的20引角的2051系列单片机来实现的,但密码简单,易破解。随着电子元件的进一步发展,电子密码锁也出现了很多的种类,功能日益强大,使用更加方便,安全保密性更强,由以前的单密码输入发展到现在的,密码加感应元件,实现了真真的电子加密,用户只有密码或电子钥匙中的一样,是打不开锁的,随着电子元件的发展及人们对保密性需求的提高出现了越来越多的电子密码锁]10[。出于安全、方便等方面的需要许多电子密码锁已相继问世。但这类产品的特点是针对特定有效卡、指纹或声音有效,且不能实现远程控制,只能适用于保密要求高且供个人使用的箱、柜、房间等。由于数字、字符、图形图像、人体生物特征和时间等要素均可成为钥匙的电子信息,组合使用这些信息能够使电子防盗锁获得高度的保密性,如防范森严的金库,需要使用复合信息密码的电子防盗锁,这样对盗贼而言是“道高一尺、魔高一丈”。组合使用(论文)2信息也能够使电子防盗锁获得无穷扩展的可能,使产品多样化,对用户而言是“千挑百选、自得其所”。可以看出组合使用电子信息是电子密码锁以后发展的趋势]8[。1.3本设计所要实现的目标本设计采用单片机为主控芯片,结合外围电路,组成电子密码锁,用户想要打开锁,必先通过提供的键盘输入正确的密码才能将锁打开,密码输入错误有提示,为了提高安全性,当密码输入错误三次将报警。密码可以由用户自己修改设定,锁打开后才能修改密码。修改密码之前必须再次输入密码,在输入新密码时候需要二次确认,以防止误操作。(论文)32设计方案的选择2.1方案一:采用数字电路控制用以74LS112双JK触发器构成的数字逻辑电路作为密码锁的核心控制,共设了9个用户输入键,其中只有4个是有效的密码按键,其它的都是干扰按键,若按下干扰键,键盘输入电路自动清零,原先输入的密码无效,需要重新输入;如果用户输入密码的时间超过10秒(一般情况下,用户不会超过10秒,若用户觉得不便,还可以修改)电路将报警20秒,若电路连续报警三次,电路将锁定键盘2分钟,防止他人的非法操作]12[。采用数字电路设计的方案好处就是设计简单但控制的准确性和灵活性差。故不采用2.2方案二:采用以单片机为核心的控制方案由于单片机种类繁多,各种型号都有其一定的应用环境,因此在选用时要多加比较,合理选择,以期获得最佳的性价比。一般来说在选取单片机时从下面几个方面考虑:性能、存储器、运行速度、I/O口、定时/计数器、串行接口、模拟电路功能、工作电压、功耗、封装形式、抗干扰性、保密性,除了以上的一些的还有一些最基本的比如:中断源的数量和优先级、工作温度范围、有没有低电压检测功能、单片机内有无时钟振荡器、有无上电复位功能等。在开发过程中单片机还受到:开发工具、编程器、开发成本、开发人员的适应性、技术支持和服务等等因素]1[。基于以上因素本设计选用单片机AT89S51作为本设计的核心元件,利用单片机灵活的编程设计和丰富的I/O端口,及其控制的准确性,实现基本的密码锁功能。在单片机的外围电路外接输入键盘用于密码的输入和一些功能的控制,外接AT24C02芯片用于密码的存储,外接LCD1602显示器用于显示作用。当用户需要开锁时,先按键盘开锁键之后按键盘的数字键0-9输入密码。密码输完后按下确认键,如果密码输入正确则开锁,不正确显示密码错误重新输入密码,当