Design of electronic code lock with STC89C52 microcontroller as the core

Publisher:skyhcgLatest update time:2023-10-12 Source: elecfansKeywords:STC89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

Electronic code lock is a commonly used encryption tool in modern life. It overcomes the shortcomings of mechanical password locks with small passwords and poor security performance, especially the smart electronic password locks with microcontrollers; it not only has the function of an electronic password lock, but also introduces intelligent management functions, so that the password lock has More security and reliability.


Electronic combination locks are usually controlled by ARM and microcontroller. Compared with ARM, microcontroller is simpler to implement and has more complete functions, so it is more controlled by microcontroller. Cellar code locks controlled by microcontrollers often use assembly language to write programs, and most displays use digital tubes. The electronic key lock introduced in this article is written in C language, a high-level language with strong portability and readability, which is easy to modify and add or delete functions. It also uses a 1602 LCD display with clear display, low power consumption and long life, making the display more intuitive. , more convenient to use. From an economic and practical point of view, an electronic password lock with password setting, alarm and prevention of multiple password attempts was designed using STC89C52 microcontroller, and was successfully simulated through Protues software.


1. System working principle

This system takes the STC89C52 microcontroller as the core, uses a 4X4 matrix keyboard as the data input method, and drives the 1602 display to prompt the program running process and specific steps. The password judgment process of this system is as follows:

When the user enters the 6-digit password and presses the BESURE button, the microcontroller compares the passwords one by one. If the entered 6-digit password is exactly the same as the set password, the * simulation light can be successfully driven to open the lock. If the 6-digit password entered is not the same as the set password, and the analog light does not light up after pressing the BESURE button, you can press the BACK button to re-enter. Since it is inevitable to make mistakes when entering the password, if you enter the wrong password, you can directly save the BACK key and re-enter it. However, the system does not allow unlimited pressing of the BACK key to prevent the password from being applied. When the password is entered incorrectly three times, the microcontroller will drive Buzzer alarm. Moreover, this system has a time limit for entering the password. If the correct password is not entered within the specified time, an alarm will be issued.

The password modification function is as follows: when the password is entered correctly, press the SET key to set a new password. Each time a new password is set, the microcontroller sends it to the EPROM. When all 6 new passwords are entered, the system will automatically return to the beginning of the program, re-read the password and save it. The user needs to enter a new password to lock the lock. Open.


2. System design

2.1 Hardware support

The components used are: core chip STC89C52, memory chip AT24C02, LCD display 1602, matrix keyboard, alarm buzzer, independent button (simulation door switch), light-emitting diode (simulation lock switch) and transistor (amplification current) .


2.2 Software design

本系统软件包插主程序模块、甯码比较判断模块、修改密码模块、键盘扫描模块、液晶显示模块及定时程序等模块。系统程序流程如图1所示。

Design of electronic code lock with STC89C52 microcontroller as the core

Figure 1 System program flow chart


2.2.1 Main program module

The master sequence is mainly used to define global variables, assign initial values ​​to global variables, initialize EPROM, start the timer and read passwords from AT24C02 to provide data for the entire program.


2.2.2 Password comparison and judgment module

The function of this module is to compare the password entered by the keyboard with the set password one by one using the IF statement. If the password is completely correct, *; if it is incorrect, press the BACK key and re-enter the password. Each time the BACK key is pressed, The number of inputs will be incremented by 1. When all 3fi are wrong, an alarm will be issued.


2.2.3 Password modification module

When the cellar code is entered correctly, you can press SET to reset the password. Each time a digit is set, the password is sent to AT24C02 for storage. When the 6-digit password is set, the system will automatically jump to the beginning of the program and call the new password. The set code.

STC89C52 writes the codon subroutine to AT24C02:

void wrtte_byte(uchar date)

Design of electronic code lock with STC89C52 microcontroller as the core

STC89C52 reads codon program from AT24C02:

Design of electronic code lock with STC89C52 microcontroller as the core

2.2.4 Keyboard scanning module

This module has functions such as: scanning the keyboard column by column for the specific position of the pressed key, determining whether a key is pressed on the keyboard, eliminating jitter, and determining whether a closed key is released.


2.2.5 Timing module

This module is used to control the password input time. When the program is running, the timer is first initialized. Starting from pressing the PUT IN key, the system starts timing. When the input time reaches the specified time, it will immediately alarm.


2.2.6 LCD module

This module includes LCD initialization, command input, and display data input. The commands are used to control whether the LCD status displays the cursor, whether the cursor flashes, whether to clear the original data and the specific position of the display. Data display mainly requires that the information to be displayed be displayed on time.


3 System Simulation

To facilitate program height. This article uses Protues simulation, and the simulation diagram is shown in Figure 2.

Design of electronic code lock with STC89C52 microcontroller as the core

3.1 System introduction

In Figure 2, U1 is STC89C52, which is the core of the system. The written program is imported into it as a binary file; U2 is AT24C02, and the 5th and 6th pins are connected to P1.2 and P1.3 of the microcontroller respectively; LCD1 is a 1602 liquid crystal Display, pin connection is shown in Figure 2; independent button DOOR, when the door is closed, the button is pressed; D1 is an analog * light, when the password is correct, D1 will light up when the BESURE button is pressed; BUZ1 is a buzzer alarm. After the program is written and imported into the microcontroller, press the start button at the bottom of Figure 2. The 1602 LCD will prompt the operating status of the password lock and the system will start working.


3.2*Function

When the power is turned on, the 1602 LCD displays the Welcome interface. When the PUT IN key is pressed, the display displays PUT IN CODES prompting you to enter the password, as shown in Figure 3. The prompt on the LCD will disappear automatically after a few seconds. In this way, you can enter the correct password, and * will be displayed when entering the password without displaying the entered data. After entering the password, press the BESURE key. If the password entered is correct, D1 will light up (D1 serves as an analog switch for *). If the password is wrong, you can press the BACK key, the program will jump to the loop (start interface), re-enter the password, and the number of input times will increase by one. When incorrect input is made three times, an alarm will be automatically issued, and the time for entering the password must be completed within the specified time, otherwise an alarm will be issued.


3.3 Password setting

After the password is entered correctly, press the SET key to reset the password, and the LCD will display SET CODS. The prompt will automatically disappear after a few seconds, and the password reset will begin. During the password setting process, the set numbers will be displayed. Each time you enter a password, you must press the YES key to confirm. When the set password reaches 6 digits, it will automatically return to the startup interface.


4 Conclusion

(1) Successfully simulated the 1602 LCD display, password*, password setting, prevention of multiple attempts, alarm and other functions.

(2) The program is written in C language, which has strong portability and facilitates the addition, deletion and modification of the system.


Keywords:STC89C52 Reference address:Design of electronic code lock with STC89C52 microcontroller as the core

Previous article:51 microcontroller serial communication programming
Next article:A/D conversion implementation based on AT89CX051

Popular Resources
Popular amplifiers
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号