Simple fingerprint lock source program based on AS608 and 51 single chip microcomputer

Publisher:RadiantGlowLatest update time:2019-11-23 Source: 51heiKeywords:AS608 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

My roommate always forgets to bring his keys, so I made a simple fingerprint lock. Six people in the dormitory use it. This is the first time I upload it. It's quite crude. I wrote a very detailed comment (I think).
If it can help you, it will be great.

The microcontroller source program is as follows:

#include

#include


sbit zhen=P2^0; //The motor rotates forward, pull the handle to open the door

sbit fan=P2^1; //motor reverses, resets door handle

sbit led_work=P2^2; //MCU has completed initialization, indicating LED and detecting door handle position indicator

sbit check=P2^3; //Reed switch position detection, door open is 1

sbit pressed=P2^6; //Fingerprint module touch detection

sbit wakeup=P2^7; //Fingerprint module power-on control, 1 means the module is powered on, 0 means it is powered off

sbit test=P3^3; //Test door opening



//////////////////////////////////////////////////////////////////////////

volatile unsigned char FPM10A_RECEICE_BUFFER[32]; //define the receive buffer

code unsigned char FPM10A_Pack_Head[6] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF}; //Protocol header

code unsigned char FPM10A_Get_Img[6] = {0x01,0x00,0x03,0x01,0x00,0x05}; //Get fingerprint image

code unsigned char FPM10A_Img_To_Buffer1[7]={0x01,0x00,0x04,0x02,0x01,0x00,0x08}; //Put the image into BUFFER1

code unsigned char FPM10A_Search[11]={0x01,0x00,0x08,0x04,0x01,0x00,0x00,0x00,0x64,0x00,0x72}; //Search fingerprint search range 0 - 999, use the signature in BUFFER1 to search


//////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////

// Timing //

/////////////////////////////////////////////

void delay1s(void) //timing 1S, crystal oscillator 11.0592MHZ

{

    unsigned char a,b,c;

    for(c=13;c>0;c--)

        for(b=247;b>0;b--)

            for(a=142;a>0;a--);

    _nop_(); //if Keil,require use intrins.h

}


void delay100ms(void) //timing 100MS, crystal 11.0592MHZ

{

    unsigned char a,b;

    for(b=221;b>0;b--)

        for(a=207;a>0;a--);

}



void delay500ms(void) //500ms

{

    unsigned char a,b,c;

    for(c=98;c>0;c--)

        for(b=127;b>0;b--)

            for(a=17;a>0;a--);

    _nop_();

}


void delay1_6_f(void) //error 0us

{

    unsigned char a,b,c;

    for(c=218;c>0;c--)

        for(b=131;b>0;b--)

            for(a=23;a>0;a--);

    _nop_(); //if Keil,require use intrins.h

}


void delay50ms(void) //error 0us

{

    unsigned char a,b;

    for(b=173;b>0;b--)

        for(a=143;a>0;a--);

}


void delay10ms(void) //error 0us

{

    unsigned char a,b,c;

    for(c=1;c>0;c--)

        for(b=38;b>0;b--)

            for(a=130;a>0;a--);

}


/////////////////////////////////////////////



void kaisuo(void)

{

        int t;

        zhen=fan=0;

        zhen=1; //Motor starts forward

        for(t=0;t<45;t++) //50ms is one segment, totaling 2.25s, to control the maximum pulling time to prevent the handle from being damaged by accidental forward rotation for too long

        {

        if(check==0)

                {

                 delay10ms(); //Wait for 10ms, the reed switch will debounce

                 if(check==0) //check again

                 {

                 led_work=0; // detect that the handle is in place, the indicator light turns off to indicate

                 zhen=0; //motor stop

                 delay100ms(); //Wait 100ms, prepare for reversal

                 //delay500ms(); //Wait for 500ms, prepare for reversal

                 fan=1;

                 delay1_6_f(); //Reverse 1.6s

                 fan=0;

                 led_work=1; //status indicator light reset

                 check=1;

                 return; //Break out of the loop

                 }

                 

                }

                else

                {

                delay50ms(); //50ms per segment

                continue;

                }

                        

        }

        zhen=0; //Time exceeded, shutdown

        delay100ms(); //Wait 100ms, prepare for reversal

        //delay500ms(); //Wait 500ms, prepare for reversal

        fan=1;

        delay1_6_f();

        fan=0;

}



void Uart_Init(void) //initialization

{

        //zhen=1;

        //fan=1;

    SCON=0x50; //UART mode 1: 8-bit UART; REN=1: Allow receiving 

    PCON=0x00; //SMOD=0: baud rate is not doubled 

    TMOD=0x20; //T1 mode 2, used for UART baud rate 

    TH1=0xFD; //UART baud rate setting: FDFD(9600)

    TL1=0xFD; //UART baud rate setting: FDFD(9600)

    TR1=1; //Allow T1 counting 

    EA=1; //

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//UART sending and receiving part 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void Uart_Send_Byte(unsigned char c)//uart sends a byte 

{

        SBUF = c;

        while(!TI); //1 after sending 

        TI = 0;

}


unsigned char Uart_Receive_Byte() //UART receives a byte 

{        

        unsigned char dat;

        while(!RI); //1 after receiving 

        RI = 0;

        dat = SBUF;

        return (dat);

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////

//AS608/FPM10A fingerprint module command //

////////////////////////////////////////////


void FPM10A_Cmd_Send_Pack_Head(void) //Send communication protocol packet header

{

        int i;        

        for(i=0;i<6;i++) 

   {

                Uart_Send_Byte(FPM10A_Pack_Head[i]);   

   }                

}


void FPM10A_Receive_Data(unsigned char ucLength) //Receive fingerprint module feedback data buffer

{

  unsigned char i;


  for (i=0;i     FPM10A_RECEICE_BUFFER[i] = Uart_Receive_Byte();


}


void FPM10A_Cmd_Get_Img(void) ////FINGERPRINT_Get fingerprint image command (detect whether there is a fingerprint)

{

    unsigned char i;

    FPM10A_Cmd_Send_Pack_Head(); //Send communication protocol packet header

    for(i=0;i<6;i++) 

        {

       Uart_Send_Byte(FPM10A_Get_Img[i]);

        }

}

//Convert the image into a feature code and store it in Buffer1

void FINGERPRINT_Cmd_Img_To_Buffer1(void)

{

        unsigned char i;

        FPM10A_Cmd_Send_Pack_Head(); //Send communication protocol packet header      

           for(i=0;i<7;i++) //Send command to convert image into feature code and store it in CHAR_buffer1

     {

             Uart_Send_Byte(FPM10A_Img_To_Buffer1[i]);                  

            }

}


//Search the first 100 fingerprints in the database (you can change the number in the DATA area up to 999) 

void FPM10A_Cmd_Search_Finger(void)

{

       unsigned char i;                       

                         FPM10A_Cmd_Send_Pack_Head(); //Send communication protocol packet header

       for(i=0;i<11;i++)

           {

                  Uart_Send_Byte(FPM10A_Search[i]); //Receive the data sent back by the fingerprint module

                      }

}


//Search for fingerprints, and authenticate if there are any

void FPM10A_Find_Fingerprint()

{

  FPM10A_Cmd_Get_Img(); //Send command to get fingerprint image

  FPM10A_Receive_Data(12); //Receive feedback data buffer

  if(FPM10A_RECEICE_BUFFER[9]==0&&pressed==1) //Based on the 9th bit of data fed back, determine whether there is a fingerprint on the module. If yes, continue to execute. If no, exit

  {

    FINGERPRINT_Cmd_Img_To_Buffer1(); //Convert the image into feature code and store it in Buffer1

        FPM10A_Receive_Data(12);                

        FPM10A_Cmd_Search_Finger(); //Search all users 100 pieces

        FPM10A_Receive_Data(16);

        if(FPM10A_RECEICE_BUFFER[9] == 0) //If the corresponding fingerprint is found  

        {

          kaisuo(); //Unlock

          //delay500ms(); //delay 0.5s

          delay1s();

      wakeup=0; //Module SOC power off 

        }

        else

        {

         wakeup=0; //Module SOC power off 

         //delay100ms(); //delay 100ms, jump out

        }

  }

          else

        {

        wakeup=0; //Module SOC power off

        }

}



//////////////////////////////////////////////


// Main program //


//////////////////////////////////////////////

void main()         

{

//delay1s(); //MCU powers on and waits for 1s to stabilize

Uart_Init(); //Initialize the serial port

led_work=0;

zhen=0;

fan=0;

wakeup=0;

pressed=0;

test=1;

check=1; //Detection position reed switch

led_work=1; //The working indicator light is on, reminding the system that the initialization has been completed (test is 0)

        while(1)

        {

                if(pressed==1) //Is the fingerprint module pressed? If pressed, it is 1; otherwise, it is 0

                {

                //Uart_Init();

                wakeup=1; //Module SOC power on

                delay500ms(); //delay 0.5s //wait for SOC initialization to complete

                Uart_Init(); //Reinitialize the serial port

                FPM10A_Find_Fingerprint(); //Search and compare fingerprints

                }

                else

                {

                if(test==0) //test unlock

                {

                kaisuo(); //Unlock

            delay500ms(); //delay 0.5s

                }

                else

                {

                delay100ms(); //The fingerprint module is not pressed and the delay is 100ms

                }                 

                }        

        }

}

Keywords:AS608 Reference address:Simple fingerprint lock source program based on AS608 and 51 single chip microcomputer

Previous article:HX711 electronic scale weighing module distribution information (MCU source code with median filter)
Next article:Design of automatic watering greenhouse control system based on single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 13:59

Microcontroller C51 programming specifications
1 Single-Chip Microcomputer C51 Programming Specifications - Preface This specification is written to improve the quality and maintainability of source programs, and ultimately improve the productivity of software products. 2 MCU C51 Programming Specifications - Scope This standard specifies the spe
[Microcontroller]
51 MCU CS1237 electronic scale source program with detailed comments
Engineering hardware platform: 1, 51Core-V1.0 (51 single-chip minimum system board)                 2, differential ADC module-CS1237                 3, weighing sensor module                 4, OLED display 0.96 inches, 4PIN Engineering program version: 51 single-chip kitchen (pharmacy) scale solution V1.0.0.0
[Microcontroller]
The main structure and function analysis of the timing counter in the 51 single chip microcomputer
1. Main structure 1) 16-bit adder counter, consisting of the upper 8-bit (THi) and lower 8-bit (TLi) SFRs. 2) When used as a counter, pins P3.4 (T0) and P3.5 (T1) are the external pulse input terminals of the two counters respectively. 3) Pins P3.2 (/INT0) and P3.3 (/INT1) can be used as gate signals for T0 and T1 whe
[Microcontroller]
The main structure and function analysis of the timing counter in the 51 single chip microcomputer
Blood Glucose Meter Based on C8051F Single Chip Microcomputer
Electrochemical Principles of Blood Glucose Measurement The electro-biochemical principle of blood glucose measurement is that when a certain voltage is applied to the blood after the enzyme reaction, the current generated will increase as the blood glucose concentration in the blood increases. By accurately me
[Microcontroller]
Blood Glucose Meter Based on C8051F Single Chip Microcomputer
How to set parity check for serial communication of 51 single chip microcomputer
Usually, the format of a frame of serial communication is 8-n-1, that is, 8 bits of data, no parity, and 1 stop bit. Sometimes, in order to improve accuracy, you need to add an "odd" or "even" check bit. For high-level languages, it is very simple to do this. Just change the format command "8-n-1" to "8-P-1" or "8-O-
[Microcontroller]
51 MCU crystal oscillator and reset common typical circuit
1. Typical circuit of internal oscillation. Theoretically, the higher the oscillation frequency, the faster the microcontroller runs, but at the same time, the higher the requirements for the memory speed and printed circuit board. Just like the barrel principle. At the same time, the performance of the microcontrol
[Microcontroller]
Introduction to the interface between high-precision ADVF32 and 51 series microcontrollers
  Since the current A/D converters with more than 12 bits are expensive, people are looking for new ways to replace them, and V/F converters are a good choice. Since V/F converters have the characteristics of high precision and high linearity, such as the ADVFC32 of Analog Devices (the domestic model is 5GVFC32), the
[Microcontroller]
Introduction to the interface between high-precision ADVF32 and 51 series microcontrollers
Timing Analysis of Power-on Reset and Reset Delay of 80C51 MCU
The power-on reset (POR) of the 80C51 microcontroller is essentially a power-on delay reset, which means that the microcontroller is locked in the reset state during the power-on delay period. Why is it necessary to add a certain delay time every time the microcontroller is powered on? The analysis is as follows.
[Industrial Control]
Timing Analysis of Power-on Reset and Reset Delay of 80C51 MCU
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号