Interfacing Lec7
Interfacing Lec7
& Microcontrollers
Computer Science & Engineering
University of Chittagong
Lecture 7
Keyboard Interfacing
Outline
• Introduction
• Keyboard organization
• Key Switches
• Keyboard Scanning
• Keyboard Interfacing
Introduction
• The keyboard was one of the first peripherals to be used with
computers
• It is still the primary input device for entering text and numbers
• A standard keyboard includes 100 keys
• Skill of typing is called keyboarding
• It contains keys for
• Alphabets
• Numeric digits
• Special characters
• Controls
• It transfers user commands and data to the system
• Each key sends a different signal to the CPU
First Keyboard
⚫ The invention of the modern computer keyboard began with the
invention of the typewriter
⚫ Christopher Latham Sholes patented the typewriter that we commonly
use today in 1868
⚫ The Remington Company mass marketed the first typewriters starting
in 1877
Keyboard Organization
• Keyboard consists of
• A number of switches organized in a matrix form
• An electronic circuit based on a microcontroller called
Keyboard Encoder
• Keyboard Encoder
• Monitors the status of all switches
• Detects pressing and releasing keys
• Encodes and transfers the information to the system
Arrangement of Key switch on Keyboard
Ref. Current
Keyboard Types
• Several types of Keyboard
• 83-key PC/PC-XT keyboard - 1983
• 84-key PC-AT keyboard - 1984
• 101-key Enhanced Keyboard
• 104-key Enhanced Keyboard
• PS/2 type keyboard - AT keyboard is renamed as PS/2 port after IBM PS/2 is
debuted in 1987
• USB Keyboard
Key Debouncing
• When a key is pressed
• The switch, before establishing a firm contact, makes and breaks
the contact several times
• This is known as debouncing
• The system should not misinterpret key bouncing as the key is being
pressed and released many times
• There are many hardware and software debouncing methods to
debounce key bouncing
• The simple method is a software delay for 20 ms is introduced
every time a key is pressed or released
Keyboard Encoder
• When a key is pressed, the associated keyboard hardware
• Detects pressing of keys
• Debounces key bouncing
• Determines the row and column numbers associated with the key being
pressed
• Converts the row and column information to a standard code
• Informs the system
• The keyboard's built-in processor
• reads the key matrix,
• debounces the keypress signals,
• converts the keypress to the appropriate scan code, and
• transmits the code to the motherboard.
• The processors built into the keyboard contain their own RAM, possibly
some ROM, and a built-in serial interface
Keyboard Encoder
• The original PC Keyboard used intel 8048 microcontroller as keyboard
encoder
• It consists of
• An 8-bit CPU
• 1KB ROM – stores programs for monitoring the key status, for debouncing
when a key is pressed and for determining the scan code for the key being
pressed
• Three I/O ports
• A programmable timer/ counter
• It transmits the code to the PC through a special serial link
• New keyboard uses 8049 version or other microcontroller compatible with
8048 or 8049
• Motorola 6805 processor
• It can also buffer up to 20 scan codes
Keyboard interface
• Scan Code
• Keyboard assign unique scan code for each key and inform pressing and
releasing of keys by transferring the codes of respective keys
• Make Code - The code is sent by keyboard when a key is pressed
• Break Code – the code is sent by keyboard when a key is released
• 101-key PC-AT enhanced keyboard is
• The break code for a key is two bytes long, where the first byte is F0H and
the second byte is the make code for that key
Keyboard Scanning Process
D0
Output port D1
D2
D3
D3 D2 D3 D0 Input port
Keyboard Scanning Process
• To determine whether a key is pressed or not
• ‘0000’ is written into the output port
• The input port is read
• If all the keys are open, the input port is read ‘1111’
• If a key is pressed the port reads ‘0’ in one of 4 bits
• It gives the information of column number of the key
• After a key debouncing delay period of 20ms, the input port is again read to ensure that
actually a key has been pressed
• To find out which key is pressed
• The LSB of the output port is set to ‘0’ and the remaining bits are set to ‘1’ (i.e. 1110)
• The input port is read
• If it reads ‘1’ in all the 4 bits, it indicates that the key being pressed is not in that key
• Then the next bit is set to ‘0’ keeping the other bits 1 (i.e 1101) and the input port is read
• The process is continued till the input port reads ‘0’ in one of the bits
• The content of the output port provides the information of row number of the key
Keyboard Interface
• PC/PC-XT keyboard interface
• It used 8255 PPI (Programmable Peripheral Interface) on the motherboard to
receive scan code from the keyboard
• This chip is connected to the interrupt controller IRQ1 line
• When a scan code is received, the 8255 generates an interrupt signal on
IRQ1 line to indicate the availability of keyboard data
• The data is then sent from the 8255 to the processor via I/O port address
60h.
• The IRQ1 signal causes the main system processor to run a subroutine (INT
9h) that interprets the keyboard scan code data and decides what to do.
Keyboard Interface
Keyboard Interface
• PC-AT keyboard interface
• In an AT-type keyboard design, the keyboard serial interface is connected to a special
keyboard controller (8042-type microcontroller) on the motherboard
• It has its own 2KB of ROM and 128 bytes of RAM
• An 8742 version that uses erasable programmable read-only memory (EPROM) can be
erased and reprogrammed
• the (8048-type) microcontroller in the keyboard sends data to the (8042-type) keyboard
controller on the motherboard
• When the keyboard controller on the motherboard receives data from the keyboard, it
signals the motherboard with an IRQ1 and sends the data to the main motherboard
processor via I/O port address 60h, just as in the PC/XT
• Acting as an agent between the keyboard and the main system processor, the 8042-type
keyboard controller can translate scan codes and perform several other functions as
well.
• The system can send data to the keyboard via 8042 microcontroller by writing the data
into the port 60H
• When the system needs to send commands to or read the status of the keyboard
controller on the motherboard, it reads or writes through I/O port 64h
Keyboard Interface
Keyboard System
Key Matrix GND
Input Port
Communication over this interface is accomplished using two signal lines that are designed as
• Keyboard Data (KBD Data) – it carries data bits from keyboard to the system and
commands from the system to the keyboard
• Keyboard Clock (KBD Clock) – this signal is used to synchronize the keyboard and
the system
Keyboard Connectors
• USB connector
• Inside the keyboard a variety of custom controller chips is used by various
keyboard manufacturers
• to receive and interpret keyboard data before sending it to the system via
the USB port
• After the keyboard data reaches the USB port on the system
• the USB port routes the data to the 8042-compatible keyboard controller,
where the data is treated as any other keyboard information
• During the BIOS configuration routine
• USB Legacy support must be enabled in the BIOS
http://geekscomputer.blogspot.com/2008/07/keyboard-interface.html
Keyboard Connectors
• Keyboard communicates with the main system in one of two ways:
• Through a special serial data link if a standard keyboard connector is used
• Through the USB port
• Keyboard Connector
• The standard keyboards are connected to the system through a special type of serial link
• All keyboards use either larger 5-pin DIN (Deutsches Institut für Normung) for PC XT
connector or the 6-pin mini-DIN for PC AT connector for attaching to the motherboard
• Keyboard Data (KBD Data) – Pin 2 for 5-Pin DIN and Pin 1 for 6-Pin DIN
• Keyboard Clock (KBD Clock) - Pin 1 for 5-Pin DIN and Pin 5 for 6-Pin DIN
• In modern motherboards, the two lines are bidirectional
Thank You
Q/A