Graduation Project Embedded Intelligent Access Control System

Article directory

  • 1 Introduction
  • 2 Subject background
  • 3 detailed design
    • 3.1 Overall Design Scheme
    • 3.2 Functional modules
    • 3.3 Software Design
  • 4 Realize the effect
  • 5 part implementation code
  • 6 last

1 Introduction

Hi, everyone, today I would like to introduce to you a single-chip microcomputer project made by a senior.

Access control system based on single chip microcomputer

You can use it for course design or graduation design

2 Topic background

The basic components of the access control system mainly include identification, sensing and alarm, processing and control, electric lock and execution, management and setting.

Starting from the application point of view, this system mainly optimizes the design from two aspects for the use needs of families or small offices: one is to adhere to low power consumption design in hardware construction, and add power management module for power supply; the other is in software implementation, Try a variety of strategies to improve the response speed of the system, and consider the alarm processing in various situations to improve the security of the system.

3 Detailed Design

3.1 Overall design scheme

The main control chip of the forbidden system designed by the senior uses STM32 single-chip microcomputer STM32F103, the fingerprint recognition module uses ATK-AS608 module, and uses LCD12864 to display the result information of processing. Try various strategies to improve system recognition and response speed.

3.2 Functional modules

The main functions realized are:

Through the usb to serial port, the fingerprint entry is carried out.

Burn the program to the main control board STM32F103 through the programming software keil4, and the LCD12864 LCD screen will display “Please enter your fingerprint”. If the fingerprint module initialization fails, it will display “Entry fingerprint failed”. Use the input fingerprint to unlock, if the fingerprint identification is successful, the electromagnetic lock will be unlocked;

If the fingerprint recognition is unsuccessful, the voice prompts “Dingling Dingling”, and the LCD displays “Fingerprint Recognition Failed”.

The lock can also be unlocked through the password, and there are also three chances. Use the matrix keyboard to register and save the password in advance. When registering the password, 6-13 characters are required, and press the “#” key to end.

When you hear “Please enter the same password again”, enter the same password on the keypad again; when you hear “Password registered successfully”, the LCD screen will display that the addition is successful.

When unlocking with a password, if the matching fails three times, the system will alarm and the LCD will display “Failed to open the door”.

The structure of the system mainly includes 6 modules:

  • door lock control module
  • main control chip
  • Matrix keyboard module
  • Fingerprint Identification Module
  • LCD
  • power management module.

3.3 Software Design

Design a child lock function, the software implementation process is as follows:

Main program flow:


The main program mainly includes power-on initialization, fingerprint setting, password setting, fingerprint recognition module, relay drive module, password processing module, voice alarm module and other subroutines.

4 Realize the effect

5 part of the implementation code

Fingerprint module code:

#ifndef __TFS_M64_H
#define __TFS_M64_H
 
#include "stm32f10x.h"
 
#define TRUE 1
#define FALSE 0
 
//Basic response information definition
#define ACK_SUCCESS 0x00 //The operation is successful
#define ACK_FAIL 0x01 //operation failed
#define ACK_FULL 0x04 //The fingerprint database is full
#define ACK_NOUSER 0x05 //No such user
#define ACK_USER_EXIST 0x07 //User already exists
#define ACK_TIMEOUT 0x08 //Acquisition timeout
 
#define ACK_GO_OUT 0x0F
//User information definition
#define ACK_ALL_USER 0x00
#define ACK_GUEST_USER 0x01
#define ACK_NORMAL_USER 0x02
#define ACK_MASTER_USER 0x03
 
#define USER_MAX_CNT 50
 
//position definition
#define HEAD 0
#define CMD 1
#define CHK 6
#define TAIL 7
 
#define P1 2
#define P2 3
#define P3 4
#define Q1 2
#define Q2 3
#define Q3 4
 
//command definition
#define CMD_HEAD 0xF5
#define CMD_TAIL 0xF5
#define CMD_ADD_1 0x01
#define CMD_ADD_2 0x02
#define CMD_ADD_3 0x03
#define CMD_MATCH 0x0C
#define CMD_DEL 0x04
#define CMD_DEL_ALL 0x05
#define CMD_USER_CNT 0x09
#define CMD_SLEEP_MODE 0x2C
#define CMD_ADD_MODE 0x2D
 
#define CMD_FINGER_DETECTED 0x14
 
extern uint8_t gFpmTxBuf[9];
extern uint8_t gFpmRxBuf[9];
extern uint8_t gFpmRxCnt;
 
 
uint8_t fpm_sendAndReceive(uint16_t delayMs);
uint8_t fpm_sleep(void);
uint8_t fpm_setAddMode(uint8_t mode);
uint8_t fpm_readAddMode(void);
uint16_t fpm_getUserNum(void);
uint8_t fpm_deleteAllUser(void);
uint8_t fpm_deleteUser(uint8_t userNum);
uint8_t fpm_addUser(uint8_t userNum, uint8_t userPermission);
uint8_t fpm_compareFinger(void);
 
 

#include "tfs-m64.h"
#include "usart2.h"
#include "delay.h"
#include "usart.h"
///Fingerprint module: Fingerprint module
 
uint8_t gFpmTxBuf[9];
uint8_t gFpmRxBuf[9];
uint8_t gFpmRxCnt;
 
 
/**
  * @brief Send a command to the fingerprint module through the serial port and receive a response command
  * @param timeOut: timeout time (unit: ms), if no response command is received within this time, it will be processed as timeout
  * @retval response message
  */
uint8_t fpm_sendAndReceive(uint16_t timeout)
{<!-- -->
  uint8_t i, j;
  uint8_t checkSum = 0; // check code
\t 
  gFpmRxCnt = 0; //Clear the receive count, which is equivalent to clearing the buffer
gFpmTxBuf[5] = 0; //The sixth bit of command data is always zero
  
  /* Send 8-bit packet */
  usart2_sendByte(CMD_HEAD); //data header
  for (i = 1; i < 6; i ++ ) //intermediate data segment
  {<!-- -->
    usart2_sendByte(gFpmTxBuf[i]);
    checkSum ^= gFpmTxBuf[i];
  }
  usart2_sendByte(checkSum); //Check code
  usart2_sendByte(CMD_TAIL); //Data tail
 
  while (gFpmRxCnt < 8 & amp; & amp; timeout > 0)
  {<!-- -->
    delay_ms(1);
    timeout--;
  }
  
  if (gFpmRxCnt != 8) return ACK_TIMEOUT;
  if (gFpmRxBuf[HEAD] != CMD_HEAD) return ACK_FAIL;
  if (gFpmRxBuf[TAIL] != CMD_TAIL) return ACK_FAIL;
  if (gFpmRxBuf[CMD] != (gFpmTxBuf[CMD])) return ACK_FAIL;
 
  checkSum = 0;
  for (j = 1; j < CHK; j ++ ) {<!-- -->
    checkSum ^= gFpmRxBuf[j];
  }
if (checkSum != gFpmRxBuf[CHK]) {<!-- -->
    return ACK_FAIL;
  }
return ACK_SUCCESS;
}
 
/**
  * @brief Make the fingerprint module enter sleep mode
  * @param none
  * @retval response message (ACK_SUCCESS ACK_FAIL)
  */
uint8_t fpm_sleep(void)
{<!-- -->
  uint8_t res;
  
  gFpmTxBuf[CMD] = CMD_SLEEP_MODE;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = 0;
  gFpmTxBuf[P3] = 0;
  
  res = fpm_sendAndReceive(500);
  
  if(res == ACK_SUCCESS) {<!-- -->
    return ACK_SUCCESS;
  }
  else {<!-- -->
    return ACK_FAIL;
  }
  
}
 
/**
  * @brief Set the fingerprint adding mode
  * @param mode: Fingerprint adding mode (0: allow duplication 1: prohibit duplication)
  * @retval response message (ACK_SUCCESS ACK_FAIL)
  */
uint8_t fpm_setAddMode(uint8_t mode)
{<!-- -->
  uint8_t res;
  
  gFpmTxBuf[CMD] = CMD_ADD_MODE;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = mode;
  gFpmTxBuf[P3] = 0;
  
  res = fpm_sendAndReceive(200);
  
  if(res == ACK_SUCCESS & amp; & amp; gFpmRxBuf[Q3] == ACK_SUCCESS) {<!-- -->
    return ACK_SUCCESS;
  }
  else {<!-- -->
    return ACK_FAIL;
  }
}
 
/**
  * @brief Add mode for reading fingerprint
  * @param none
  * @retval Response information (0: allow repetition 1: prohibit repetition)
  */
uint8_t fpm_readAddMode(void)
{<!-- -->
  gFpmTxBuf[CMD] = CMD_ADD_MODE;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = 0;
  gFpmTxBuf[P3] = 0X01;
  
  fpm_sendAndReceive(200);
  
  return gFpmRxBuf[Q2];
}
 
/**
  * @brief Get the number of users (in fact, it should be the number of fingerprints, which is represented by the number of users here to be consistent with the expression of the communication protocol)
  * @param none
  * @retval response information (number of fingerprints)
  */
uint16_t fpm_getUserNum(void)
{<!-- -->
  uint8_t res;
  
  gFpmTxBuf[CMD] = CMD_USER_CNT;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = 0;
  gFpmTxBuf[P3] = 0;
  
  res = fpm_sendAndReceive(200);
  
  if(res == ACK_SUCCESS & amp; & amp; gFpmRxBuf[Q3] == ACK_SUCCESS) {<!-- -->
    return gFpmRxBuf[Q2];
  }
  else {<!-- -->
    return 0XFF;
  }
  
}
 
/**
  * @brief delete all fingerprints
  * @param none
  * @retval response message (ACK_SUCCESS ACK_FAIL)
  */
uint8_t fpm_deleteAllUser(void)
{<!-- -->
  uint8_t res;
  
  gFpmTxBuf[CMD] = CMD_DEL_ALL;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = 0;
  gFpmTxBuf[P3] = 0;
  
  res = fpm_sendAndReceive(200);
  
  if(res == ACK_SUCCESS & amp; & amp; gFpmRxBuf[Q3] == ACK_SUCCESS) {<!-- -->
    return ACK_SUCCESS;
  }
  else {<!-- -->
    return ACK_FAIL;
  }
}
 
/**
  * @brief Delete the fingerprint at the specified location
  * @param userNum: the location of the fingerprint (1-255)
  * @retval response message (ACK_SUCCESS ACK_FAIL)
  */
uint8_t fpm_deleteUser(uint8_t userNum)
{<!-- -->
  uint8_t res;
  
  gFpmTxBuf[CMD] = CMD_DEL;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = userNum;
  gFpmTxBuf[P3] = 0;
  
  res = fpm_sendAndReceive(200);
  
  if(res == ACK_SUCCESS & amp; & amp; gFpmRxBuf[Q3] == ACK_SUCCESS) {<!-- -->
    return ACK_SUCCESS;
  }
  else {<!-- -->
    return ACK_FAIL;
  }
}
 
/**
  * @brief Enroll fingerprint
  * @param userNum: The location where the fingerprint is stored (1-255)
  * @param userPermission: User permission (1-3), the specific meaning is defined by yourself.
  * @retval response message (ACK_SUCCESS ACK_FAIL ACK_USER_EXIST ACK_TIMEOUT)
  */
uint8_t fpm_addUser(uint8_t userNum, uint8_t userPermission)
{<!-- -->
  uint8_t res;
  
  gFpmTxBuf[CMD] = CMD_ADD_1;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = userNum;
  gFpmTxBuf[P3] = userPermission;
  
  res = fpm_sendAndReceive(30000);
 
  if(res == ACK_SUCCESS) {<!-- -->
    if(gFpmRxBuf[Q3] == ACK_SUCCESS) {<!-- -->
      gFpmTxBuf[CMD] = CMD_ADD_2;
      
      res = fpm_sendAndReceive(30000);
      
      if(res == ACK_SUCCESS) {<!-- -->
        if(gFpmRxBuf[Q3] == ACK_SUCCESS) {<!-- -->
          gFpmTxBuf[CMD] = CMD_ADD_3;
          
          res = fpm_sendAndReceive(30000);
          
          if(res == ACK_SUCCESS) {<!-- -->
            return gFpmRxBuf[Q3];
          }
        }
      }
    }
  }
  return res;
 
}
 
/**
  * @brief Compare fingerprints by 1:N method
  * @param none
  * @retval match fingerprint information
  */
uint8_t fpm_compareFinger(void)
{<!-- -->
  uint8_t res;
  
  gFpmTxBuf[CMD] = CMD_MATCH;
  gFpmTxBuf[P1] = 0;
  gFpmTxBuf[P2] = 0;
  gFpmTxBuf[P3] = 0;
  
  res = fpm_sendAndReceive(30000);
  
  if(res == ACK_SUCCESS)
  {<!-- -->
    if(gFpmRxBuf[Q3] == ACK_NOUSER) {<!-- -->
      return ACK_NOUSER;
    }
    if(gFpmRxBuf[Q3] == ACK_TIMEOUT) {<!-- -->
      return ACK_TIMEOUT;
    }
    if((gFpmRxBuf[Q2] != 0) & amp; & amp; (gFpmRxBuf[Q3] == 1 || gFpmRxBuf[Q3] == 2 || gFpmRxBuf[Q3] == 3)) {<!-- -->
      return ACK_SUCCESS;
    }
  }
  return res;
}


6 Last