0% found this document useful (0 votes)
106 views30 pages

Lec 1

This document provides information about interfacing keyboards to microprocessors and details on how keyboards are interfaced in IBM PC computers. It discusses how keyboards use a matrix of rows and columns accessed through ports. For PC keyboards, an 8042 microcontroller scans keys and sends scan codes to the motherboard. When a key is pressed or released, INT 09 handles reading the scan code and storing it in a keyboard buffer. INT 16H is used by programs to read characters from this buffer.

Uploaded by

yahia mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views30 pages

Lec 1

This document provides information about interfacing keyboards to microprocessors and details on how keyboards are interfaced in IBM PC computers. It discusses how keyboards use a matrix of rows and columns accessed through ports. For PC keyboards, an 8042 microcontroller scans keys and sends scan codes to the motherboard. When a key is pressed or released, INT 09 handles reading the scan code and storing it in a keyboard buffer. INT 16H is used by programs to read characters from this buffer.

Uploaded by

yahia mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 30

Microprocessor

II
Khaled M. Ibraheem
Email: Khsoradi@eng.cu.edu.eg
Phone: 01277377726
FB/groups/CMPN211
Course Syllabus and Grading

• Class Work:
– 15: Project
– 10: Assignments
– 5: Quizzes
– 10: Labs
• References:
– Barry B. Brey, ``The Intel Microprocessors”.
– M.A. Mazidi, ``The 80x86 IBM PC and Compatible
Computers”.
Course Contents

• Part 1
– Keyboard and parallel port
– 8255 I/O programming
– Motor
– sensor and timer
• Part 2
– Introduction to Microcontroller
• Part 3
– Interrupts and interrupt controller
– Direct memory access (DMA)
– Memory , high-speed memory design and cache
– Video and video adapters
– Hard disk
Keyboard
and Printer Interfacing
INTERFACING KEYBOARD TO CPU

• Keyboards are organized in a matrix of rows and


columns, and the CPU accesses rows & columns
through ports.
– With two 8-bit ports, an 8 x 8 matrix of keys can be
connected to a microprocessor.
• On a keypress, a row & column make contact.
– Otherwise, there is no connection between rows/columns.
• In PC keyboards, a single microcontroller takes care
of hardware & software interfacing of the keyboard.
– It scans keys continuously, identifies which one has
been activated & presents it to the motherboard CPU.
INTERFACING KEYBOARD TO CPU

4 x 4 matrix connected
to two ports.
If no key has been pressed,
the input port will yield 1s for
all columns, since they are
all connected to high. (Vcc)

If all the rows are grounded


and a key is pressed, one of
the columns will have 0.
The key pressed provides
the path to ground.
Matrix Keyboard Connection to Ports
INTERFACING KEYBOARD TO CPU
grounding rows and reading the columns
• To detect the key pressed, the processor grounds
all rows by providing 0 to the output latch, and then
reads the columns.
– If data read from the columns is D3–D0 = 1111, no key
has been pressed
• The process continues until a key press is detected.
– If one of the column bits has a zero, a key press has
occurred.
INTERFACING KEYBOARD TO CPU
grounding rows and reading the columns
• To identify the key, the microprocessor, starting with
the top row, grounds it by providing a low to row D0
only, then it reads the columns.
– If the data read is all 1s, no key in that row is activated.
• The process is moved to the next row.
– This process continues until the row is identified.
INTERFACING KEYBOARD TO CPU
grounding rows and reading the columns
• After identification of the row, the next task is to find
out which column the pressed key belongs to.
– Easy, since the CPU knows at any time which row and
column are being accessed.
PC KEYBOARD INTERFACING/PROGRAMMING

• The keyboard microcontroller used widely in the PC


and compatibles is Intel's 8042. (or some variation)
– A scan code is assigned to each key, and the controller
provides the code for the pressed key to the motherboard.
• IBM PC/AT keyboards use the following data frame
to send scan code serially to the motherboard.
– For each scan code, a total of 11 bits are transferred.
• One start bit (always 0)
• 8 bits for scan code
• Odd parity bit
• One stop bit (always 1)
PC KEYBOARD INTERFACING/PROGRAMMING
make and break
• In the IBM PC, the key press and release are
represented by two different scan codes.
– The key press is referred to as a make, for which
the keyboard sends a scan code.
– Release of the same key is called a break, for which
another scan code is sent.
• The scan code for the break is always 127 decimal (80H)
larger than the make scan code.
PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• The original IBM PC keyboard had 83 keys in three
major groupings:
– 1. The standard typewriter keys
– 2. Ten function keys, F1 to F10
– 3. 15-key keypad

IBM later introduced


the the enhanced
keyboard, with the
number of keys
increased to 101.
PC KEYBOARD INTERFACING/PROGRAMMING
INT 09 interrupt service
• To understand fully principles in the PC keyboard,
it is necessary to know how INT 09 works.
– The PC keyboard communicates with the motherboard
through hardware interrupt IRQ1 of the 8259.

Keyboard Cable Jack for the PC


PC KEYBOARD INTERFACING/PROGRAMMING
INT 09 interrupt service sequence
1. The keyboard microcontroller scans the keyboard
matrix continuously.
– When a key is pressed (a make)…
• It is identified and its scan code is sent serially to the
motherboard through the keyboard cable.
– The circuitry on the motherboard…
• Receives the serial bits.
• Gets rid of the frame bits
• Makes one byte (scan code) with its serial-in-parallel-out
shift register
• Presents this 8-bit scan code to port A of 8255 at
I/O address 60H.
• Activates IRQ1.
PC KEYBOARD INTERFACING/PROGRAMMING
INT 09 interrupt service sequence
2. Since IRQ1 is set to INT 09, its interrupt service
routine (ISR) residing in BIOS ROM is invoked.
3. ISR of INT 09 reads the scan code from port 60H.
4. ISR of INT 09 tests the scan code to see if it is
the Right or Left Shift, Alt, Ctrl keys, etc.
– If so, the appropriate bit of the keyboard status
bytes in BIOS 0040:0017H and 0018H are set.
• It will not write the scan code to the keyboard buffer.
5. Before returning from INT 09, ISR will issue EOI
to unmask IRQ1, followed by the IRET instruction.
– This allows IRQ1 activation to be responded to again.
PC KEYBOARD INTERFACING/PROGRAMMING
INT 09 interrupt service sequence
6. When the key is released (a break), the keyboard
generates the second scan code by adding 80H to
it and sends it to the motherboard.
7. ISR of INT 09 checks the scan code to see if there
is 80H difference between this code and the one.
– If D7 is high, it is interpreted as meaning the key has
been released & the system ignores the 2nd scan code.
– If the key is held down more than 0.5 seconds, it is
interpreted as a new key and INT 09 will write it into
the keyboard buffer next to the preceding one.
• Commonly referred to as typematic in IBM literature,
which means repeating the same key.
PC KEYBOARD INTERFACING/PROGRAMMING
keyboard overrun
• On the keyboard side, the 8042 must serialize the
scan code & send it by cable to the motherboard.
• On the motherboard side, circuits get the serial
data & make a single byte of scan code out of
the bit streams, and holds it for the CPU to read.
• The CPU can fall behind, and fail to keep up with
the number of keystrokes, called keyboard overrun.
– The motherboard beeps the speaker when overrun occurs.
• BIOS ROM on the motherboard is responsible for
beeping the speaker in the event of keyboard
overrun.
PC KEYBOARD INTERFACING/PROGRAMMING
BIOS keyboard buffer
• INT 09 gets the scan code from the keyboard and
stores it in memory locations in the BIOS data area.
– Referred to as the BIOS keyboard buffer, it should not
be confused with the buffer in the keyboard itself.
• 32 bytes (16 words) of BIOS data memory is set
aside, at addresses 40:001EH - 40:003DH.
– Physical addresses 0041EH and 0043DH.
• Each two consecutive locations are used for a
single character.
– One for the scan code, the other for the ASCII code (if
any) of the character.
PC KEYBOARD INTERFACING/PROGRAMMING
buffer pointers - tail pointer
• There are two keyboard buffer pointers:
– The head pointer and the tail pointer.

– It is the job of INT 09 to put the character in the keyboard


buffer and advance the tail by incrementing the word
contents of location 0041C, where the tail pointer is held.
– Memory locations 0040:001CH & 0040:001DH
(physical addresses 0041CH & 0041DH) hold the
address for the tail.
18.2: PC KEYBOARD INTERFACING/PROGRAMMING
buffer pointers - head pointer
• As INT 16H reads a character from the keyboard
buffer, it advances the head pointer, which is held
by memory locations 41AH and 41BH.
– As INT 09 inserts the character into the keyboard buffer,
it advances the tail.
– As INT 16H reads the character from the keyboard buffer
it advances the head.
PC KEYBOARD INTERFACING/PROGRAMMING
buffer pointers
• As INT 16H reads a character from the keyboard
buffer, it advances the head pointer, which is held
by memory locations 41AH and 41BH.
– When they come to the end of the keyboard buffer, they
both wrap around, creating a ring of 16 words where the
head is continuously chasing the tail.
– If the buffer is empty, head address equals tail address.

Keyboard Buffer Head and Tail


PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• The same scan code is used for a given lowercase
letter & capital, as for all the keys with dual labels.
– location 0040:0017H holds the shift status byte.

When a key is pressed, the interrupt service routine of INT 9


receives the scan code and stores it in a memory location
called a keyboard buffer, located in the BIOS data area.
PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• The same scan code is used for a given lowercase
letter & capital, as for all the keys with dual labels.
– location 0040:0018H holds the second status byte.

Some of the bits are used for the 101-key enhanced keyboards.
To relieve programmers from details of keyboard and
motherboard interaction, IBM provides INT 16H.
PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• INT 16H, AH = 0 (read a character) - checks the
keyboard buffer for a character.
– If a character is available, it returns its scan code in AH
and its ASCII code in AL.
– If no character is available in the buffer, it waits for a
key press and returns it.
– For characters for which there is no ASCII code, it
provides the scan code in AH and AL = 0.
• Such as F1–F10.
PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• INT 16H, AH = 01 (find if a character is available) -
checks the keyboard buffer for a character.
– If a character is available, it returns its scan code in AH,
its ASCII code in AL, and sets ZF = 0.
– If no character is available in the buffer, it does not wait
for a key press, and simply makes ZF = 1.
PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• INT 16H, AH = 02 (return current keyboard status
byte) - provides keyboard status in register AL.
– The keyboard status byte (also referred to as the
keyboard flag byte) is located in the BIOS data area
memory location 0040:0017H.

Fig. 18-3 First Keyboard Status Byte


PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• INT 16H, AH = 02 (return current keyboard status
byte) - provides keyboard status in register AL.
PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
• INT 16H, AH = 10H (read a character) - same as
AH = 0 except it also accepts the additional keys
on the IBM extended (enhanced) keyboard.
• INT 16H, AH = 11H (find if a character is available) -
same as AH = 1 except it accepts the additional
keys on the IBM extended (enhanced) keyboard.
• INT 16H, AH = 12H (return the current status byte) -
same as AH = 2 except it also provides the shift
status byte of the IBM extended (enhanced)
keyboard to AH.
PC KEYBOARD INTERFACING/PROGRAMMING
IBM PC scan codes
PC KEYBOARD INTERFACING/PROGRAMMING
PC keyboard technology
• The keyboard shown is 4 x 4 matrix connected
a hard contact keyboard. to two ports.
– When a key is pressed,
a physical contact in the
row & column causes
the column to be pulled
to ground.
– The alternative to hard
contact keyboards are
capacitive keyboards.
• No physical contact.
• There is a capacitor for
each point of the matrix. Matrix Keyboard Connection to Ports

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy