Interface description and Code Wiring methods:
1. the matrix key Pad having 16 keys is interfaced with microcontroller 8051 with a 8PIN data cable, the port P1 of MCU At89c51is used for this purpose.
2. The LED seven segment display common anode type blue color is connected to port P0 of microcontroller 8051.
3. The number pressed on the keypad is displayed on 7-segment display.
- the program scan button and display the number accordingly.
- respectively 16 keyboard display show the digital 0123456789ABCD
- what key is pressed on the keyboard matrix to determine , "line scanning method." is used to scan which key is pressed. Line scanning method, also known as progressive (or column) scan query method, is one of the most commonly used keys recognition.
|Keypad scanning program 8051 seven segment display|
The PINs P1.0 to Pin P1.3 are connected to columns while Port PIns P1.3 to Port PIn P1.7 are connected to rows of the keypads. The columns are multiplexed while rows are the input for scanning which keys is pressed while multiplexing of columns. Four rows and four columns wire line formed 16 intersection.
1 detects whether this key is pressed. Methods to detect the P1.4-P1.7 output all "0", reads the status of P1.0-P1.3, P1.0-P1.3 as if all "1", no key is closed, otherwise there button closure.
When a key is detected, the delay time to do testing to determine the next step.
if the key is pressed, which one should identify the key closure.
Read P1.0-P1.3 output in each set of rows, if the whole is "1", then "0" line is no bond closed, otherwise the key is closed. Whereby closing key row and column values, and can be calculated or lookup table to convert the row and column values close bond into key defined.
4, in order to ensure that each key only once closed a CPU for processing, jitter must be removed when the key is released.
|Assembly language program Keypad scanning program 8051 seven segment display|
mov dptr, # tab; the header into DPTR
lcall Key; calling keyboard scanner
movc a, @ a + dptr; lookup key into the ACC after
mov P0, a; would Acc value into the P0 port
CLR P2.1; open display
ljmp main; returned repeatedly to cycle
KEY: LCALL KS; detect key subroutine call
JNZ K1; key is pressed to continue
LCALL DELAY2; without key debounce delay by calling
AJMP KEY; returns continue to test the key
K1: LCALL DELAY2
LCALL DELAY2; delay key is pressed to shake
LCALL KS; then call detection key procedures
JNZ K2; recognized the pressing Next
AJMP KEY; without pressing the Return key to continue to detect
K2 : MOV R2, # 0EFH; would sweep into the R2 value of the temporary
MOV R4, # 00H; R4 first column values into a temporary
K3: MOV P1, R2; the value of R2 into the P1 port
L6: JB P1 .0, L1; P1.0 = 1 jump to L1
MOV A, # 00H; into the first row of the value of ACC
AJMP LK; jump to the key handler
L1: JB P1.1, L2; P1.1 Jump to L2 is equal to 1
MOV A, # 04H; the second row into the row values ACC
AJMP LK; jump to the key management program key processing
L2: JB P1.2, L3; P1.2 = 1 Jump to L3
MOV A, # 08H; the row values into the third row ACC
AJMP LK; jump to the key handler
L3: JB P1.3, NEXT; P1.3 = 1 Jump to NEXT at the
MOV A, # 0cH; fourth row of the row values into the ACC
LK: ADD A, R4; key row and column values of the added value into A
PUSH ACC; the A stack of values into a temporary
K4 : LCALL DELAY2; calls to delay jitter program
LCALL KS; call button detection program
JNZ K4; continue to return the keys did not release detection
POP ACC; the value of the stack into the ACC
INC. R4; the column value plus one
MOV A , R2; the value of R2 into A
JNB ACC.7, KEY; scanned to perform at the next scan KEY
RL A; scanning unfinished value in the A right one scan to the next column
MOV R2, A; The R2 value of ACC into temporary
AJMP K3; Jump to K3 continues
KS: MOV P1, # 0FH; P1 port will be four positions lower nibble value 0 1
MOV A, P1; Reading the P1 port
XRL A, # 0FH ; the A and A values in the value of different or
RET; subroutine return
DELAY2:; 40ms delay to shake subroutine
MOV R5, # 08H
L7: MOV R6, # 0FAH
L8: DJNZ R6, L8
DJNZ R5, L7
dB 28h, 34h, 28h, 34h, 0A9H, 60H, 20h, 7ah, 20h, 21h, 61h, 74h, 30h, 62h, 0A2H, 7eh