; *********************** ; KEYPAD SCANNING ROUTINE ; *********************** ; ; CONNECTIONS TO HEX KEYPAD: ; ; | | | | ; | | | | ; P1.7 -----0----1----2----3------ ; | | | | ; P1.6 -----4----5----6----7------ ; | | | | ; P1.5 -----8----9----A----B------ ; | | | | ; P1.4 -----C----D----E----F------ ; | | | | ; | | | | ; P1.3 P1.2 P1.1 P1.0 ; ;----------------------------------------------------------------------------------------; ;DISPLAY IS A SEVEN SEGMENT ATTACHED TO P0 ; ;----------------------------------------------------------------------------------------; ;This code is written by Mubashar Yasin(Islamabad,Pakistan).It is freely distributable ; ;however please distribute it with my name and if you add this code to your website or ; ;some other publication then mention about me along with this code.I have tested this ; ;code to work properly even then there is no guarantee or warranty and i cannot be held ; ;responsible for any damage or loss due to this code.If you have any querries about this ; ;code please contact me at: ; ; ; ; kool_projects@yahoo.com ; ; mubasharpk09@hotmail.com ; ; ; ;or visit my website: ; ; ; ; http://www.geocities.com/kool_projects ; ;----------------------------------------------------------------------------------------; ORG 0000H LJMP MAIN ;;;;;;;;;;;;;;;;; KEY_PRESSED: ;;;;;;;;;;;;;;;;; REPEAT: ;SCANNING THE FIRST ROW MOV P1,#07FH ;CLR P1.7 JB P1.3,NEXT1 JNB P1.3,$ ;WAIT FOR KEY RELEASE MOV A,#0H LJMP EXIT1 NEXT1: JB P1.2,NEXT2 JNB P1.2,$ MOV A,#01H LJMP EXIT1 NEXT2: JB P1.1,NEXT3 JNB P1.1,$ MOV A,#02H LJMP EXIT1 NEXT3: JB P1.0,NEXT4 JNB P1.0,$ MOV A,#03H LJMP EXIT1 ;;;;;;;;;;;; NEXT4: ;SCANNING THE SECOND ROW MOV P1,#0BFH ;CLR P1.6 JB P1.3,NEXT5 JNB P1.3,$ MOV A,#04H LJMP EXIT1 NEXT5: JB P1.2,NEXT6 JNB P1.2,$ MOV A,#05H LJMP EXIT1 NEXT6: JB P1.1,NEXT7 JNB P1.1,$ MOV A,#06H LJMP EXIT1 NEXT7: JB P1.0,NEXT8 JNB P1.0,$ MOV A,#07H LJMP EXIT1 ;;;;;;;;;;;; NEXT8: ;SCANNING THE THIRD ROW MOV P1,#0DFH ;CLR P1.5 JB P1.3,NEXT9 JNB P1.3,$ MOV A,#08H LJMP EXIT1 NEXT9: JB P1.2,NEXT10 JNB P1.2,$ MOV A,#09H LJMP EXIT1 NEXT10: JB P1.1,NEXT11 JNB P1.1,$ MOV A,#0AH LJMP EXIT1 NEXT11: JB P1.0,NEXT12 JNB P1.0,$ MOV A,#0BH LJMP EXIT1 ;;;;;;;;;;;; NEXT12: ;SCANNING THE FOURTH ROW MOV P1,#0EFH ;CLR P1.4 JB P1.3,NEXT13 JNB P1.3,$ MOV A,#0CH LJMP EXIT1 NEXT13: JB P1.2,NEXT14 JNB P1.2,$ MOV A,#0DH LJMP EXIT1 NEXT14: JB P1.1,NEXT15 JNB P1.1,$ MOV A,#0EH LJMP EXIT1 NEXT15: JB P1.0,NEXT16 JNB P1.0,$ MOV A,#0FH LJMP EXIT1 ;;;;;;;;;;;; NEXT16: LJMP REPEAT ; DEFAULT ;;;;;;;;;;;; EXIT1: RET ;;;;;;;;;;;;;;;;; LOOK_UP: ;;;;;;;;;;;;;;;;; INC A MOVC A,@A+PC RET TABLE: DB 0xC0,0xFC,0x92,0x98,0xAC,0x89,0x81,0xDC,0x80,0x88,0x84,0xE1,0xC3,0xB0,0x83,0x87 ;COMMON ANODE DISPLAY ;;;;;;;;;;;;;;;;; MAIN: ;;;;;;;;;;;;;;;;; AGAIN: MOV P1,#0x0F RPT: MOV A,P1 CJNE A,#0x0F,GET_KEY LJMP RPT GET_KEY:LCALL KEY_PRESSED LCALL LOOK_UP MOV P0,A LJMP AGAIN END