51 Assembly Language Programming - Enter Password

Publisher:朱颜素韵Latest update time:2018-05-09 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;On some touch-screen phones, there is a slide-to-unlock operation.

;On laptops, passwords are usually entered using the keyboard.

;Some people set the password to: ASDFGHJKL;'Enter. When turning on the computer, just swipe your finger on the keyboard.


; For single-chip microcomputers, you can also set passwords in this form. By pressing certain keys in sequence, you can successfully enter the next step.


;The circuit in the figure below is to press the keys in sequence to enter the power-on password:


51 Assembly Language Programming - Enter Password - Non-Famous Blogger - Electronic Information Corner


;P1.0 to P1.5 are password keys, P1.7 is the confirmation key,


; P2.1 to P2.6 correspond to 5 password keys, normally lit, --- the original text says so, should be 6

;After pressing the corresponding password, the corresponding LED goes out, and lights up again when you release it.

;The blue LED on P2.7 corresponds to the confirmation key.


; The password sequence is P1.0 to P1.5,

;The LED on P1.6 will light up only if the password value and sequence are correct, otherwise the red LED on P2.0 will light up.


;The original program in the title is not available.


; Following the idea of ​​the original program, the program written by Erlundao is as follows:

;-----------------------------------------

    ORG 0000H

    JMP START

START:

    MOV R0, #7; Use R0 as a counter to check the password sequence

    CLR P1.6 ; Turn off the correct indicator light

    MOV P2, #01111110B; P2.1 to P2.6 correspond to 6 password keys, which are normally lit.

LOOP:

    MOV A, P1 ; read

    MOV B, A ;temporary storage

    ORL A, #01000000B ; Shield indicator light

    CPL A

    JZ LOOP; No key pressed, loop detection

    CALL DL20MS ; Delay

    MOV A, P1 ; read again

    CJNE A, B, LOOP; debounce

;-----------------------------------------

; It has been confirmed that a key has been pressed:

    MOV C, ACC.7 ;P1.7 key

    CPL C

    RL A

    MOV ACC.7, C ; send to P2.7

    CLR ACC.0 ; Turn off the error indicator

    MOV P2, A; drives the indicator lights of each button

;-----------------------------------------

; Wait for release below

LOP2:

    MOV A, P1 ; read

    ORL A, #01000000B ; Shield indicator light

    CPL A

    JNZ LOP2 ; loop detection, waiting for release

;-----------------------------------------

;The key has been released,

    MOV P2, #01111110B; P2.1 to P2.6 correspond to 6 password keys, which are normally lit.

;-----------------------------------------

; The following handles the key just pressed

    JNB B.0, KEY0

    JNB B.1, KEY1

    JNB B.2, KEY2

    JNB B.3, KEY3

    JNB B.4, KEY4

    JNB B.5, KEY5

    JNB B.7, KEY7

    JMP LOOP

;-----------------------------------------

KEY0:

    CJNE R0, #7, LOOP

    DEC R0

    JMP LOOP

KEY1:

    CJNE R0, #6, LOOP

    DEC R0

    JMP LOOP

KEY2:

    CJNE R0, #5, LOOP

    DEC R0

    JMP LOOP

KEY3:

    CJNE R0, #4, LOOP

    DEC R0

    JMP LOOP

KEY4:

    CJNE R0, #3, LOOP

    DEC R0

    JMP LOOP

KEY5:

    CJNE R0, #2, LOOP

    DEC R0

    JMP LOOP

KEY7:

    CJNE R0, #1, ERROR

    MOV P2, #0 ; Turn off the button indicator light

    SETB P1.6 ; Correct indication

    SJMP $ ; stop

ERROR:

    MOV P2, #0 ; Turn off the button indicator light

    SETB P2.0 ; Error indication

    SJMP $ ; stop

;-----------------------------------------

DL20MS:

    MOV R6, #40

    DJNZ R7, $

    DJNZ R6, $ - 2

    RET

;-----------------------------------------

END


Reference address:51 Assembly Language Programming - Enter Password

Previous article:51 MCU Assembly Programming: Recording Keystrokes
Next article:51 MCU Programming: Dual Counter

Latest Microcontroller Articles
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号