📄 the ps-2 mouse-keyboard protocol.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0048)http://www.computer-engineering.org/ps2protocol/ -->
<HTML><HEAD><TITLE>The PS/2 Mouse/Keyboard Protocol</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2995" name=GENERATOR>
<META content="Adam C" name=Author>
<META
content="This site contains info on the PS/2 protocol and interfacing keyboards and the PS/2 mouse."
name=Description>
<META
content="PS/2, PS/2, PS/2, PS/2, PS/2, PS/2, PS/2, PS/2, PS/2, PS/2, PIC, microcontroller, interfacing, keyboard, mouse, mice, AT keyboard, PS/2 mouse, PC keyboard, interfacing, mouse, PS/2"
name=KeyWords><!--This file created 3:58 PM 2/5/2000 by Claris Home Page version 3.0--></HEAD>
<BODY vLink=#3333ff aLink=#3333ff link=#0000ee bgColor=#ffffff><SMALL><B><FONT
face=Arial,Helvetica><FONT size=+3><SMALL>The PS/2 Mouse/Keyboard
Protocol</SMALL></FONT></FONT></B></SMALL><BR>
<CENTER></CENTER>
<CENTER>
<HR align=left width=400 noShade SIZE=1>
</CENTER><BR><FONT face=Arial,Helvetica>Source: <A
href="http://www.computer-engineering.org/">http://www.computer-engineering.org/</A></FONT><BR><FONT
face=Arial,Helvetica>Author: Adam Chapweske<BR>Last Updated:
05/09/03<BR><BR><BR></FONT><B>Legal Information:</B><BR><BR>All information
within this article is provided "as is" and without any express or implied
warranties, including, without limitation, the implied warranties of
merchantibility and fitness for a particular purpose. <BR><BR>This article
is protected under copyright law. This document may be copied only if the
source, author, date, and legal information is included.<BR><BR><B>Abstract:</B>
<P>This document descibes the interface used by the PS/2 mouse, PS/2 keyboard,
and AT keyboard. I'll cover the physical and electrical interface, as well
as the protocol. If you need higher-level information, such as commands,
data packet formats, or other information specific to the keyboard or mouse, I
have written separate documents for the two devices: </P>
<BLOCKQUOTE><A href="http://www.computer-engineering.org/ps2keyboard">The PS/2
(AT) Keyboard Interface</A> <BR><A
href="http://www.computer-engineering.org/ps2mouse">The PS/2 Mouse
Interface</A></BLOCKQUOTE><B>The Physical Interface:</B><BR>
<P>The physical PS/2 port is one of two styles of connectors: The 5-pin
DIN or the 6-pin mini-DIN. Both connectors are completely (electrically)
similar; the only practical difference between the two is the arrangement of
pins. This means the two types of connectors can easily be changed with
simple hard-wired adaptors. These cost about $6 each or you can make your
own by matching the pins on any two connectors. The DIN standard was
created by the German Standardization Organization (Deutsches Institut fuer
Norm) . Their website is at <A href="http://www.din.de/"
target=_top>http://www.din.de/</A> (this site is in German, but most of their
pages are also available in English.) </P>
<P>PC keyboards use either a 6-pin mini-DIN or a 5-pin DIN connector. If
your keyboard has a 6-pin mini-DIN and your computer has a 5-pin DIN (or visa
versa), the two can be made compatible with the adaptors described above.
Keyboards with the 6-pin mini-DIN are often referred to as "PS/2" keyboards,
while those with the 5-pin DIN are called "AT" devices ("XT" keyboards also used
the 5-pin DIN, but they are quite old and haven't been made for many
years.) All modern keyboards built for the PC are either PS/2, AT, or
USB. This document <I>does not</I> apply to USB devices, which use a
completely different interface. </P>
<P>Mice come in a number of shapes and sizes (and interfaces.) The most
popular type is probably the PS/2 mouse, with USB mice gaining popularity.
Just a few years ago, serial mice were also quite popular, but the computer
industry is abandoning them in support of USB and PS/2 devices. This
document applies only to PS/2 mice. If you want to interface a serial or
USB mouse, there's plenty of information available elsewhere on the
web.<BR><BR>The cable connecting the keyboard/mouse to the computer is usually
about six feet long and consists of four to six 26 AWG wires surrounded by a
thin layer of mylar foil sheilding. If you need a longer cable, you can
buy PS/2 extenstion cables from most consumer electronics stores. You
should not connect multiple extension cables together. If you need a
30-foot keyboard cable, buy a 30-foot keyboard cable. Do not simply
connect five 6-foot cables together. Doing so could result in poor
communication between the keyboard/mouse and the host.<BR></P>
<P>As a side note, there is one other type of connector you may run into on
keyboards. While most keyboard cables are hard-wired to the keyboard, there are
some whose cable is not permanently attached and come as a separate
component. These cables have a DIN connector on one end (the end that
connects to the computer) and a SDL (Sheilded Data Link) connector on the
keyboard end. SDL was created by a company called "AMP." This
connector is somewhat similar to a telephone connector in that it has wires and
springs rather than pins, and a clip holds it in place. If you need more
information on this connector, you might be able to find it on AMP's website at
<A href="http://www.connect.amp.com/"
target=_top>http://www.connect.amp.com/</A>. Don't confuse the SDL
connector with the USB connector--they probably both look similar in my diagram
below, but they are actually very different. Keep in mind that the SDL
connector has springs and moving parts, while the USB connector does not. </P>
<P>The pinouts for each connector are shown below: <BR>
<TABLE width=468>
<TBODY>
<TR>
<TD>
<CENTER>Male <BR><IMG height=68 alt=""
src="The PS-2 Mouse-Keyboard Protocol.files/fpindin.jpg" width=80>
<BR>(Plug)</CENTER></TD>
<TD>
<CENTER>Female <BR><IMG height=68 alt=""
src="The PS-2 Mouse-Keyboard Protocol.files/fpdin1.jpg" width=80>
<BR>(Socket)</CENTER></TD>
<TD><B>5-pin DIN (AT/XT): </B> <BR>1 - Clock <BR>2 - Data <BR>3 - Not
Implemented <BR>4 - Ground <BR>5 - Vcc (+5V)</TD></TR></TBODY></TABLE><BR>
<TABLE width=469>
<TBODY>
<TR>
<TD>
<CENTER>Male <BR><IMG height=68 alt=""
src="The PS-2 Mouse-Keyboard Protocol.files/spindin.jpg" width=80>
<BR>(Plug)</CENTER></TD>
<TD>
<CENTER>Female <BR><IMG height=68 alt=""
src="The PS-2 Mouse-Keyboard Protocol.files/spindin1.jpg" width=80>
<BR>(Socket)</CENTER></TD>
<TD><B>6-pin Mini-DIN (PS/2):</B> <BR>1 - Data <BR>2 - Not Implemented
<BR>3 - Ground <BR>4 - Vcc (+5V) <BR>5 - Clock <BR>6 - Not
Implemented</TD></TR></TBODY></TABLE><BR>
<TABLE width=469>
<TBODY>
<TR>
<TD>
<CENTER><IMG height=49 alt=""
src="The PS-2 Mouse-Keyboard Protocol.files/sdl.jpg" width=114>
</CENTER></TD>
<TD>
<CENTER><IMG height=49 alt=""
src="The PS-2 Mouse-Keyboard Protocol.files/sdl1.jpg" width=114>
</CENTER></TD>
<TD><B>6-pin SDL:</B> <BR>A - Not Implemented <BR>B - Data <BR>C - Ground
<BR>D - Clock <BR>E - Vcc (+5V) <BR>F - Not
Implemented</TD></TR></TBODY></TABLE></P>
<P></P>
<P><BR><B>The Electrical Interface:</B><BR></P>
<P>Note: Throughout this document, I will use the more general term "host"
to refer to the computer--or whatever the keyboard/mouse is connected to-- and
the term "device" will refer to the keyboard/mouse. </P>
<P>Vcc/Ground provide power to the keyboard/mouse. The keyboard or mouse
should not draw more than 275 mA from the host and care must be taken to avoid
transient surges. Such surges can be caused by "hot-plugging" a
keyboard/mouse (ie, connect/disconnect the device while the computer's power is
on.) Older motherboards had a surface-mounted fuse protecting the keyboard
and mouse ports. When this fuse blew, the motherboard was useless to the
consumer, and non-fixable to the average technician. Most newer
motherboards use auto-reset "Poly" fuses that go a long way to remedy this
problem. However, this is not a standard and there's still plenty of older
motherboards in use. Therefore, I recommend against hot-plugging a PS/2
mouse or keyboard.<BR></P>
<BLOCKQUOTE>
<P><U>Summary: Power Specifications</U><BR>Vcc = +4.5V to +5.5V. <BR>Max
Current = 275 mA.<BR></P></BLOCKQUOTE>
<P>The Data and Clock lines are both open-collector with pullup resistors to
Vcc. An "open-collector" interface has two possible state: low, or high
impedance. In the "low" state, a transistor pulls the line to ground
level. In the "high impedance" state, the interface acts as an open
circuit and doesn't drive the line low or high. Furthermore, a "pullup" resistor
is connected between the bus and Vcc so the bus is pulled high if none of the
devices on the bus are actively pulling it low. The exact value of this
resistor isn't too important (1~10 kOhms); larger resistances result in less
power consumption and smaller resistances result in a faster rise time. A
general open-collector interface is shown below:<BR></P>
<BLOCKQUOTE>
<P><FONT color=#ff0000>Figure 1: General open-collector interface. Data
and Clock are read on the microcontroller's pins A and B, respectively.
Both lines are normally held at +5V, but can be pulled to ground by
asserting logic "1" on C and D. As a result, Data equals D, inverted,
and Clock equals C, inverted.</FONT><BR></P></BLOCKQUOTE>
<BLOCKQUOTE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -