3x3 Matrix Keyboard using AT89C2051 microcontroller
Project Name: 3x3 Matrix Keyboard
Objective of Project:
Showing 0 to 8 on a 7 segment display by using
matrix theory connected to P3.0 to P3.5
Circuit Diagram:
List of components:
SL
|
Name
and Description
|
Quantity
|
1
|
MCU 89C2051
|
1
|
2
|
7 segment display ( Common Anode )
|
1
|
3
|
Resistance 1K Ohm
|
10
|
4
|
Capacitors 30pf
(10 uf 50Volt(1), 100uf 50Volt(1))
|
2
|
5
|
Crystal Q11.059A1
|
1
|
6
|
Voltage regulator 7805
|
1
|
7
|
Bread board
|
1
|
8
|
Connecting wires
|
|
9
|
Battery 9 Volt
|
1
|
10
|
Micro Push Type Switch
|
9
|
Flow Chart:
Program:
ORG 00h
MOV
P1, #0FFh
Starter:
MOV
P3, #00111000b
MOV
A, P3
ANL
A, #00111000b
CJNE
A, #00111000b, Starter
KeyCheck:
CALL
Delay
MOV A, P3
ANL A, #00111000b
CJNE A, #00111000b, Debonc
SJMP
KeyCheck
Debonc:
CALL
Delay
MOV A, P3
ANL A, #00111000b
CJNE A, #00111000b, FindRow
SJMP
KeyCheck
FindRow:
MOV
P3, #11111110b
MOV
A, P3
ANL
A, #00111000b
CJNE
A, #00111000b, Row_0
MOV
P3, #11111101b
MOV
A, P3
ANL
A, #00111000b
CJNE
A, #00111000b, Row_1
MOV
P3, #11111011b
MOV
A, P3
ANL
A, #00111000b
CJNE
A, #00111000b, Row_2
LJMP
KeyCheck
Row_0:
MOV
DPTR, #Row_0_Data
SJMP
Find_Col
Row_1:
MOV
DPTR, #Row_1_Data
SJMP
Find_Col
Row_2:
MOV
DPTR, #Row_2_Data
SJMP
Find_Col
Find_Col:
MOV
R2, #03
CLR
C
Get_col:
RRC
A
DJNZ
R2, Get_col
Find_Main:
RRC
A
JNC
Matched
INC
DPTR
SJMP
Find_Main
Matched:
CLR
A
MOVC
A, @A+DPTR
MOV
P1, A
LJMP
Starter
Delay:
MOV R5, #50h
Del_1:
MOV R6, #10h
Del_2: DJNZ R6, Del_2
DJNZ
R5, Del_1
RET
Row_0_Data:
db 0C0h, 0F9h, 0A4h
Row_1_Data:
db 0B0h, 99h, 92h
Row_2_Data:
db 82h, 0F8h, 80h
END
Brief Description of Program:
Rows
are connected to Port P3.0, P3.1, and P3.2 respectively. And Columns are
connected to P3.3, P3.4, and P3.5 respectively.
In the
‘start’ we put some value in accumulator register through port p3. Then we make
an AND operation and run a loop ranges from 00111000b to the new value of
accumulator register. After that, inside ‘check’, we call a delay and here we
start to get the value of row0, row1 and row2 respectively. In the look up
table data are kept within three rows.
Matrix Keyboard Connection to ports
- • Rows are connected to Port P3.0, P3.1, and P3.2 respectively.
- • Columns are connected to P3.3, P3.4, and P3.5 respectively.
- • If all the rows are grounded and a key is pressed, one of the columns will have 0 since the key pressed provides the path to ground.
- • If no key has been pressed, reading the input port will yield 1s for all columns since they are all connected to high (Vcc).
Detect a key press
- • To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output latch,
- • Then it reads the columns
Ø If the data read from columns is D2 – D0 =111, no
key has been pressed and the process continues till key press is detected
Ø If one of the column bits has a zero, this means
that a key press has occurred
For example, if D2 – D0
= 101, this means that a key in the D1 column has been pressed.
Detect row of key press
- • To detect which row key press belongs to, it grounds one row at a time, reading the columns each time.
Ø If it finds that all columns are high, this means
that the key press cannot belong to that row
Ø Therefore, it grounds the next row and continues
until it finds the row the key press belongs to
- • Upon finding the row that the key press belongs to, it sets up the starting address for the look-up table holding the scan codes (or ASCII) for that row
Identify the key press
- • To identify the key press, it rotates the column bits, one bit at a time, into the carry flag and checks to see if it is low
•
Upon finding the
zero, it pulls out the ASCII code for that key from the look-up table otherwise,
it increments the pointer to point to the next element of the look-up table .
Achievements (Result):
It is showing 0 t 8 on a 7 segment display by using matrix
theory connected to P3.0 to P3.5.
See the project at https://youtu.be/xmYHmVd1MFY
Comments
Post a Comment