Design and simulation of electronic password lock based on STC89C52 single chip microcomputer

Publisher:一条属马的龙Latest update time:2010-11-19 Source: 现代电子技术Keywords:Protues Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0. Introduction

Electronic password locks are commonly used encryption tools in modern life. They overcome the shortcomings of mechanical password locks, such as small passwords and poor security performance, especially the intelligent electronic password locks; they not only have the functions of electronic password locks, but also introduce intelligent management functions, making the password locks more secure and reliable.

Electronic password locks are usually controlled by ARM and single-chip microcomputers. Compared with ARM, single-chip microcomputers are simpler to implement and have more complete functions, so single-chip microcomputers are more commonly used. Code locks controlled by single-chip microcomputers are often programmed in assembly language, and most displays are in C. The electronic password lock introduced in this article is written in C language, a high-level language with strong portability and readability, which is convenient for modification and addition and subtraction of functions. At the same time, it uses a clear digital tube, a liquid crystal display with low power consumption and long life, and the display is more intuitive and more convenient to use. From the perspective of economy and practicality, an electronic password lock with password setting, alarm and prevention of multiple password attempts is designed using STC89C52 single-chip microcomputer, and it is successfully simulated by Protues software.

1. System working principle

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

When the user enters a 6-digit password and presses the BESURE key, the microcontroller compares the passwords one by one. If the entered 6-digit honey code is exactly the same as the set password, the *simulation light can be successfully driven to open the lock. If the entered 6-digit password is different from the set password, after pressing the BESURE key, the simulation light will not light up, and you can press the BACK key to re-enter it. Since input errors are inevitable during the password input process, if the password is entered incorrectly, you can directly press the BACK key to re-enter it, but the system does not allow unlimited pressing of the BACK key to prevent the password from being applied. When the password is entered incorrectly 3 times, the microcontroller will drive the buzzer to alarm. In addition, this system has a time limit for entering the password. If the correct password is not entered within the specified time, an alarm will also be triggered.

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 open the lock.

2. System design

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

2.1 Hardware Support

2.2 Software Design

The system software package includes main program module, code comparison and judgment module, password modification module, keyboard scanning module, LCD display module and timing program module. The system program flow is shown in Figure 1.


Figure 1 System program flow chart

2.2.1 Main program module

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

2.2.2 Password comparison module

The function of this module is to compare the password input by the keyboard with the set password one by one using IF statements. If the password is completely correct, it will be *; if incorrect, press the BACK key and re-enter the password. Each time the BACK key is pressed, the number of inputs will increase by 1. When all 3 errors are made, an alarm will be triggered.

2.2.3 Password modification module

When the password is entered correctly, you can press SET to reset the password. Each time you set a digit, the password will be 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 newly set password.

STC89C52 writes password to AT24C02 subroutine: void wrtte_byte (uchar date)



STC89C52 reads the password subroutine from AT24C02:


2.2.4 Keyboard Scanning Module

The module has the following functions: scanning the specific positions of the keys pressed column by column, judging whether any keys are pressed, eliminating jitter, judging whether the closed keys are released, etc.

2.2.5 Timing module

This module is used to control the password input time. When the program is running, the timer is initialized first. When the PUT IN key is pressed, the system starts timing. When the input time reaches the specified time, an alarm will be triggered immediately.

2.2.6 LCD display module

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

3 System Simulation

In order to facilitate the program height, this paper adopts Protues simulation, and the simulation diagram is shown in Figure 2.


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, and the pin connection is shown in Figure 2; the independent button DOOR is in the key pressed state when the door is closed; D1 is an analog * light, and when the password is correct, press the BESURE key and D1 will light up; 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 liquid crystal display will prompt the running status of the password lock, and the system starts working.

3.2* Function

When the power is turned on, the 1602 LCD displays the Welcome interface. When the PUT IN button is pressed, the display shows PUT IN CODES prompting the user to enter the password, as shown in Figure 3. After a few seconds, the prompt on the LCD will automatically disappear. Now you can enter the correct password, and the password will be displayed while entering the password, but the entered data will not be displayed. When the password is entered, press the BESURE button. If the password is correct, D1 will light up (D1 is an analog switch for *). If the password is wrong, you can press the BACK button, the program will jump to the loop (start interface), re-enter the password, and the number of inputs will increase by one. If the input is wrong for 3 times, an alarm will be automatically triggered, and the time to enter the password must be completed within the specified time, otherwise an alarm will be triggered.


3.3 Password Setting

After the password is entered correctly, press the SET button 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 digits will be displayed. Each time you enter a password, you need to press the YES button to confirm. When the set password reaches 6 digits, it will automatically return to the startup interface.

4. Conclusion

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

(2) Programs are written in C language, which has strong portability and facilitates system additions, deletions and modifications.

Keywords:Protues Reference address:Design and simulation of electronic password lock based on STC89C52 single chip microcomputer

Previous article:Design of intelligent car based on 80C51 single chip microcomputer
Next article:Implementation of serial communication between PC and single chip microcomputer based on duplex mode

Recommended ReadingLatest update time:2024-11-16 19:53

Design and simulation of electronic password lock based on STC89C52 single chip microcomputer
0. Introduction Electronic password locks are commonly used encryption tools in modern life. They overcome the shortcomings of mechanical password locks, such as small passwords and poor security performance, especially the intelligent electronic password locks; they not only have the functions of electroni
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号