Digital code lock with already defined password:
Password is: 465
/************************************************************************************/
//            PROGRAM TO  DEMONSTRATE  INTERFACING OF HEX DISPALY WITH MCS51       
/************************************************************************************/


ORG 0000H


/************************************************************************************/
/*                                           I/O PIN INITIALISATIONS AND DECLARATIONS                                                                                                                   */
/************************************************************************************/

C1 EQU P2.0
C2 EQU P2.1
C3 EQU P2.2
C4 EQU P2.3
ROW1 EQU P2.4
ROW2 EQU P2.5
ROW3 EQU P2.6
ROW4 EQU P2.7
RS equ p3.0
RW equ p3.1
EN equ p3.2
LCD equ p1
MOV R1,#'4'
MOV R2,#'6'
MOV R3,#'5'


MOV P2,#00H
MOV P0,#00H
MOV B,#00H
MOV R3,#00H
AGAIN: MOV LCD,#38H
ACALL CMD
ACALL DELAY
MOV LCD,#01H
ACALL CMD
ACALL DELAY
MOV LCD,#0EH
ACALL CMD
ACALL DELAY
MOV LCD,#06H
ACALL CMD
ACALL DELAY
MOV LCD,#80H
ACALL CMD
ACALL DELAY


MOV DPTR,#200H
MOV LCD,#01H
ACALL CMD
ACALL DELAY
MOV LCD,#80H
ACALL CMD
ACALL DELAY
ABC1: CLR A
MOVC A,@A+DPTR
JZ GO1
MOV LCD,A
LCALL DISP
INC DPTR
MOV LCD,#06H
ACALL CMD
ACALL DELAY
SJMP ABC1
GO1: MOV LCD,#0C5H
ACALL CMD
ACALL DELAY
CLR A
ACALL KEYBOARD
MOV R7,A                                                          
CLR A
ACALL KEYBOARD
MOV R0,A
CLR A
ACALL KEYBOARD
MOV R4,A
ACALL DELAY
CLR A
MOV A,R1
CJNE A,07H,DID_NOT
CLR A
MOV A,R2
CJNE A,00H,DID_NOT
CLR A                                    
MOV A,R4
CJNE A,04H,DID_NOT
SETB P3.3
SETB P3.4
CLR P3.5
CLR P3.6
ACALL DELAY
SETB P3.5
SETB P3.6
ACALL DELAY
CLR P3.5
CLR P3.6
MOV DPTR,#250H
MOV LCD,#01H
ACALL CMD
ACALL DELAY
MOV LCD,#80H
ACALL CMD
ACALL DELAY
ABC2: CLR A
MOVC A,@A+DPTR
JZ GO2
MOV LCD,A
LCALL DISP
INC DPTR
MOV LCD,#06H
ACALL CMD
ACALL DELAY
SJMP ABC2

GO2: ACALL DELAY
     ACALL DELAY
                 ACALL DELAY
                 ACALL DELAY
                 ACALL DELAY
     ACALL DELAY
                 ACALL DELAY
                 ACALL DELAY
     ACALL DELAY
                    
                    
     lJMP AGAIN

DID_NOT: SETB P3.5
         SETB P3.6
         CLR P3.3
         CLR P3.4
                                 ACALL DELAY
                                 SETB P3.3
                                 SETB P3.4
                                 ACALL DELAY
                                 CLR P3.3
         CLR P3.4
         MOV DPTR,#300H
         MOV LCD,#01H
         ACALL CMD
         ACALL DELAY
                                 MOV LCD,#80H
         ACALL CMD
         ACALL DELAY
   ABC3: CLR A
                                 MOVC A,@A+DPTR
                                 JZ GO3
                                 MOV LCD,A
                                 LCALL DISP
                                 INC DPTR
                                 MOV LCD,#06H
                                 ACALL CMD
                                 ACALL DELAY
                                 SJMP ABC3
                GO3: ACALL DELAY
                     ACALL DELAY
                                 ACALL DELAY
                                 ACALL DELAY
                     ACALL DELAY
                                 ACALL DELAY
                     ACALL DELAY
                     ACALL DELAY
                                 ACALL DELAY
                     ACALL DELAY
                     ACALL DELAY
                                 ACALL DELAY
                    
                     LJMP AGAIN

/************************************************************************************/
/*                                           READING COLUMN VALUE                                                                                                                                                                                                          */
/************************************************************************************/


KEYBOARD: ACALL DELAY           
       MOV P2, #0FH
                   ACALL DELAY
K1:             MOV A,P2
                   CJNE A,#0FH,KK1
                   SJMP K1
KK1:   JB C1,N1
                   MOV B,#00h
                   ACALL DELAY
N1:            JB C2,N2
                   MOV B,#01h
                   ACALL DELAY
N2:            JB C3,N3
                   MOV B,#02h
                   ACALL DELAY
N3:            JB C4,N4
                   MOV B,#03h
                   ACALL DELAY

/************************************************************************************/
/*                                           READING ROW VALUE                                                                                                                                                                                                                   */
/************************************************************************************/
                              
N4:   MOV P2, #0F0H
K11:  MOV A,P2
                  CJNE A,#0F0H,KK11
                  SJMP K11
KK11: ACALL DELAY
                  JB ROW1,NR1
                  MOV R3,#00h
                  ACALL DELAY
NR1:  JB ROW2,NR2
                  MOV R3,#04h
                  ACALL DELAY
NR2:  JB ROW3,NR3
                  MOV R3,#08h
                  ACALL DELAY
NR3:  JB ROW4,NR4
                  MOV R3,#0Ch
                  ACALL DELAY
NR4:  MOV A,R3

/************************************************************************************/
/*                           SENDING KEYVALUE TO PORT 0 AND SERAIL PORT                                                                                                                                            */
/************************************************************************************/
                  MOV DPTR,#MSG
                  ADD A,B
                  MOVC A,@A+DPTR
                  MOV LCD,A
                  ACALL DISP
                  RET

/************************************************************************************/
/*                                           DELAY SUBROUTINE                                                                                                                                                                                                                       */
/************************************************************************************/


DELAY:  MOV R6,#5FH
a1:     MOV R5,#0FEH
a2:     DJNZ R5,a2
        DJNZ R6,a1
                    RET


CMD:     CLR RS
         CLR RW
                                 SETB EN
                                 NOP
                                 CLR EN
                                 RET

DISP:    SETB RS
         CLR RW
                                 SETB EN
                                 NOP
                                 CLR EN
                                 RET
/************************************************************************************/
/*                                           LOOKUP TABLE W.R.T 0-15 SWITCHES IN HEX KEYPAD                                                                                                     */
/************************************************************************************/

MSG: DB '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',0

ORG 200H
DB 'CONFIRM PASSWORD',0

ORG 250H
DB 'PASSWORD MATCHED',0

ORG 300H
DB 'WRONG PASSWORD',0

      END


Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Microcontroller Projects -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -