The essence of commonly used electronic password lock source program

Publisher:Meilin8888Latest update time:2017-11-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

       ;************************************************
       ;********* Electronic password lock *********
       ;********************************************
       ;********* 2005/12/24 *********
       ;************************************************
       ;Display buffer
       ;LED1 EQU 6FH
       BUFF EQU 6EH
       TIMERS1 EQU 6DH ;Enter the number of carriage returns
       TIMERS2 EQU 6CH ;The number of alarms
       TIMERS EQU 6BH ;The number of digits entered
       ;LED6 EQU 6AH
       ;Password buffer
       PS1 EQU 69H
       PS2 EQU 68H
       PS3 EQU 67H
       PS4 EQU 66H
       PS5 EQU 65H
       PS6 EQU 64H
       ;AT24C02 reads buffer
       AT1 EQU 63H
       AT2 EQU 62H
       AT3 EQU 61H
       AT4 EQU 60H
       AT5 EQU 5FH
       AT6 EQU 5EH
       ;Key flag bit
       F_1 BIT 20H
       F_2 BIT 21H
       F_3 BIT 22H
       F_4 BIT 23H
       BUF_FULL BIT 24H ;The flag bit that the password is six digits long, 1 means full
       CH_STATE BIT 25H ;The status flag bit of system change, 1 means busy
       FLAG1 BIT 26H ;Function key flag bit, 1 means function key.
       F_F1 BIT 27H
       F_F2 BIT 28H
       PSW_F BIT 29H ; Flag bit for whether the password is correct
       ; Port resource definition
       SPK BIT P2.1
       JDQ BIT P2.3
       SDA BIT P2.4 ; Define serial port data end
       SCL BIT P2.5
       ; LED light
       L1 BIT P1.0
       L2 BIT P1.1
       L3 BIT P1.2
       ;
       ORG 0000H
       AJMP MAIN
       ORG 000BH
       ;AJMP TIMER0
       ORG 001BH
       ;AJMP TIMER1
       ORG 0030H
  MAIN:MOV SP, #70H
       MOV TMOD, #11H
       MOV TH0, #3CH
       MOV TL0, #0B0H
       MOV TH1, #3CH
       MOV TL1, #0B0H
       CLR F_1 ; Clear flag bit
       CLR F_2
       CLR F_3
       CLR F_4
       CLR BUF_FULL
       CLR CH_STATE
       CLR FLAG1
       CLR F_F1
       CLR F_F2
       CLR PSW_F
       MOV BUFF,#00H ;Call
       LCALL INITPS ;Initialize environment
       LCALL INITAT
       LCALL XSA ;Call default display
       MOV TIMERS1,#00H
       NOP
       MOV PS1, #11H ;Initialize password 830620
       MOV PS2, #0AH
       MOV PS3, #02H
       MOV PS4, #13H
       MOV PS5, #0BH
       MOV PS6, #02H
  START:NOP ; Start the program
       LCALL CH_KEY ; Check the keyboard
       AJMP START ; Return

CH_KEY:LCALL KS ; Check if any key is pressed
       JNZ LK1
       AJMP CH_KEY
   LK1:
       LCALL T12MS
       ACALL KS
       JNZ LK2
       RET

   LK2:
       NOP
       LCALL SBIE ;Key recognition subroutine
       MOV BUFF, A ;Send buffer to identify whether it is a numeric key or a function key?
       LCALL CH_KF ;Judge key function.
       JB FLAG1 ,KEY_FUN ;If the flag is 1, it is a function key
;***********Digit key input and store in the buffer for comparison************
KEY_DIG:NOP ;Set a flag to distinguish whether the input is full
       ;SETB TR0
       INC TIMERS ;Input the number of digits
       MOV A, TIMERS
       CLR C
       SUBB A, #01H
       JNZ PS_2
       MOV PS1, BUFF ;Store the password in sequence
       AJMP NEXT
  PS_2:MOV A, TIMERS
       SUBB A, #02H
       CLR C
       JNZ PS_3
       MOV PS2, BUFF
       AJMP NEXT
  PS_3:MOV A, TIMERS
       CLR C
       SUBB A, #03H
       JNZ PS_4
       MOV PS3, BUFF
       AJMP NEXT
  PS_4:MOV A, TIMERS
       CLR C
       SUBB A, #04
       JNZ PS_5
       MOV PS4, BUFF
       AJMP NEXT
  PS_5:MOV A, TIMERS
       CLR C
       SUBB A, #05
       JNZ PS_6
       MOV PS5, BUFF
       AJMP NEXT
  PS_6:MOV A, TIMERS
       CLR C
       SUBB A, #06H
       JNZ CH_KEY
       MOV PS6, BUFF
  NEXT:LCALL XSC
       MOV R7, TIMERS ;Compare the number of inputs.
       CJNE R7, #06H ,FULL
  FULL:JC NEXT9
       SETB BUF_FULL
       MOV TIMERS,#06H
       CLR L3
       NOP
       CLR P2.1
       LCALL T100MSD
       SETB P2.1
       NOP
       AJMP CH_KEY
  NEXT9:CLR P2.1 ;When each digit of password is entered, it will beep once.
       CLR L3
       LCALL T100MSD ; Delay 100ms
       SETB L3
       SETB P2.1
       AJMP CH_KEY
;*****************Compare and jump function keys*************
KEY_FUN:
       CLR FLAG1
       CLR C
       MOV A, BUFF
       SUBB A, #03H ; Jump by key CL
       JNZ EN_C
       AJMP CL
  EN_C:CLR C
       MOV A, BUFF ; Jump by key EN
       SUBB A, #00H
       JNZ F1_C
       AJMP EN
  F1_C:CLR C
       MOV A, BUFF
       SUBB A, #1BH
       JNZ F2_C
       AJMP FU1
  F2_C:CLR C
       MOV A, BUFF
       SUBB A, #1AH
       JNZ F3_C
       AJMP FU2
  F3_C:CLR C
       MOV A, BUFF
       SUBB A, #19H
       JNZ F4_C
       AJMP FU3
  F4_C:CLR C
       MOV A, BUFF
       SUBB A, #18H
       JZ FU4
  EXIT8:NOP
       LJMP CH_KEY
;***************Open door subroutine********************************
    CL:NOP
       SETB L3
       MOV BUFF, #00H ;Eliminate password buffer
       MOV TIMERS,#00H
       LCALL INITPS ;Eliminate AT buffer, be sure to add
       LCALL XSC
       LCALL BP
       LCALL BP
       LCALL T100MSD
       LCALL BP
       CLR FLAG1
       AJMP CH_KEY

   FU4:NOP
       LCALL BP
       LCALL T100MSD
       LCALL BP
       LCALL T100MSD
       LCALL BP
       LCALL T100MSD
       LCALL BP
       LCALL T100MSD
       LCALL BP
       CLR   FLAG1
       AJMP  CH_KEY

   FU3:NOP
       LCALL BP
       LCALL T100MSD
       LCALL BP
       LCALL KILLXS ; Turn off display
       CLR FLAG1
       AJMP CH_KEY

   FU1:NOP
       LCALL XSC
       JB F_F1, NEXT_F1
       CLR L1
       LCALL BP
       SETB F_F1
       AJMP CH_KEY
NEXT_F1:SETB L1
       LCALL BP
       CLR F_F1
       ;LCALL CH_STATE ;Check the current status to prevent accidental pressing
       ;SETB TR1 ;Alarm limit is temporarily disabled
       ;INC F_F1
       CLR FLAG1
       AJMP CH_KEY

   FU2:NOP
       JB F_F2, NEXT_F2
       CLR L2
       LCALL BP
       SETB F_F2
       AJMP CH_KEY
NEXT_F2:SETB L2
       LCALL BP
       CLR F_F2
       CLR FLAG1
       AJMP CH_KEY
;***************Key function description****************************
    EN:NOP
       JB BUF_FULL, GOON
       AJMP EXIT
  GOON:CLR BUF_FULL
       JB F_F2, AT_WRON ;F2 key flag, if it is 1, call the password modification subroutine.
       LCALL AT_RADE
       LCALL C_PSW ;Compare password subroutine
       JB PSW_F,OPEN ;If the password is correct, call the unlock subroutine
       LCALL XSD
       INC TIMERS2
       MOV R7,TIMERS2 ;Wrong password, call in the password input times, prepare to lock the keyboard
       CJNE R7,#03H,D0
    D0:JC NEXT1 ;The number of errors is less than 3 times
       LCALL XSE ;Lock for 5 minutes
       LCALL WARN2S
       LCALL LOCK_1M
  NEXT1:LCALL WARN2S ;Warn for 2 minutes
       LCALL XSA
  EXIT:LCALL INITPS
       MOV BUFF, #00H
       CLR FLAG1
       MOV TIMERS, #00H
       AJMP CH_KEY ;Jump out
       
AT_WRON:LCALL AT_WR
       LCALL XSF
       LCALL BP
       LCALL T100MSD
       LCALL BP
       LCALL T500MSD
       LCALL KILLXS
       LCALL T500MSD
       LCALL XSF
       LCALL T500MSD
       LCALL KILLXS
       LCALL T500MSD
       LCALL XSF
       LCALL T500MSD
       NOP
       NOP
       LCALL XSA
       AJMP EXIT

    OPEN:MOV  A,     TIMERS1
        CJNE A,     #09H,CLT1
   CLT1:JC   GOON1
        MOV  TIMERS1,#00H
  GOON1:INC  TIMERS1                ;输入回车的次数
        MOV  TIMERS2,#00H
        SETB  L3
        CLR   PSW_F
        LCALL XSB
        CLR  JDQ             ;开门
        LCALL BP
        LCALL BP
        LCALL BP
        LCALL BP
        LCALL SEC
        LCALL SEC
        LCALL SEC
        LCALL SEC
        LCALL SEC
        LCALL SEC
        LCALL SEC
        LCALL SEC
        SETB  JDQ
        LCALL XSA
        NOP
        AJMP  EXIT


;**************Various subroutines********************************
;**** Note that when clearing the buffer, AT1...AT6 should not be executed during initialization to***
;****Prevent both buffers from being 0 and unlocking the same ***
;************************************************************

CLR_BUF:MOV R7, #06H
       MOV R0, #6FH
  LOOP1:MOV A, #00H
       MOV @R0, A
       DEC R0
       DJNZ R7,LOOP1
       RET
;*************Initialize display buffer and other buffers**************
INITPS:PUSH ACC
       PUSH PSW
       MOV R7, #06H
       MOV R1, #PS1
       MOV A, #00H
INIT_PS:MOV @R1, A
       DEC R1
       DJNZ R7, INIT_PS
       POP PSW
       POP ACC
       NOP
       RET

INITAT:PUSH ACC
       PUSH PSW
       MOV R7,#06H
       MOV R1,#AT1
       MOV A, #00H
INIT_AT:MOV @R1, A
       DEC R1
       DJNZ R7, INIT_AT
       MOV TIMERS,#00H ;The number of password inputs is cleared.
       POP PSW
       POP ACC
       RET

;**************** Key recognition subroutine ******************************
  SBIE:MOV R2, #0EFH ;Key recognition subroutine, data is sent to A for storage, page P146 of the textbook.
       MOV R4, #00H
   LK4:MOV A, R2
       MOV P0, A
       NOP
       MOV A, P0
       JB ACC.0,LONE
       MOV A, #00H
       AJMP LKP
  LONE:JB ACC.1,LTWO
       MOV A, #08H
       AJMP LKP
  LTWO:JB ACC.2,LTHR
       MOV A, #10H
       AJMP LKP
  LTHR:JB ACC.3,NEXTT ; Judge next Column
       MOV A, #18H
   LKP:ADD A, R4
       PUSH ACC
   LK3:ACALL KS
       JNZ LK3
       POP ACC
       RET
  NEXTT:INC R4
       MOV A, R2
       JNB ACC.7,KND
       RL A
       MOV R2, A
       AJMP LK4
   KND:AJMP CH_KEY

    KS:MOV   P0,    #0FH
       NOP
       MOV   A,     P0
       CPL   A
       ANL   A,     #0FH
       NOP
       RET

  CH_KF:CLR C
       MOV A, BUFF ;Judge whether it is a numeric key or a function key, 1 indicates a function key
       CJNE A, #17H, KY
    KY:JC SET_CH ;If it is a numeric key, the flag is set to 0
       SETB FLAG1 ;If it is a function key, the flag is set to 1
       AJMP CHKE_END
SET_CH:CLR C
       MOV A, BUFF
       SUBB A, #00H
       JNZ EN_CH
       SETB FLAG1
       AJMP CH_END
  EN_CH:MOV A, BUFF
       SUBB A, #03H
       JNZ DIG
       SETB FLAG1
       AJMP CH_END
   DIG:CLR FLAG1
CH_END:NOP
CHKE_END:RET

  T12MS:MOV     R7,   #18H
    TM1:MOV     R6,   #0FFH
   TM66:DJNZ    R6,   TM66
        DJNZ    R7,   TM1
        RET

;****************Check the password is correct*******************************
  C_PSW:PUSH PSW
        PUSH ACC
        MOV R2,#06H
        MOV R0,#PS1
        MOV R1,#AT1
    C_P:CLR C
        MOV A,@R0
        SUBB A,@R1
        JNZ RETURN
        DEC R0
        DEC R1
        DJNZ R2,C_P
        NOP
        SETB PSW_F
        AJMP EXIT7
  RETURN:CLR PSW_F
  EXIT7:NOP
        POP ACC
        POP PSW
        RET
;×××××××××××××××××Lock, whistle subroutine××××××××××××
LOCK_1M:MOV R4,#3CH ;Lock for 1 minuteM1_LOOP
:LCALL SEC
        DJNZ R4,M1_LOOP
        NOP
        RET

   WARN2S:PUSH PSW
         PUSH ACC
         MOV R5, #14H ;Call BP 20 times, alarm 2s
    WARN:LCALL BP
         DJNZ R5,WARN
         NOP
         POP ACC
         POP PSW
         NOP
         RET
     BP:CLR SPK ;Whistle subroutine
        LCALL T100MSD
        SETB SPK
        NOP
        RET

Reference address:The essence of commonly used electronic password lock source program

Previous article:C51 Interrupt Receive Query Send
Next article:How to choose 51 chip according to the purpose

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号