

mov R1,#90h
PSIFIO2:
DELAY10: MOV R6,#0C3h ; delay for the keys to be pressed
DELAY11: MOV R7,#0FFh
DELAY21: NOP
NOP
DJNZ R7,DELAY21
DJNZ R6,DELAY11



mov A,#0h
call SCAN2 ; scan2 is the routine that scans the keypad
MOV A,R5
CJNE A,#0FFh,ELEGXOSPSIFIOU2 ; check if any key has been pressed and jump to ELEGXOSPSIFIOU2
JMP PSIFIO2 ; ;if no key has been pressed jump to psifio2 and scan again.



ELEGXOSPSIFIOU2:
MOV 96h,R5 ; Put the code of the key that has benn pressed, at memory location 96h

MOV A,34h ; Put in A 04h (has been declared before). A counter to check if it's the 4th digit of the password
CJNE A,#04h,GRAPSE2 ; Check if it's the 4th key that has been pressed. Go to Grapse 2
TELOS2: JMP ENTER2 ; OR ENTER2


GRAPSE2:      INC CURSPOS ;move cursor one position
              CALL POSIT_CURSOR   ; on the lcd
              MOV A,#2Ah		
              CALL LCDCHAR ; Show  * character on the lcd
	      INC 34h ; increase the pressed key counter
	      INC R1 ; show the next memory location, in which the code of the next pressed key will be saved 
	      
	      MOV @R1,96h ; put the code of the pressed key in the memory location that is in R1
	      JMP PSIFIO2 ; Go back to scan again

ENTER2:

		CALL SCAN2 ; call the scan keypad routine
		mov A, R5       ; put the code of the pressed key to A
	        CJNE A,#03h,ENTER2 ; wait until * key is pressed
		
ELEGXOSCODE1:    

		MOV A,91h ; put in A the code of the first pressed key
		CJNE A,40h,WRONGPASS ; if it isn't 0, go to wrongpass routine
		MOV A,92h ; if it is 0 continue and compare the next pressed key with 0
		CJNE A,41h,WRONGPASS ; if it isn't 0, go to wrongpass routine
		MOV A,93h ;if it is 0 continue and compare the next pressed key with 0
		CJNE A,42h,WRONGPASS ;if it isn't 0, go to wrongpass routine
		MOV A,94h ;if it is 0 continue and compare the next pressed key with 0
		CJNE A,43H,WRONGPASS  ;if it isn't 0, go to wrongpass routine
		CALL LCDCLS	;CLEAR SCREEN
                MOV CURSPOS,#4 ;put cursor in the first row of the lcd
                CALL POSIT_CURSOR   
		MOV DPTR,#STRING4	; show ALARM ON message
		CALL LCDSTR
JMP HALT

WRONGPASS: 
		CALL LCDCLS	;clear screen
		MOV CURSPOS,#4 ;put cursor in the first row of the lcd
		CALL POSIT_CURSOR   ; 
		MOV DPTR,#STRING5	;show wrong pass message
		CALL LCDSTR	



HALT: JMP HALT


STRING1:
DB ' ALARM OFF ' ,0

STRING2:
DB ' GIVE PASS ' ,0

STRING3:
DB ' GIVE OLD PASS ' ,0

STRING4:
DB ' ALARM ON ' ,0

STRING5:
DB ' WRONG PASS ' ,0
END
 