3. • Keyboard interfacing is the process of connecting a keyboard to a
computer or a microcontroller, allowing the user to input data or
commands using the keys on the keyboard.
• Keyboard interfacing also requires a keyboard controller, which is a
device that informs the computer or the microcontroller when a key is
pressed or released.
• When data from the keyboard arrives, the controller raises an interrupt to
allow the CPU to handle the input. The keyboard controller can be either a
separate chip or integrated into the keyboard itself
Keyboard Interfacing
3
4. • There are different methods of keyboard interfacing, depending on
the type of keyboard and the device.
• For example, some keyboards use a serial interface, such as PS/2 or
USB, to communicate with the computer. Other keyboards use a
parallel interface, such as a matrix of rows and columns, to connect
with a microcontroller. In this case, the microcontroller needs to scan
the keyboard continuously to detect and identify the key pressed
4
5. 5
Examples:-
• Keyboard interfacing with AVR microcontroller using a 4x4 matrix keypad.
• Keyboard interfacing with 8051 microcontroller using a 4x4 matrix keypad.
• Keyboard interfacing with x86 PC using PS/2 or USB interface.
• Keyboard interfacing with LCD display using latches and buffers.
6. 6
Keyboard interfacing with 8051
microcontroller using a 4x4 matrix keypad :-
4X4 Matrix Keypad
• Matrix keypad consists of set of Push buttons,
which are interconnected. Like in our case we are
using 4X4 matrix keypad, in which there are 4
push buttons in each of four rows.
• In first row, one terminal of all the 4 push buttons
are connected together and another terminal of 4
push buttons are representing each of 4 columns,
same goes for each row. So we are getting 8
terminals to connect with a microcontroller.
7. 7
Interfacing keypad with 8051 microcontroller
• To interface a 4x4 matrix keypad with
8051 microcontroller, you need to connect
the row lines to an output port and the
column lines to an input port of the
microcontroller. You also need to write a
program that performs the following
steps:
8. Steps:
8
1. Set the output port to low and the input port to high.
2. Scan the input port for any low bit, indicating that a key in that column is
pressed.
3. Identify the column number by checking which bit is low.
4. Set the output port to high and the input port to low.
5. Scan the output port for any low bit, indicating that a key in that row is shorted
with the column.
6. Identify the row number by checking which bit is low.
7. Use the row and column numbers to determine which key is pressed and display
it on an LCD or other device.