⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keypad.lst

📁 Library for the 8051 microcontroller. such as math routine, hexBCD, LCD, Keyboard, I2C, Remote, Ke
💻 LST
📖 第 1 页 / 共 2 页
字号:

ASEM-51 V1.3                                         Copyright (c) 2002 by W.W. Heinz                                         PAGE 1





       MCS-51 Family Macro Assembler   A S E M - 5 1   V 1.3
       =====================================================



	Source File:	E:\MiCrOConTroller\Coba_M-IDE\KEYPAD\KEYPAD.asm
	Object File:	E:\MiCrOConTroller\Coba_M-IDE\KEYPAD\KEYPAD.hex
	List File:	E:\MiCrOConTroller\Coba_M-IDE\KEYPAD\KEYPAD.lst



 Line  I  Addr  Code            Source

    1:				;---------------------------------------------------------------------------------------------------
				------------------
    2:				;Author: Ashwin
    3:				;Location: India
    4:				;Code: 4x4 matrix key pad
    5:				;Inputs: hex keypad via port1
    6:				;outputs: ASCII value of pressed button is sent through the serial port and also the hex equivalent
				is ouput thru p3.5 to p3.2
    7:				;---------------------------------------------------------------------------------------------------
				-----------------
    8:
    9:		B      0090	ROW0             EQU          P1.0
   10:		B      0091	                      ROW1             EQU          P1.1
   11:		B      0092	                      ROW2             EQU          P1.2
   12:		B      0093	                      ROW3             EQU          P1.3
   13:
   14:		B      0097	                      CLMN0            EQU          P1.7
   15:		B      0096	                      CLMN1            EQU          P1.6
   16:		B      0095	                      CLMN2            EQU          P1.5
   17:		B      0094	                      CLMN3            EQU          P1.4
   18:
   19:		N	 30						  DIGIT            DATA         30h    ;temporary storage of
				 pressed key
   20:		B      00B7						  ALERT            EQU          P3.7   ;goes low when any ke
				y's pressed
   21:
   22:
   23:
   24:		N      0000	org  0000h
   25:
   26:	  0000	02 00 B2	    ljmp ks_main
   27:
   28:		N      0030	org 0030h
   29:
   30:				;_________________________________________________________________
   31:				;----------SERIAL PORT INITIALISATION STARTS HERE-----------------
   32:				;_________________________________________________________________
   33:
   34:
   35:	  0030	75 89 20	s9k_main:           mov tmod,#20h         ;timer_0 in mode2 (8bit auto reload)
   36:	  0033	75 8D FD	                    mov th1,#0fdh           ;set baud to 9600
   37:	  0036	75 98 50	                    mov scon,#50h         ;serial mode1 (8bit data varialble baud)
   38:	  0039	D2 8E		                    setb tr1                    ;start timer_0

ASEM-51 V1.3                                         Copyright (c) 2002 by W.W. Heinz                                         PAGE 2



 Line  I  Addr  Code            Source

   39:	  003B	22		                    ret
   40:
   41:
   42:				;--------------SERIAL TRANSMIT SUBROUTINE-------------------------
   43:
   44:
   45:
   46:	  003C	F5 99		tx_main:            mov sbuf,a
   47:	  003E	30 99 FD	tx_loop:            jnb TI,tx_loop
   48:	  0041	C2 99		                    clr TI
   49:	  0043	22		                    ret
   50:
   51:
   52:				;--------------SERIAL RECIEVE SUBROUTINE--------------------------
   53:
   54:
   55:
   56:	  0044	E4		rx_main:            clr a
   57:	  0045	30 98 FD	rx_loop:            jnb ri,rx_loop
   58:	  0048	E5 99		                    mov a, sbuf
   59:	  004A	C2 98			                clr ri
   60:	  004C	22			                ret
   61:
   62:				;------------------------------20ms delay----------------------------------
   63:
   64:	  004D	C0 00		delay_20ms:         push 00
   65:	  004F	C0 01		                    push 01
   66:	  0051	78 24		                    mov r0,#36
   67:	  0053	79 FF		delay_20ms_loop1:   mov r1,#255
   68:	  0055	D9 FE		delay_20ms_loop2:   djnz r1,delay_20ms_loop2
   69:	  0057	D8 FA		                    djnz r0,delay_20ms_loop1
   70:	  0059	D0 01		                    pop 01
   71:	  005B	D0 00		                    pop 00
   72:	  005D	22		                    ret
   73:
   74:				;------------------------display subroutine--------------------------------
   75:
   76:	  005E	C0 E0		disp_message:       push acc
   77:
   78:	  0060	74 00		disp_message_loop1: mov a, #00h	; reset accumulator
   79:	  0062	93				            movc a,@a+dptr
   80:	  0063	B4 00 03						cjne a,#00h,disp_message_loop2
   81:
   82:	  0066	D0 E0							pop acc
   83:	  0068	22							ret
   84:
   85:	  0069	F5 99		disp_message_loop2: mov sbuf,a
   86:	  006B	11 3C		                    acall tx_main
   87:	  006D	A3				            inc dptr
   88:									;clr ti      ;ti was setting up automatically.
   89:	  006E	80 F0				            sjmp disp_message_loop1
   90:
   91:	  0070	20 20 20 4B	disp_pressed:DB"   Key pressed is:  ",00h
	  0074	65 79 20 70
	  0078	72 65 73 73
	  007C	65 64 20 69

ASEM-51 V1.3                                         Copyright (c) 2002 by W.W. Heinz                                         PAGE 3



 Line  I  Addr  Code            Source

	  0080	73 3A 20 20
	  0084	00
   92:
   93:				;----------------packed ascii to hex conversion--------------------
   94:
   95:	  0085	C0 E0		ascii2hex:       push acc
   96:
   97:	  0087	E5 30						 mov a,DIGIT
   98:	  0089	94 30						 subb a,#30h
   99:	  008B	F5 F0						 mov b,a
  100:	  008D	54 10						 anl a,#10h
  101:	  008F	B4 00 07					 cjne a,#00h,ascii2hex_loop2
  102:	  0092	E5 F0						 mov a,b
  103:
  104:	  0094	F5 30		ascii2hex_loop1: mov DIGIT,a
  105:	  0096	D0 E0		                 pop acc
  106:	  0098	22						 ret
  107:
  108:	  0099	E5 30		ascii2hex_loop2: mov a,DIGIT
  109:	  009B	94 37		                 subb a,#37h
  110:	  009D	80 F5						 sjmp ascii2hex_loop1
  111:
  112:				;------------------send pressed button via p3----------------------
  113:
  114:	  009F	C0 E0		send4x4_parallel: push acc
  115:	  00A1	E5 30		                  mov a,Digit
  116:
  117:	  00A3	13						  rrc a
  118:	  00A4	92 B5						  mov p3.5,c	   ;LSB
  119:	  00A6	13						  rrc a
  120:	  00A7	92 B4						  mov p3.4,c
  121:	  00A9	13						  rrc a
  122:	  00AA	92 B3						  mov p3.3,c
  123:	  00AC	13						  rrc a
  124:	  00AD	92 B2						  mov p3.2,c	   ;MSB
  125:
  126:	  00AF	D0 E0						  pop acc
  127:	  00B1	22						  ret
  128:				;_________________________________________________________________
  129:				;-------------------------main code------------------------------
  130:				;_________________________________________________________________
  131:
  132:
  133:	  00B2	75 90 FF	ks_main:    mov p1,#0ffh					;make input ports
  134:				            ;mov p3,#00h	;make output ports; never make this mistake => 3.0 n 3.1 are serial
				pins
  135:	  00B5	D2 B7					setb ALERT
  136:	  00B7	11 30		            acall s9k_main
  137:	  00B9	75 90 F0	ks_main1:	mov p1,#0f0h                    ;all columns high n rows low
  138:	  00BC	E5 90		            mov a,p1
  139:	  00BE	54 F0		            anl a,#11110000b                ;consider only columns
  140:	  00C0	B4 F0 F6	            cjne a,#11110000b,ks_main1      ;initially check for all keys released
  141:				;-------------------------------------------------------------------
  142:	  00C3	11 4D		ks_loop1:   acall delay_20ms
  143:	  00C5	E5 90		            mov a,p1
  144:	  00C7	54 F0		            anl a,#11110000b                            ;scan columns

ASEM-51 V1.3                                         Copyright (c) 2002 by W.W. Heinz                                         PAGE 4



 Line  I  Addr  Code            Source

  145:	  00C9	B4 F0 02	            cjne a,#11110000b,debounce         ;if key pressed, check debounce
  146:	  00CC	80 F5		            sjmp ks_loop1                       ;if not, keep checking for key pressed
  147:				;-------------------------------------------------------------------
  148:	  00CE	11 4D		debounce:   acall delay_20ms
  149:	  00D0	E5 90		            mov a,p1
  150:	  00D2	54 F0		            anl a,#11110000b
  151:	  00D4	B4 F0 02	            cjne a,#11110000b,check_row
  152:	  00D7	80 EA		            sjmp ks_loop1
  153:				;--------------------------------------------------------------------
  154:	  00D9	90 00 70	check_row:  mov dptr,#disp_pressed
  155:	  00DC	11 5E		            acall disp_message
  156:
  157:	  00DE	C2 90		            clr ROW0
  158:	  00E0	D2 91					setb ROW1
  159:	  00E2	D2 92					setb ROW2
  160:	  00E4	D2 93					setb ROW3
  161:
  162:	  00E6	E5 90					mov a,p1
  163:	  00E8	54 FE		            anl a,#11111110b 			 ;test row zero
  164:	  00EA	B4 FE 2F	            cjne a,#11111110b,row_0
  165:				;--------------------------------------------------------------------
  166:	  00ED	D2 90					setb ROW0
  167:	  00EF	C2 91					clr ROW1
  168:	  00F1	D2 92					setb ROW2
  169:	  00F3	D2 93					setb ROW3

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -