📄 the ps-2 mouse-keyboard protocol.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0061)http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/PS2/ps2.htm -->
<HTML><HEAD><TITLE>The PS/2 Mouse/Keyboard Protocol</TITLE>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" 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 aLink=#3333ff bgColor=#ffffff link=#0000ee vLink=#3333ff><X-CLARIS-WINDOW
right="1012" left="0" bottom="607" top="0"><X-CLARIS-TAGVIEW
mode="minimal"></X-CLARIS-TAGVIEW></X-CLARIS-WINDOW>
<TABLE bgColor=#faf0e6 border=0 cellPadding=4 cellSpacing=0 cols=1
width="100%"><TBODY>
<TR>
<TD>
<CENTER><FONT size=+2><BR>PS/2 Mouse/Keyboard Protocol</FONT><BR>This
article is Copyright 1999, Adam Chapweske </CENTER><BR>
<P><B>Introduction:</B> </P>
<P>The PS/2 device interface, used by many modern mice and keyboards, was
developed by IBM and originally appeared in the IBM Technical Reference
Manual. However, this document has not been printed for many years
and as far as I know, there is currently no official publication of this
information. I have not had access to the IBM Technical Reference
Manual, so all information on this page comes from my own experiences as
well as help from the references listed at the bottom of this page. </P>
<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://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/keyboard/atkeyboard.html">The
PS/2 (AT) Keyboard Interface</A> <BR><A
href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/mouse/mouse.html">The
PS/2 Mouse Interface</A></BLOCKQUOTE>I also encourage you to check this
site's <A href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro">main
page</A> for more information related to this topic, including projects,
code, and links related to the mouse and keyboard. Please send an <A
href="mailto:achapwes@panda.cs.ndsu.nodak.edu">email </A>if you find any
mistakes or bad advice on this site.<BR><BR><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>. I have only seen this
type of connector on (old) XT keyboards, although there may be AT
keyboards that also use the SDL. 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 align=bottom height=68
src="The PS-2 Mouse-Keyboard Protocol_files/fpindin.jpg" width=80>
<BR>(Plug)</CENTER></TD>
<TD>
<CENTER>Female <BR><IMG height=68
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 align=bottom height=68
src="The PS-2 Mouse-Keyboard Protocol_files/spindin.jpg" width=80>
<BR>(Plug)</CENTER></TD>
<TD>
<CENTER>Female <BR><IMG align=bottom height=68
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 align=bottom height=49
src="The PS-2 Mouse-Keyboard Protocol_files/sdl.jpg" width=114>
</CENTER></TD>
<TD>
<CENTER><IMG align=bottom height=49
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 100 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 = +5V. <BR>Max
Current = 100 mA.<BR></P></BLOCKQUOTE>
<P>The Data and Clock lines are both open-collector with pullup resistors
to +5V. 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>
<P><IMG alt="" height=330
src="The PS-2 Mouse-Keyboard Protocol_files/ps2.jpg" width=352>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -