DIY Electronic Combination Lock

Publisher:泥匠手Latest update time:2018-01-02 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Experimental task:
  According to the set password, use two buttons to input the password. When the password is entered correctly, the lock will open. If the password is entered incorrectly three times, the button will be locked for 3 seconds and an alarm will sound. The button lock function will not be opened until no button is pressed for 3 times. Otherwise, if there is still a button pressed within 3 seconds, the button will be locked again for 3 seconds and an alarm will sound.
2. Circuit diagram


Electronic combination lock design
                 Figure 4.32.1
3. Hardware connection on the system board
(1). Connect P0.0/AD0 in the "MCU system" area to the SPK IN terminal in the "Audio amplifier module" area with a wire;
(2). Connect the SPK OUT terminal in the "Audio amplifier module" area to the speaker;
(3). Connect P2.0/A8-P2.7/A15 in the "MCU system" area to any ABCDEFGH terminal in the "Four-way static digital display" area with an 8-core cable;
(4). Connect P1.0 in the "MCU system" area to the L1 terminal in the "Eight-way LED module" area with a wire;
(5). Connect P3.6/WR and P3.7/RD in the "MCU system" area to the SP1 and SP2 terminals in the "Stand-alone keyboard" area with a wire;
4. Program design content
(1). Password setting: In this program, the password is fixed in the program memory ROM. Assume that the preset password is "12345", a total of 5 digits.
(2) Password input problem:
  Since two keys are used to complete the password input, one of the keys is a function key and the other is a numeric key. During the input process, first enter the length of the password, then enter the number of digits of the password according to the length of the password, until all passwords of all lengths have been entered; or enter the confirmation function key to complete the password input process. Enter the password judgment and comparison processing state and give the corresponding processing process.
(3) Key prohibition function: During initialization, it is allowed to enter the password by key. When a key is pressed and starts to enter the key recognition state, the key prohibition function is activated, but the activation state occurs when the password is entered incorrectly 3 times.
5. C language source program
#include
unsigned char code ps[]={1,2,3,4,5};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
                               0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
unsigned char pslen=9;
unsigned char templen ;
unsigned char digit; unsigned
char funcount;
unsigned char digitcount; unsigned char
psbuf[9];
bit cmpflag;
bit hibitflag
; bit errorflag; bit
rightflag; unsigned int 
second3; unsigned
int aa ;
unsigned int bb ; oka; unsigned char okb; void main(void) {   unsigned char i,j;   P2=dispcode[digitcount];   TMOD=0x01;   TH0=(65536-500)/256;   TL0=(65536-500)%6; ==   0   )   //           function key             {               for(i=10;i>0;i--)               for(j=248;j>0;j--);         if       (P3_6==0)               {     if                   (hibitflag==0)   {                 funcount                       ++;                       if(funcount==pslen+2)                     {                           funcount=0;                           cmpflag=1;                          }                        P1=dispcode[funcount];                     }                     else                         {                          second3=0                       ;                       }                   while(P3_6==0);                 }             }           if(P3_7==0) //digit key













































            {
              for(i=10;i>0;i--)
              for(j=248;j>0;j--);
              if(P3_7==0)
                {
                  if(hibitflag==0)
                    {
                      digitcount++;                     
                      if( digitcount==10)
                        {
                          digitcount=0;
                        }
                      P2=dispcode[digitcount];
                      if(funcount==1)
                        {
                          pslen=digitcount;
                          templen=pslen;
                        }
                        else if(funcount>1)
                          {
                            psbuf[funcount-2]= digitcount;
                          }
                    }
                    else
                      {
                        second3=0;
                      }
                  while(P3_7==0);
                }
            }
        }
        else
          {
            cmpflag=0;
            for(i=0;i
              {
                if(ps[i]!=psbuf[i])
                  {
                    hibitflag=1;
                    i=pslen;
                    errorflag=1;
                    rightflag=0;
                    cmpflag=0;
                    second3=0;
                    goto a;
                  }
              }
            cc=0;
            errorflag=0;
            rightflag=1;
            hibitflag=0;
a: cmpflag=0;
          }


    }
}
void t0(void) interrupt 1 using 0
{
  TH0=(65536-500)/256;
  TL0=(65536-500)%6;
  if((errorflag==1) && (rightflag==0))
    {
      bb++ ;
      if(bb==800)
        {
          bb=0;
          alarmflag=~alarmflag;
        }
      if(alarmflag==1)
        {
          P0_0=~P0_0;
        }
      aa++;
      if(aa==800)
        {
          aa=0;
          P0_1=~ P0_1;
        }
      second3++;
      if(second3==6400)
        {
          second3=0;
          hibitflag=0;
          errorflag=0;
          rightflag=0;
          cmpflag=0;
          P0_1=1;
          alarmflag=0;
          bb=0;
          aa=0;
        }
    }
  if((errorflag==0) && (rightflag==1))
    {
      P0_1=0;
      cc++;
      if(cc<1000)
        {
          okflag=1;
        }
        else if(cc<2000)
          {
            okflag=0;
          }
          else
            {
              errorflag=0;
              rightflag=0;
              hibitflag=0;
              cmpflag=0;
              P0_1=1;
              cc=0;
              oka=0;
              okb=0;
              okflag=0;
              P0_0=1;
            }
      if(okflag==1)
        {
          oka++ ;
          if(oka==2)
            {
              oka=0;
              P0_0=~P0_0;
            }
        }
        else
          {
            okb++;
            if(okb==3)
              {
                okb=0;
                P0_0=~P0_0;
              }
          }
    }
}


Reference address:DIY Electronic Combination Lock

Previous article:Design a four-digit thermometer
Next article:DIY 6-digit frequency meter

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号