输入按键并显示:4×4矩阵键盘分别定义为:0、1、2、3、4、5、。。。、E、F,16个按键。当键入一个按键,在一位数码管上显示键值。(汇编语言)

TEMP DATA 32H
ORG 0000H
AJMP START
START:
      MOV SP,60H
      MOV P0,#00H
MAIN:
       LCALL KEYBOARD
	   LJMP MAIN
KEYBOARD: 

ROW1:
      MOV P1,#0EFH
      MOV TEMP,P1
      ANL TEMP,#0F0H
	  MOV A,TEMP
	  CJNE A,0F0H,L100
	  LJMP ROW2
L100:
	      LCALL DELAY10MS
		  MOV TEMP,P1
		  ANL TEMP,#0F0H
	      MOV A,TEMP
	      CJNE A,#0F0H,COLUMN1_1
	      LJMP ROW2
COLUMN1_1:	
         MOV TEMP,P1
		 MOV A,TEMP
		 CJNE A,#0E7H,COLUMN1_2
MUM0:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#68
LOOP1:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN1_2:	
		 CJNE A,#0EBH,COLUMN1_3
MUM1:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#69
LOOP2:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN1_3:	
		 CJNE A,#0EDH,COLUMN1_4
MUM2:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#70
LOOP3:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN1_4:	
		 CJNE A,#0EEH,ROW2
MUM3:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#71
LOOP4:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET	 

ROW2:
      MOV P1,#0DFH
      MOV TEMP,P1
      ANL TEMP,#0F0H
	  MOV A,TEMP
	  CJNE A,0F0H,L200
	  LJMP ROW3
L200:
	  LCALL DELAY10MS
	  MOV TEMP,P1
	  ANL TEMP,#0F0H
	  MOV A,TEMP
	  CJNE A,#0F0H,COLUMN2_1
	  LJMP ROW3
COLUMN2_1:	
         MOV TEMP,P1
		 MOV A,TEMP
		 CJNE A,#0D7H,COLUMN2_2
MUM4:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#72
LOOP5:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN2_2:	
		 CJNE A,#0DBH,COLUMN2_3
MUM5:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#73
LOOP6:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN2_3:	
		 CJNE A,#0DDH,COLUMN2_4
MUM6:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#74
LOOP7:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN2_4:	
		 CJNE A,#0DEH,ROW3
MUM7:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#75
LOOP8:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET

ROW3:
      MOV P1,#0BFH
      MOV TEMP,P1
      ANL TEMP,#0F0H
	  MOV A,TEMP
	  CJNE A,0F0H,L300
	  LJMP ROW4
L300:
	  LCALL DELAY10MS
	  MOV TEMP,P1
	  ANL TEMP,#0F0H
	  MOV A,TEMP
	  CJNE A,#0F0H,COLUMN3_1
	  LJMP ROW4
COLUMN3_1:	
         MOV TEMP,P1
		 MOV A,TEMP
		 CJNE A,#0B7H,COLUMN3_2
MUM8:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#76
LOOP9:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN3_2:	
		 CJNE A,#0BBH,COLUMN3_3
MUM9:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#77
LOOP10:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN3_3:	
		 CJNE A,#0BDH,COLUMN3_4
CH_A:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#78
LOOP11:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN3_4:	
		 CJNE A,#0BEH,ROW4
CH_B:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#79
LOOP12:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET

ROW4:
      MOV P1,#07FH
      MOV TEMP,P1
      ANL TEMP,#0F0H
	  MOV A,TEMP
	  CJNE A,0F0H,L400
	  LJMP KEYBOARD
L400:
	  LCALL DELAY10MS
	  MOV TEMP,P1
	  ANL TEMP,#0F0H
	  MOV A,TEMP
	  CJNE A,#0F0H,COLUMN4_1
	  LJMP KEYBOARD
COLUMN4_1:	
         MOV TEMP,P1
		 MOV A,TEMP
		 CJNE A,#077H,COLUMN4_2
CH_C:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#80
LOOP13:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN4_2:	
		 CJNE A,#07BH,COLUMN4_3
CH_D:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#81
LOOP14:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN4_3:	
		 CJNE A,#07DH,COLUMN4_4
CH_E:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#82
LOOP15:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
COLUMN4_4:	
		 CJNE A,#07EH,COLSCANEND
CH_F:
     MOV DPTR,#NUM_TABLE
     MOV R0,#68
   	 MOV A,#83
LOOP16:
     SUBB A,R0
	 MOVC A,@A+DPTR
	 MOV P0,A
	 RET
	 
COLSCANEND:
     RET
DELAY10MS:
	 PUSH 30H
	 PUSH 30H
	 MOV 30H,#173
	 MOV 31H,#27
NEXT:
	 DJNZ 31H,NEXT
	 DJNZ 30H,NEXT
	 POP 31H
	 POP 30H
	 RET
NUM_TABLE:
		  DB 3FH,06H,5BH,4FH,66H
		  DB 6DH,7DH,07H,7FH,6FH,77H
		  DB 7CH,39H,5EH,79H
		  DB 71H
END

按键显示0-F硬件调试结果:

输入按键并显示:4×4矩阵键盘分别定义为:0、1、2、3、4、5、。。。、E、F,16个按键。当键入一个按键,在一位数码管上显示键值。(汇编语言)_第1张图片

输入按键并显示:4×4矩阵键盘分别定义为:0、1、2、3、4、5、。。。、E、F,16个按键。当键入一个按键,在一位数码管上显示键值。(汇编语言)_第2张图片 

 

你可能感兴趣的:(汇编)