You are on page 1of 15

LCD AND KEYBOARD

INTERFACING(2)
KEYBOARD
INTERFACING
Interfacing the keyboard to the 8051
• At the lowest level, keyboards are organized in a matrix of rows and
columns.
• In IBM PC keyboards, a single microcontroller (consisting of a
microprocessor, RAM and EPROM, and several ports all on a single
chip) takes care of hardware and software interfacing of the keyboard.
• The microcontroller scans the keys continuously, identify which one
has been activated, and present it to the motherboard.
4x4 keypad
Scanning and identifying the key

• 4x4 Matrix Keyboard


Connection to Ports
A key press detection and identification
• A key press detection
• OUT =0000  INPUT = ?  = 1111 (no key pressed), other wise (a key
pressed)
• Identify the pressed key
• OUT =1110  INPUT = ?  = 1111 (no key pressed), otherwise the
column with a 0 identify the pressed key
• The process is repeated with other rows.
Mechanical switches are used as keys in most of the keyboards. When a key is
pressed the contact bounce back and forth and settle down only after a small time
delay (about 20ms). Even though a key is actuated once, it will appear to have been
actuated several times. This problem is called Key Bouncing.

http://www.labbookpages.co.uk/electronics/debounce.html
Hardware Key de-bouncing
(circuit examples)
MM74C922 • MM74C923
16-Key Encoder • 20-Key Encoder
Block Diagram
Truth Tables
Software De-bouncing
• After the key press detection, the microcontroller waits 20 ms for the
bounce and then scans the columns again
• This serves two functions: (a) it ensures that the first key press
detection was not an erroneous one due to a spike noise, and (b) the
20-ms delay prevents the same key press from being interpreted as a
multiple key press.
• If after the 20-ms delay the key is still pressed, it goes to the next
stage to detect which row it belongs to; otherwise, it goes back into
the loop to detect a real key press.
Accessing code data space in 8051 C
• In all our 8051 C examples so far, byte-size variables were stored in
the 128 bytes of RAM.
• To make the C compiler use the code space instead of the RAM space,
we need to put the keyword code in front of the variable declaration.
• Example:
code unsigned char mynum[] = "012345ABCD"; //use code space
code unsigned char weekdays=7, month=12; //use code space

You might also like