利用数字电路实现电子密码锁
学生:XXX 指导老师:XXX
内容摘要:本数字密码锁采用单片机AT89S52为主控芯片,由EEPROM存储密码。硬
件部分包括主控制系统、人机交互界面以及输出系统三大部分。
主控制系统中主控制芯片使用了AT89S52单片机,该单片机性能优良,能满足一般的普通应用;EEPROM采用AT24C02芯片,掉电后可以存储密码,从而保证了系统的安全性。人机交互通道部分采用了4×4矩阵键盘输入以及LCD1602标准字符型液晶显示。输出系统部分包括驱动开锁电路和报警电路;其中,在本系统设计中,驱动开锁电路用发光二极管表示,而报警电路则使用蜂鸣器。
本系统中使用的AT24C02芯片是一个带有I2C总线接口的EEPROM存储器。I2C总线是一种双向二线制总线,它的结构简单,可靠性和抗干扰性能好。I2C总线结构很简单,只有两条线,包括一条数据线(SDA)和一条串行时钟线(SCL)。具有I2C接口的器件可以通过这两根线接到总线上,进行相互之间的信息传递。
本数字密码锁的功能为:密码位数为8位,可选值为0~9,从而保证足够的锁体强度;用户可以自行设定和修改密码;防止密码被盗,输入密码错误次数超过3次则报警;友好的人机界面;输入正确的密码后,驱动开锁电路。
软件部分应用单片机C语言实现了本设计的全部控制功能。C语言编译方便,易读性好,且移植性方便,能够满足实现本系统的功能要求。在设计过程中,给出了本系统C语言编程的原理和流程图。
本数字密码锁系统稳定性好,设计人性化,由于使用单片机控制并有记忆模块,功能齐全可靠,并有很好的扩展性,而且成本低廉,具有良好的发展前景。
关键词:数字密码锁 AT24C02芯片 安全性
I
Electronic combination lock
Abstract:Using the digital circuit realize electronic combination lock
This digital locks USES the monolithic integrated circuit AT89S52 as the controller chip, by EEPROM memory password. Hardware including master control system, man-machine interface and output system of three.
The Lord control system used in the control chip AT89S52 SCM, this single chip good performance, can satisfy the general common application; The AT24C02 chip EEPROM, after power off can be stored password, so as to ensure the security of the system. Man-machine interactive channel part adopts the 4 x 4 matrix keyboard input and LCD1602 standard character type LCD display. The output of system including drive circuit and alarm lock circuit; Which, in the system design, drive the lock circuit using light-emitting diodes said, and alarm circuit is using a buzzer.
The system used AT24C02 chip is a with the I2C bus interface EEPROM memory. The I2C bus is a two-way two wire bus, its simple structure, reliability and anti-interference capability. The I2C bus structure is simple, only two lines, including a data line (SDA) and a serial clock line (SCL). Has the I2C devices through this interface to two lines on the bus, the mutual information transfer.
This digital locks function for: password digits for eight, optional value is 0 ~ 9, so as to ensure enough lock body strength; The user can set and modify the password; To prevent the password is stolen, the input password mistake number more than three times the alarm; Friendly human-machine interface; To enter the correct password, drive the lock circuit.
Application software of single chip microcomputer C language realized this design of all control function. C compiler convenient, easy to read the gender is good, and easy portability, and can meet the requirement of system function realization. In the design process are given, and the system of the C programming language principle and flow chart.
This digital locks system stability, humanized design, because use a
II single-chip microcomputer control and a memory module, complete function and reliable, and have a good scalability, and the cost is low, have good development prospect.
Keywords: Electronic combination lock AT24C02 chip safety
III
目 录
前言 ..................................................................... 1 1 系统的硬件设计 ......................................................... 2 1.1 硬件的总体结构和原理 ............................................... 2 1.1.1 硬件系统的总体结构图 ........................................... 2 1.1.2 硬件系统组成 ................................................... 2 1.1.3 系统的可能性分析 ............................................... 3 1.2 单片机AT89S51简介 ................................................ 4 1.2.1 主要性能 ....................................................... 4 1.2.2 引脚功能描述 ................................................... 5 1.3 AT24C02简介 ........................................................ 7 1.3.1 功能描述 ....................................................... 7 1.3.2 管脚描述 ....................................................... 7 1.3.3 I2C总线协议 .................................................... 8 1.4 LCD1602介绍 ........................................................ 8 1.4.1 引脚描述 ....................................................... 9 1.4.2 LCDI602控制指令 ................................................ 9 1.4.3 LCDI602读写控制时序 ........................................... 11 1.5 4×4矩阵键盘 ...................................................... 11 1.6 复位电路 .......................................................... 12 1.7 振荡电路 .......................................................... 12 1.8 发光二极管LED电路 ................................................ 13 1.9 报警电路 .......................................................... 13 1.10 电源输入电路 ..................................................... 14 1.11 使用到的元器件列表 ............................................... 15 2 软件程序设计 .......................................................... 15 2.1 编译器Keil uVision2简介 .......................................... 16 2.2 软件总设计流程图 .................................................. 16 2.3 具体功能软件实现 .................................................. 17 2.3.1 4×4矩阵键盘扫描程序 .......................................... 17
IV 2.3.2 显示程序 ...................................................... 19 2.3.3 时钟运行子程序 ................................................ 19 2.3.4 时钟时、分修改子程序 .......................................... 20 2.3.5 掉电存储服务程序 .............................................. 21 2.3.7 密码修改子程序 ................................................ 23 3 结束语 ............................................................... 24 附录1: PCB原理图 ...................................................... 26 附录2: 仿真原理图 ...................................................... 27 附录3: 单片机硬件实物图 ................................................ 28 参考文献 ................................................................ 29
V