;  By www.TechnoElectro.CO
;  Email: TechnoElectro.CO@Gmail.com
	ORG 	00H
D:	   MOV 	 R7,#0FFH
	   CALL	 START_LCD
	   CALL	 WELLCOM
FIRST: CALL  WAIT_OPEN
	   CALL  DELAY	
K1:    CALL  WAIT_PRESS
	   CALL  DELAY
	   MOV 	 A,P2
	   ANL 	 A,#00000111B
	   CJNE  A,#00000111B,FIND
	   SJMP  K1
FIND:  CALL  ROW_SEARCH
	   CJNE  R7,#0FFH,EXIT1
AGAIN: RRC 	 A
	   JNC 	 FOUND
	   INC 	 DPTR
	   JMP 	 AGAIN
FOUND: CLR 	 A
	   MOVC  A,@A+DPTR
	   MOV	 R5,A
	   CALL	 DELAY
	   CALL	 MOHASEBE
EXIT1: JMP 	 FIRST
;*******************************
WAIT_OPEN:
	   MOV 	 P2,#0FFH	;sotonha=1
HERE:  MOV 	P0,#00H		;satrha=0
	   RET
;*******************************
WAIT_PRESS:
	   MOV 	A,P2
	   ANL 	A,#07H
	   CJNE A,#07H,NEXT1
	   SJMP WAIT_PRESS
NEXT1:	RET
;*******************************
ROW_SEARCH :
	MOV 	P0,#11111110B
	MOV 	A,P2
	ANL 	A,#00000111B
	CJNE 	A,#00000111B,ROW0
	MOV 	P0,#11111101B
	MOV 	A,P2
	ANL 	A,#00000111B
	CJNE 	A,#00000111B,ROW1
	MOV 	P0,#11111011B
	MOV 	A,P2
	ANL 	A,#00000111B
	CJNE 	A,#00000111B,row2
	MOV 	P0,#11110111B
	MOV 	A,P2
	ANL 	A,#00000111B
	CJNE 	A,#000000111B,ROW3
	MOV 	R7,#00H
	JMP 	LAST
ROW0:   MOV 	DPTR,#KCODE0
	JMP 	LAST
ROW1:	MOV 	DPTR,#KCODE1
	JMP 	LAST
ROW2:	MOV 	DPTR,#KCODE2
	JMP 	LAST
ROW3:	MOV 	DPTR,#KCODE3
	JMP 	LAST
LAST: 	RET
;*******************************
DELAY:	MOV 	R2,#10
AGAIN2: MOV 	R3,#250 
HERE2: 	DJNZ 	R3,HERE2
	DJNZ 	R2,AGAIN2
	RET

;*******************************
	ORG 200H
KCODE0:DB 31H,32H,33H
KCODE1:DB 34H,35H,36H
KCODE2:DB 37H,38H,39H
KCODE3:DB 01H,30H,10H
;*******************************			
;############search for accont####################
MOHASEBE:
	    CLR	    C
	    MOV	    A,R5	;SHOMAREYE AWAL KE DAR R5 ZAKHIRE SHODEBOD DAR A MIRIZIM.
;	         SUBB	         A,#30H
	    MOV	    R1,A
	    CJNE	R1,#31H,BADI
	    ACALL	SHOMARE1
BADI:	CJNE	R1,#32H,BADI2
    	ACALL	SHOMARE2
BADI2:	CJNE	R1,#33H,BADI3
	    ACALL	SHOMARE3
BADI3:	CJNE	R1,#34H,SETAREH
	    ACALL	SHOMARE4
;BADI4:	CJNE	R1,#35H,BADI5
;	    ACALL	SHOMARE5
;BADI5:	CJNE	R1,#36H,BADI6
;	    ACALL	SHOMARE6
;BADI6:	CJNE	R1,#37H,BADI7
;	    ACALL	SHOMARE7
;BADI7:	CJNE	R1,#38H,BADI8
;	    ACALL	SHOMARE8
;BADI8:	CJNE	R1,#39H,SETAREH
;       ACALL	SHOMARE9
SETAREH:CJNE	R1,#01H,MORABA
    	lCALL	y
		SJMP AKHAR1
MORABA: CJNE	R1,#10H,SETAREH
        ACALL   D
AKHAR1:	RET
;#####end search for accont##
;#####Contact1#######
SHOMARE1:
	
	MOV DPTR,#400H
	MOV R1,#00H
START:	MOV R0,#80H
	MOV R2,#9AH
	CALL START_LCD
	MOV A,R0
NEXT2:	CALL COM_WR
	MOV A,R1
	CALL DATA_WR
	INC R0
	INC R1
	MOV A,R0
	CJNE R1,#24H,ROW_C
	CALL DELAY_2
	MOV R1,#00H
	SJMP START
ROW_C:	CJNE A,02,NEXT2
	MOV R3,00
	MOV R0,#0C0H
	MOV R2,#0CAH
	MOV A,R0
	CJNE R3,#0CAH,NEXT2
	CALL DELAY_2
	SJMP START
;#####LCD######

START_LCD:
	MOV A,#38H
	CALL COM_WR
	MOV A,#01H
	CALL COM_WR
	MOV A,#0CH
	CALL COM_WR
	RET

DATA_WR:
	MOVC A,@A+DPTR
	MOV P1,A
	MOV P3,#05H
	NOP
	NOP
	NOP
	MOV P3,#01H
	CALL DELAY_1
	RET

COM_WR:
	MOV P1,A
	MOV P3,#04H
	NOP
	NOP
	NOP
	MOV P3,#00H
	CALL DELAY_1
	RET

	;#############;
	;DELAY 1.67 ms;
	;#############;
DELAY_1:
	    MOV	R4,#03H
WAIT:	MOV	R5,#0FFH
	DJNZ	R5,$ ;ta waghti ke sefr shawad dar in khat mimanad
	DJNZ	R4,WAIT
	RET
;##########DELAY 1s########
	
DELAY_2:
	MOV	R4,#12
WAIT1:	MOV	R5,#255
WAIT2:	MOV	R6,#157
WAIT3:	DJNZ	R6,WAIT3
	DJNZ	R5,WAIT2
	DJNZ	R4,WAIT1
	RET

	;	LOOK UP TABLE	;
	
	ORG	400H
	DB	'www.TechnoElectro.CO'
	DB	'     09166191732   '
;*********Contact2***************	
SHOMARE2:
	MOV DPTR,#500H
	MOV R1,#00H
START33:MOV R0,#80H
	MOV R2,#9AH
	CALL START_LCD
	MOV A,R0
NEXT7:	CALL COM_WR
	MOV A,R1
	CALL DATA_WR
	INC R0
	INC R1
	MOV A,R0
	CJNE R1,#24H,ROW_C22
	CALL DELAY_2
	MOV R1,#00H
	SJMP START33
ROW_C22:CJNE A,02,NEXT7
	MOV R3,00
	MOV R0,#0C0H
	MOV R2,#0CAH
	MOV A,R0
	CJNE R3,#0CAH,NEXT7
	CALL DELAY_2
	SJMP START33
ORG	500H
	DB	'Designed  ';the name of contact
	DB	'BY  Saghi ';information about him
	DB	'               ';the numbers of contact
;######Contact3###
	SHOMARE3:
	MOV DPTR,#600H
	MOV R1,#00H
START44:MOV R0,#80H
	MOV R2,#8AH
	CALL START_LCD
	MOV A,R0
NEXT77:	CALL COM_WR
	MOV A,R1
	CALL DATA_WR
	INC R0
	INC R1
	MOV A,R0
	CJNE R1,#24H,ROW_C33
	CALL DELAY_2
	MOV R1,#00H
	SJMP START44
ROW_C33:CJNE A,02,NEXT77
	MOV R3,00
	MOV R0,#0C0H
	MOV R2,#0CAH
	MOV A,R0
	CJNE R3,#0CAH,NEXT77
	CALL DELAY_2
	SJMP START44
ORG	600H
	DB	'  Empty   '           ;the name of contact
	DB	'   Contact  '          ;information about him
	DB	'            '           ;the numbers of contact
;######contact 4###########
	SHOMARE4:
MOV DPTR,#700H
	MOV R1,#00H
STARTff:MOV R0,#80H
	MOV R2,#8AH
	CALL START_LCD
	MOV A,R0
NEXTff:	CALL COM_WR
	MOV A,R1
	CALL DATA_WR
	INC R0
	INC R1
	MOV A,R0
	CJNE R1,#24H,ROW_Cff
	CALL DELAY_2
	MOV R1,#00H
	SJMP STARTff
ROW_Cff:CJNE A,02,NEXTff
	MOV R3,00
	MOV R0,#0C0H
	MOV R2,#0CAH
	MOV A,R0
	CJNE R3,#0CAH,NEXTff
	CALL DELAY_2
	SJMP STARTff
ORG	700H
	DB	'  Empty   '           ;the name of contact
	DB	'   Contact  '          ;information about him
	DB	'            '           ;the numbers of contact
;*********************************
DELAY_3:
	    MOV	R4,#3
WAIT11:	MOV	R5,#255
WAIT12:	MOV	R6,#157
WAIT13:	DJNZ	R6,WAIT13
	DJNZ	R5,WAIT12
	DJNZ	R4,WAIT11
	RET
;**********************************
WELLCOM:	
	MOV DPTR,#800H
	MOV R1,#00H
STARTW:	MOV R0,#80H
	MOV R2,#8AH
	CALL START_LCD
	MOV A,R0
NEXTW:	CALL COM_WR
	MOV A,R1
	CALL DATA_WR
	INC R0
	INC R1
	MOV A,R0
	CJNE R1,#24H,ROW_CW
	CALL DELAY_4
	MOV R1,#00H
	SJMP STARTW
ROW_CW:	CJNE A,02,NEXTW
	MOV R3,00
	MOV R0,#0C0H
	MOV R2,#0CAH
	MOV A,R0
	CJNE R3,#0CAH,NEXTW
	CALL DELAY_4
	RET
ORG	800H
    DB  'Press     '
	DB	'*Nbr #NtBk    '
;####################################
DELAY_4:
	    MOV	R4,#12
WAITw1:	MOV	R5,#255
WAITw2:	MOV	R6,#157
WAITw3:	DJNZ	R6,WAITw3
	DJNZ	R5,WAITw2
	DJNZ	R4,WAITw1
	RET
;###########Pulse Setting##################
y:
up6:     MOV     A,#38H
         CALL    lcd99
         mov     A,#0Eh
         call    lcd99
         mov     a,#1H
         call    lcd99
;##################
UP2:     MOV     R3,#1
         mov     a,#0C0H
         call    lcd99
;##################
UP1:     NOP
         CALL    KEYPAD
         CALL    Commander
         Call    Pulser
CJNE     R3,#18,UP
         JMP UP2
;##################
UP:CJNE  R3,#0,UP1
         MOV     A,#0C0H
         CALL    lcd99
         JMP     UP1
;##################
lcd99:   CALL    DELLY
         MOV     P1,A
         CLR     P3.0
         CLR     P3.1
         SETB    P3.2
         CLR     P3.2
         RET
;##################
Commander:CALL    DELLY
         MOV     P1,A
         SETB    P3.0
         CLR     P3.1
         SETB    P3.2
         CLR     P3.2
         RET
;##################
DELLY:   MOV     R1,#150
W1:      MOV     R2,#250
W2:      DJNZ    R2,W2
         DJNZ    R1,W1
         RET
;##################
KEYPAD:  mov p2,#0fh
         mov p0,#0h
         jnb p2.0,a0
         jnb p2.1,a0
         jnb p2.2,a0
         jmp KEYPAD
;##################
a0:      mov p0,#11111110b
         jnb p2.0,ONE
         jnb p2.1,TWO
         jnb p2.2,THREE
         mov p0,#11111101B
         jb  p2.0,ku5
         jmp FOUR
;##################
KU5:     jb  p2.1,ku2
         jmp FIVE
;##################
KU2:     JB  P2.2,KU3
         JMP SIX
;##################
KU3:     mov p0,#11111011B
         jb  p2.0,ku1
         jmp SEVEN
;##################
KU1:     jb  p2.1,ku
         jmp EIGHT
;##################
ku:      jb  p2.2,M2
         JMP NINE
;##################
M2:      mov p0,#11110111B
         jnb p2.1,ZERO
         jnb p2.2,cear
         jmp KEYPAD
;##################
TWO:     MOV B,#'2'
         MOV A,#6H
         MOV R4,#2
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
cear:    jnb p2.2,cear
         jmp againi
;##################

ZERO:     MOV B,#'0' 
         MOV A,#6H
         MOV R4,#10
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
ONE:     MOV B,#'1' 
         MOV A,#6H
         MOV R4,#1
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
THREE:   MOV B,#'3' 
         MOV A,#6H
         MOV R4,#3
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
FOUR:    MOV B,#'4'
         MOV A,#6H
         MOV R4,#4
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
FIVE:    MOV B,#'5'
         MOV A,#6H
         MOV R4,#5
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
SIX:     MOV B,#'6'
         MOV A,#6H
         MOV R4,#6
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
SEVEN:   MOV B,#'7'
         MOV A,#6H
         MOV R4,#7
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
EIGHT:   MOV B,#'8'
         MOV A,#6H
         MOV R4,#8
         CALL lcd99
         MOV A,B
         INC R3
         jmp WQL
;##################
NINE:    MOV B,#'9'
         MOV A,#6H
         MOV R4,#9
         CALL lcd99
         MOV A,B
         INC R3
         JMP WQL
;##################
WQL:     JNB P2.0,WQL
         JNB P2.1,WQL
         JNB P2.2,WQL
         RET
;##################
againi:   MOV DPTR,#ROWz
;##################
YY:      CLR A
MOVC     A,@A+DPTR
         JZ EXIT
         INC DPTR
         CALL DELET
         JMP YY
EXIT:    RET
;##################
ROWz:    DB"              ",0
         jmp up6
DELET:   MOV B,A
         MOV A,#4H
         CALL lcd99
         MOV A,B
         CALL Commander
         JMP UP6
;##################
Pulser:   setb p3.7
         call delly
         clr p3.7
         call delly
djnz     r4,Pulser
         ret
END
;  By www.TechnoElectro.CO
;  Email: TechnoElectro.CO@Gmail.com