Introduction to Keyboard INTERFACING (1)
Introduction to Keyboard INTERFACING (1)
INTERFACING:
8086 VS. 8051
Presented By : GROUP 5
AGENDA
01 Introduction To 2. Keyboard 03Keyboard 04Comparison of 8086
keyboard Interfacing Interfacing with 8086: Interfacing with 8051: and 8051 Keyboard
What is keyboard BIOS and DOS Interfacing:
Polling vs. interrupts.
interfacing? interrupts for keyboard Differences in
Matrix keyboard
input (INT 21h). architecture and
Why is it important? scanning.
interrupt handling.
Overview of keyboard Reading single Debouncing
Complexity and
characters and strings. techniques.
hardware and scan 8051 code examples
flexibility.
Handling keyboard
codes. for keyboard input.
buffer.
INTRODUCTION TO KEYBOARD
INTERFACING 1
Keyboard Interfacing: Keyboard interfacing refers to the process of connecting a keyboard to a microcontroller or
microprocessor and enabling the system to read and interpret the keystrokes entered by a user. This allows for user
input, a critical component in countless applications.
IMPORTANCE:
Keyboard interfacing is fundamental to countless applications, including:
Computers: The primary means of text input.
Embedded Systems: User control and configuration in industrial automation, consumer electronics, and medical
devices.
Point-of-Sale (POS) Systems: Data entry for transactions.
Gaming Consoles: Game commands and character input.
KEY COMPONENTS:
Keyboard: The input device that generates signals corresponding to pressed keys.
Microcontroller/Microprocessor: The central processing unit that reads and interprets these signals.
Display/Output Device (Optional): Provides visual feedback to the user, showing the entered data or system
responses.
KEYBOARD INTERFACING WITH 8086
2
The 8086 microprocessor interacts with a keyboard through BIOS and DOS interrupts. These
interrupts allow the program to handle keyboard inputs, such as reading single characters or entire
strings, and managing the keyboard buffer efficiently.
How:
mov ah, 00h: Prepares BIOS interrupt 16h, function 00h, which waits for a key
press.
int 16h: Calls the BIOS interrupt to handle the operation. Once a key is pressed:
AL: Receives the ASCII value of the pressed key.
AH: Receives the scan code of the key.
How:
mov dx, offset keyPressedMsg: Loads the address of the key-pressed
message into DX.
mov ah, 09h: Sets up DOS interrupt 21h, function 09h, to print the
message.
int 21h: Executes the interrupt to display the message.
Program 1: Detecting a Key Press on 8086 – Code
5
and explanation.
6. Exit the Program
Practise Problem
1.Create Program to check the password is valid or not.
Solution:
solution
5
Problem 5 : Multi-key detection in 8086 code and explanation
Explanation :
Waits for the first key press, retrieves it, and stores it in BL.
Checks if a second key is pressed; if yes, retrieves it and stores it in BH.
Displays a message (Keys pressed:).
Prints the first key, then the second key if available.
Terminates the program.
ORG 100H OUTPUT:
START: MOV AH, 09H
MOV AH, 1 LEA DX, MSG
INT 16H INT 21H
JZ START MOV AH, BL
CALL PRINT_CHAR
MOV AH, 0 MOV AH, BH
INT 16H CALL PRINT_CHAR
MOV BL, AL INT 20H
MOV AH, 1
INT 16H PRINT_CHAR:
JZ OUTPUT MOV DL, AH
MOV AH, 02H
MOV AH, 0 INT 21H
INT 16H RET
MOV BH, AL
MSG DB 'Keys pressed: $'
`
6
Key De-bouncing
implementaion in 8086
Key debouncing is a technique used in electronics and programming to handle the "bouncing" effect that
occurs when a mechanical switch, like a keyboard key, is pressed or released. When a key is pressed, the
contacts inside the switch can make and break contact multiple times in a very short period due to vibrations
or imperfections, creating multiple signals instead of a single clean press.There are multiple way to implement
key de-bouncing, one of them being doing it on a software level with a microprocessor.
; Start of Program
START:
; 1. Wait for a key press
IN AL, KEYBOARD_PORT ; Read the keyboard port
TEST AL, 00000001b ; Check if the key is pressed (adjust based on hardware logic)
JZ START ; If not pressed, keep waiting
In summary: The 8051 excels in resource-constrained embedded applications where its built-in peripherals and low
power consumption are valuable. The 8086, while more powerful, is more complex and typically consumes more
power, making it less suitable for such applications. The choice depends heavily on the application's requirements
and constraints.
KEYBOARD INTERFACING WITH 8051 5
the 8051 microcontroller, keyboard interfacing refers to the process of connecting a keyboard
(usually a matrix keyboard) to the 8051 microcontroller and reading the keys pressed by the
user. The 8051, like other microcontrollers, can use polling or interrupts to handle keyboard
input. Additionally, when interfacing with mechanical keys, debouncing techniques are used to
avoid erroneous key presses.
3. Debouncing Techniques
Mechanical switches, such as those in a keyboard, tend to produce multiple transitions when a key is pressed or released. This
phenomenon, known as key bounce, can lead to incorrect key detections. Debouncing is a technique used to ensure that only one valid
key press is registered.
Debouncing Methods:
Software Debouncing:
Wait for a short delay after detecting a key press or release, then check the key state again to ensure it's stable.
Hardware Debouncing:
Use components like capacitors or dedicated ICs (e.g., Schmitt triggers) to filter out the noise caused by bouncing.
Simple Software Debouncing:
After detecting a key press, wait for a brief period (e.g., 10-20 milliseconds) before checking again to confirm the key press.
KEYBOARD INTERFACING WITH 8051 5
Summary
1. Polling vs Interrupts:
Polling is simple but inefficient as it continuously checks the keyboard state.
Interrupts are more efficient, allowing the microcontroller to perform other tasks
while waiting for key presses.
2. Matrix Keyboard Scanning:
Scanning is done by sequentially setting rows to low and checking columns for a
key press.
3. Debouncing:
Software debouncing uses delays to filter out noise from key presses.
Hardware debouncing involves using capacitors or specific ICs.
COMPARISON OF 8086 AND 8051 5
KEYBOARD INTERFACING
Both the 8086 microprocessor and the 8051 microcontroller are popular in embedded
systems and computing applications, but their architectures and handling of keyboard
interfacing differ significantly. Here's a comparison of how each handles keyboard
interfacing, focusing on architecture, interrupt handling, complexity, and flexibility.
1. Architecture Differences
8086 Architecture:
General-Purpose Microprocessor: The 8086 is a 16-bit general-purpose microprocessor.
It requires external components, such as a keyboard interface and I/O ports, for
peripheral communication. The 8086 is not a microcontroller and lacks built-in I/O and
peripherals, meaning keyboard interfacing requires additional circuitry and interfacing
hardware (e.g., external I/O controllers, port expanders).
COMPARISON OF 8086 AND 8051 5
KEYBOARD INTERFACING
Memory and Addressing: The 8086 uses a segmented memory model with a 20-bit
address bus, allowing it to address up to 1 MB of memory. This makes it more suitable
for general computing tasks but introduces complexity in interfacing with peripherals.
I/O Management: The 8086 primarily relies on programmable I/O (PIO) devices or
custom external circuits for handling keyboard input. It uses interrupts (like INT 21h
for DOS and INT 16h for BIOS) but requires external interfacing hardware for real-time
keyboard scanning.
8051 Architecture:
Microcontroller: The 8051 is an 8-bit microcontroller that comes with built-in
peripherals such as timers, serial communication, and I/O ports. This makes it more
suited for embedded systems where simple input/output operations, such as
keyboard interfacing, are handled directly by the microcontroller.
COMPARISON OF 8086 AND 8051 5
KEYBOARD INTERFACING
Memory and Addressing: The 8051 has a 4 KB ROM and 128 bytes of RAM, with built-in I/O ports for
peripheral interfacing. These I/O ports make it easier to connect external devices like keyboards directly.
I/O Management: The 8051 microcontroller allows direct access to the I/O ports and uses internal
registers for peripheral management. It is more streamlined for handling keyboard input with fewer
external components, especially when using a matrix keyboard.
COMPARISON OF 8086 AND 8051 5
KEYBOARD INTERFACING
2. Interrupt Handling
8086 Interrupt Handling:
Software Interrupts: The 8086 supports a wide range of interrupts, including BIOS
(INT 10h, INT 16h) and DOS interrupts (INT 21h). These can be used for keyboard
input via INT 21h (AH=01h), but the handling is more manual and requires a
customized setup for real-time interrupt handling.
Interrupt Vector Table: The 8086 has a more complex interrupt vector table to
manage different interrupt sources. Each interrupt has a unique vector address,
and external hardware can be used to trigger interrupts for keyboard events.
Interrupt Service Routines (ISR): Custom ISRs must be written for each type of
interrupt. For example, a key press could generate an interrupt, and an ISR would
handle the scanning of the keyboard matrix and key detection.
COMPARISON OF 8086 AND 8051 5
KEYBOARD INTERFACING
8051 Interrupt Handling:
Built-in Interrupts: The 8051 has built-in interrupts, which makes it easier to handle
keyboard input directly. The 8051's external interrupts (INT0, INT1) or internal
interrupts like Timer Interrupts can be used to detect a key press.
Interrupts for Keyboard: The 8051 is more flexible when it comes to handling external
interrupts, such as those triggered by key presses from a matrix keyboard. The 8051
also has an interrupt priority scheme that can be used to manage different interrupt
sources effectively.
Interrupt Vector Table: The 8051 has a fixed interrupt vector table, with predefined
addresses for each interrupt type (external, timer, serial, etc.), making it simpler to set
up an interrupt service routine.
COMPARISON OF 8086 AND 8051 5
KEYBOARD INTERFACING
8051 Interrupt Handling:
Built-in Interrupts: The 8051 has built-in interrupts, which makes it easier to handle
keyboard input directly. The 8051's external interrupts (INT0, INT1) or internal
interrupts like Timer Interrupts can be used to detect a key press.
Interrupts for Keyboard: The 8051 is more flexible when it comes to handling external
interrupts, such as those triggered by key presses from a matrix keyboard. The 8051
also has an interrupt priority scheme that can be used to manage different interrupt
sources effectively.
Interrupt Vector Table: The 8051 has a fixed interrupt vector table, with predefined
addresses for each interrupt type (external, timer, serial, etc.), making it simpler to set
up an interrupt service routine.
COMPARISON OF 8086 AND 8051 5
KEYBOARD INTERFACING
8051 Interrupt Handling:
Built-in Interrupts: The 8051 has built-in interrupts, which makes it easier to handle
keyboard input directly. The 8051's external interrupts (INT0, INT1) or internal
interrupts like Timer Interrupts can be used to detect a key press.
Interrupts for Keyboard: The 8051 is more flexible when it comes to handling external
interrupts, such as those triggered by key presses from a matrix keyboard. The 8051
also has an interrupt priority scheme that can be used to manage different interrupt
sources effectively.
Interrupt Vector Table: The 8051 has a fixed interrupt vector table, with predefined
addresses for each interrupt type (external, timer, serial, etc.), making it simpler to set
up an interrupt service routine.
KEYBOARD INTERFACING CONCEPTS 6
Conclusion
8086: The 8086 is more suitable for general-purpose computing and complex systems where the keyboard interfacing can be customized through
external hardware and interrupts. Its complexity is higher due to the need for additional peripherals and custom software for keyboard scanning
and interrupt management.
8051: The 8051 microcontroller is better suited for embedded systems with simpler and more direct keyboard interfacing. It comes with built-in peripherals, including
I/O ports and interrupts, making it easier to interface with a matrix keyboard and handle input efficiently.
The 8051 is less complex and more straightforward for keyboard interfacing, while the 8086 provides higher flexibility and power but at the cost of
added complexity in handling keyboard input.
APPLICATIONS OF KEYBOARD 6
INTERFACING
Keyboard interfacing plays a crucial role in numerous applications across embedded systems, data entry and control, and
user interfaces. Whether it's an embedded system used in automation, a data entry terminal, or a sophisticated user
interface, keyboards provide a reliable method for input. Here's a closer look at the applications in these areas:
Embedded Systems
In embedded systems, keyboards are used to facilitate user input for controlling devices, configuring settings, or
interacting with embedded software. These systems are typically designed for specific tasks and may not include full-
fledged operating systems, but still require a method for user input.
Examples of Keyboard Interfacing in Embedded Systems:
Home Automation Systems: Keyboards can be used to control various aspects of a smart home, such as adjusting
lighting, temperature, or security settings. The user can enter commands through a simple matrix keyboard interface.
Medical Devices: In medical devices like infusion pumps, ventilators, or diagnostic tools, keyboards are used for
inputting patient data or controlling settings (e.g., drug dosages, operating modes). The keyboard provides a simple
interface for healthcare professionals to interact with the device.
Security Systems: Keypads are often used in alarm systems, where users input passwords to enable or disable security
systems. These systems rely on simple, low-cost matrix keyboards interfaced with embedded systems.
Key Characteristics in Embedded Systems:
Low-power, compact designs.
Real-time data input and response.
APPLICATIONS OF KEYBOARD 6
INTERFACING
2. Data Entry and Control
Keyboards are essential for data entry and control in a variety of settings, especially in devices that require text input,
command entry, or control operations. In these applications, keyboards are typically used for entering information into a
system, controlling operations, or navigating through different options in menus.
Examples of Keyboard Interfacing in Data Entry and Control:
Point-of-Sale (POS) Systems: In retail environments, POS terminals use keyboards for salespeople to enter item codes,
calculate prices, or process transactions. Keyboards, often with numeric keypads, enable quick and efficient data entry.
Inventory Management Systems: Warehouse workers use keyboards to enter product codes, update stock levels, and
control inventory operations. A keypad or a full keyboard is used depending on the complexity of the data entry needed.
Database Systems: Data entry into databases often requires a keyboard for entering text, numbers, and codes, either
through a command-line interface or graphical user interface (GUI). This could involve anything from entering customer
information to performing searches within large datasets.
Smart Meters and Devices: Keyboards are used in consumer electronics like smart meters for utilities (water, gas,
electricity) to enter user configurations, billing information, or system settings.
Key Characteristics in Data Entry and Control:
Fast and accurate data entry.
Integration with external systems for real-time control and updates.
Often uses numeric keypads or alphanumeric keyboards for varied data entry.
APPLICATIONS OF KEYBOARD 6
INTERFACING
3. User Interfaces
Keyboards are integral components of user interfaces (UIs) in a wide variety of applications, allowing users to interact with
devices, software, or systems. These UIs can range from simple embedded systems to full-fledged computer systems, and
the keyboard serves as a primary method of input.
Examples of Keyboard Interfacing in User Interfaces:
Mobile Devices: Although touchscreen interfaces are more common in mobile devices, external keyboards can be
connected for data entry, such as in tablets, smartphones, or laptop computers. This is particularly useful in
professional or business environments where typing efficiency is needed.
Game Consoles and Entertainment Systems: Keyboards are sometimes used for user input in game consoles or home
entertainment systems for typing, messaging, or navigating settings. Specialized keyboards or custom keypads might be
used for gaming, particularly for text input in multiplayer games.
ATM Machines: ATMs use keyboards for users to enter PIN numbers, select transaction types, and input withdrawal
amounts. Keyboards are part of the interface with the machine, designed for quick and secure data input.
Key Characteristics in User Interfaces:
Interaction with visual displays (either text-based or graphic-based).
Typing and selecting options are commonly managed via keyboard input.
Keyboards provide input for form-based interactions (e.g., entering addresses, login details, or command-line
instructions).
APPLICATIONS OF KEYBOARD 6
INTERFACING
Conclusion