projectus.freehost7.com:UG and PG level projects,mini projects and many more here ...



AT89c51 Program Code for password based lock :

 

ORG 0000H

START1:MOV R6,#00H

MOV SP, #07H

MOV B, #0FH

SETB P0.7

CLR P0.6

START2:MOV R4, #00H

LCALL LCD

LCALL DELAY1

LCALL KEYPAD1

LCALL COMPARE

CJNE R3,#00H,START2

LJMP START1

END

DPOS:

DB ' ','E','N','T','E','R',' ','P',

'A','S','S','W','O','R','D',' ',' ',

' ',' ',' ',' ','S','O','R','R','Y',

' ',' ',' ',' ',' ',' ','P','A','S',

'S','W','O','R','D',' ','M','A','T',

'C','H','E','D',' ',' ','N','E','W',

' ','P','A','S','S','W','O','R','D',

' ',' ',' ','E','N','T','E','R','-',

'1',' ','E','X','I','T','-','2',' ',

' ','O','P','E','N','-','1',' ','C',

'H','A','N','G','E','-','2',' ',' ',

' ','W','R','O','N','G',' ','E','N',

'T','R','Y',' ',' ',' ',' ',' ',' ',

'W','E','L','C','O','M','E',' ',' ',

' ',' ','P','A','S','S','W','O','R',

'D',' ','C','H','A','N','G','E','D'

KCODE1: DB '1','2','3'

KCODE2: DB '4','5','6'

KCODE3: DB '7','8','9'

KCODE4: DB '*','0','#'

PASS: DB '1','2','3','4'

LCD:

MOV A,#38H

LCALL COMNWRT

LCALL DELAY2

MOV A,#0EH

LCALL COMNWRT

LCALL DELAY2

MOV A,#01H

LCALL COMNWRT

LCALL DELAY2

MOV A,#06H

LCALL COMNWRT

LCALL DELAY2

MOV A,#80H

LCALL COMNWRT

LCALL DELAY2

LCALL DATAGIVE

RET

DATAGIVE:

MOV DPTR,#DPOS

MOV A,R4

MUL AB

MOV DPL,A

MOV R5,#00H

X1:CLR A

MOVC A,@A+DPTR

LCALL DATAWRT

LCALL DELAY2

INC DPTR

INC R5

CJNE R5,#0FH,X1

MOV B,#16

RET

COMNWRT:

LCALL READY

MOV P1,A

CLR P2.0

CLR P2.1

SETB P2.2

LCALL DELAY2

CLR P2.2

RET

DATAWRT:

LCALL READY

MOV P1,A

SETB P2.0

CLR P2.1

SETB P2.2

LCALL DELAY2

CLR P2.2

RET

READY:

SETB P1.7

CLR P2.0

SETB P2.1

BACK:CLR P2.2

LCALL DELAY

SETB P2.2

JB P1.7,BACK

RET

LCD2:

MOV A,#38H

LCALL COMNWRT

LCALL DELAY2

MOV A,#0EH

LCALL COMNWRT

LCALL DELAY2

MOV A,#06H

LCALL COMNWRT

LCALL DELAY2

MOV A,#0C5H

LCALL COMNWRT

LCALL DELAY2

MOV A,#'*'

LCALL DATAWRT Page- 13

LCALL DELAY2

RET

KEYPAD1:

MOV R7,#00H

KEYPAD2:

MOV R5,#00H

MOV R4, #00H

MOV P3, #0FFH

K2:

MOV P2,#01H

MOV A,P3

ANL A,#0E0H

CJNE A,#0E0H,K2

K1:

LCALL DELAY2

MOV A,P3

ANL A,#0E0H

CJNE A,#0E0H,OVER

SJMP K1

OVER:LCALL DELAY2

MOV A,P3

ANL A,#0E0H

CJNE A,#0E0H,ROWCHECK

SJMP K1

ROWCHECK:

MOV P2,#00111000B

MOV A,P3

ANL A,#0E0H

CJNE A,#0E0H,ROW1

MOV P2,#01011000B

MOV A,P3

ANL A,#0E0H

CJNE A,#0E0H,ROW2

MOV P2,#01101000B

MOV A,P3

ANL A,#0E0H

CJNE A,#0E0H,ROW3

MOV P2,#01110000B

MOV A,P3

ANL A,#0E0H

CJNE A,#0E0H,ROW4

LJMP K1

ROW1:

MOV DPTR,#KCODE1

SJMP FIND

ROW2:

MOV DPTR,#KCODE2

SJMP FIND

ROW3:

MOV DPTR,#KCODE3

SJMP FIND

ROW4:

MOV DPTR,#KCODE4

SJMP FIND

FIND:

RLC A

JNC MATCH

INC DPTR

SJMP FIND

MATCH:

CLR A

MOVC A,@A+DPTR

LCALL REG

LCALL LCD2

INC R4

CJNE R7,#00H,NEW

CJNE R4,#04H,K3

NEW:

RET

K3:

LJMP K2

REG:

CJNE R5,#0H,B1

MOV R0,A

RET

B1:

CJNE R5,#01H,B2

MOV R1,A

RET

B2:

CJNE R5,#02H,B3

MOV R2,A

RET

B3:

CJNE R5,#03H,B4

MOV R3,A

B4:

RET

COMPARE:

CLR A

Q1:MOV DPTR,#0h

MOV R4,A

MOVC A,@A+DPTR

MOV DPTR,#PASS

MOV R7,A

MOV A,R4

MOVC A,@A+DPTR

CJNE A,07H,S1

MOV A,R4

INC A

CJNE R4,#03H,Q1

LJMP S2

S1:

LCALL NOTEQUAL

RET

S2:

LCALL EQUAL

RET

NOTEQUAL:

INC R6

CJNE R6,#03H,A1

LCALL DELAY3

MOV R3,#00H

RET

A1:

MOV R4,#01H

LCALL LCD

LCALL DELAY4

MOV R3,#0FFH

RET

EQUAL:

MOV R4,#05H

LCALL LCD

MOV R7,#01H

LCALL KEYPAD2

CJNE R0,#01H,LOC1

CLR P0.7

SETB P0.6

MOV R4,#07H

LCALL LCD

LCALL DELAY4

MOV R3,#00H

RET

LOC1:

CJNE R0,#02H,LOC2

MOV R4,#03H

LCALL LCD

LCALL KEYPAD1

MOV A,R0

MOV R6,A

MOV R4,#04H

LCALL LCD

MOV R7,#01H

LCALL KEYPAD2

CJNE R0,#01H,M1

LCALL CHANGE

MOV R3,#00H

RET

M1:

CJNE R0, #02H ,LOC2

MOV R3 ,#00H

RET

LOC2:

MOV R4, #06H

LCALL LCD

LCALL DELAY4

MOV R3 ,#00H

RET

CHANGE:

MOV DPTR,#PASS

MOV A,DPL

MOV R0,A

CLR A

MOV A,R6

MOV @R0,A

INC R0

MOV A,R1

MOV @R0,A

INC R0

MOV A,R2

MOV @R0,A

INC R0

MOV A,R3

MOV @R0,A

MOV R4,#08H

LCALL LCD

LCALL DELAY4

RET

DELAY:

PUSH 07H

MOV R7, #250

LOOP_1_MILI:

NOP

NOP

DJNZ R7,LOOP_1_MILI

POP 07H

RET

DELAY2:

PUSH 06H

MOV R6,#10

LOOP_10_MILI:LCALL DELAY

DJNZ R6,LOOP_10_MILI

POP 06H

RET

DELAY1:

PUSH 05H

MOV R5,#100

LOOP_1_SEC:LCALL DELAY2

DJNZ R6,LOOP_1_SEC

POP 05H

RET

DELAY4:

PUSH 04H

MOV R5, #05

LOOP_5_SEC:LCALL DELAY1

DJNZ R6,LOOP_5_SEC

POP 04H

RET

DELAY3:

PUSH 03H

MOV R3,#12

LOOP_1_MIN:LCALL DELAY4

DJNZ R6,LOOP_1_MIN

POP 03H

RET