📄 ps-2 mouse interfacing.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0066)http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/mouse/mouse.html -->
<HTML><HEAD><TITLE>PS/2 Mouse Interfacing</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 Chapweske" name=Author><!--This file created 10:20 PM 3/29/01 by Claris Home Page version 3.0--></HEAD>
<BODY aLink=#3333ff bgColor=#ffffff link=#3333ff vLink=#3333ff><X-CLARIS-WINDOW
right="1012" left="0" bottom="603" top="0"><X-CLARIS-TAGVIEW mode="minimal"><!--This file created 8:24 PM 3/26/01 by Claris Home Page version 3.0-->
</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>The PS/2 Mouse Interface</FONT> <BR>This article is
Copyright 2001, Adam Chapweske <BR><BR></CENTER>
<P><B>Electrical Interface / Protocol:</B> </P>
<P>The PS/2 mouse uses the same protocol as the PS/2 (AT) keyboard.
This standard originally appeared in the IBM technical reference manual,
but I am not aware of any current official publication of this
standard. However, you may click <A
href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/PS2/ps2.htm">here</A>
for the (detailed) information I have gathered about that protocol. </P>
<P><B>Inputs, Resolution, and Scaling:</B> </P>
<P>The standard PS/2 mouse supports the following inputs: X (right/left)
movement, Y (up/down) movement, left button, middle button, and right
button. The mouse reads these inputs at a regular freqency and updates
various counters and flags to reflect movement and button states.
There are many PS/2 pointing devices that have additional inputs and may
report data differently than described in this document. One popular
extension I cover later in this document is the Microsoft Intellimouse,
which includes support for the standard inputs as well as a scrolling
wheel and two additional buttons. </P>
<P>The standard mouse has two counters that keep track of movement: the
X-movement counter and the Y-movement counter. These are 9-bit
2's complement values and each has an associated overflow flag.
Their contents, along with the state of the three mouse buttons, are sent
to the host in the form of a 3-byte movement data packet (as described in
the next section.) The movement counters represent the amount of
movement that has occurred since the last movment data packet was sent to
the host. </P>
<P>When the mouse reads its inputs, it records the current state of its
buttons, then checks for movement. If movement has occurred, it increments
(for +X or +Y movement) or decrements (for -X or -Y movement) its X and/or
Y movement counters. If either of the counters has overflowed, it sets the
appropriate overflow flag. </P>
<P>The parameter that determines the amount by which the movement counters
are incremented/decremented is the <I>resolution</I>. The default
resolution is 4 counts/mm and the host may change that value using the
"Set Resolution" (0xE8) command. </P>
<P>There is a parameter that does not effect the movement counters, but
does effect the reported<A
href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/mouse/mouse.html#Footnotes">(1)</A>
value of these counters. This parameter is <I>scaling</I>. By
default, the mouse uses 1:1 scaling, which has no effect on the reported
mouse movement. However, the host may select 1:2 scaling by sending
the "Set Scaling 2:1" (0xE7) command. If 2:1 scaling is enabled, the
mouse will apply the following algorithm to the counters before sending
their contents to the host: <BR> <BR> </P>
<CENTER>
<TABLE border=1 cols=2 width=300>
<TBODY>
<TR>
<TD>
<CENTER>Movement Counter</CENTER></TD>
<TD>
<CENTER>Reported Movement</CENTER></TD></TR>
<TR>
<TD>
<CENTER>0</CENTER></TD>
<TD>
<CENTER>0</CENTER></TD></TR>
<TR>
<TD>
<CENTER>1</CENTER></TD>
<TD>
<CENTER>1</CENTER></TD></TR>
<TR>
<TD>
<CENTER>2</CENTER></TD>
<TD>
<CENTER>1</CENTER></TD></TR>
<TR>
<TD>
<CENTER>3</CENTER></TD>
<TD>
<CENTER>3</CENTER></TD></TR>
<TR>
<TD>
<CENTER>4</CENTER></TD>
<TD>
<CENTER>6</CENTER></TD></TR>
<TR>
<TD>
<CENTER>5</CENTER></TD>
<TD>
<CENTER>9</CENTER></TD></TR>
<TR>
<TD>
<CENTER>N > 5</CENTER></TD>
<TD>
<CENTER>2 * N</CENTER></TD></TR></TBODY></TABLE></CENTER>
<P><B>Movement Data Packet:</B> </P>
<P>The standard PS/2 mouse sends movement (and button) information to the
host using the following 3-byte packet <A
href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/mouse/mouse.html#Footnotes">(4)</A>:
</P>
<BLOCKQUOTE>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=650>
<TBODY>
<TR>
<TD><BR><FONT face=Arial,Helvetica><FONT size=-1>Byte
1 </FONT></FONT></TD>
<TD>
<TABLE border=0 cellPadding=0 cols=8 width="100%">
<TBODY>
<TR>
<TD>
<CENTER>Bit 7</CENTER></TD>
<TD>
<CENTER>Bit 6</CENTER></TD>
<TD>
<CENTER>Bit 5</CENTER></TD>
<TD>
<CENTER>Bit 4</CENTER></TD>
<TD>
<CENTER>Bit 3</CENTER></TD>
<TD>
<CENTER>Bit 2</CENTER></TD>
<TD>
<CENTER>Bit 1</CENTER></TD>
<TD>
<CENTER>Bit 0</CENTER></TD></TR></TBODY></TABLE>
<TABLE border=1 cellPadding=0 cellSpacing=0 cols=8 width="100%">
<TBODY>
<TR>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Y
overflow</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>X
overflow</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Y sign
bit</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>X sign
bit</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Always
1</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Middle
Btn</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Right
Btn</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Left
Btn</FONT></FONT></CENTER></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><FONT face=Arial,Helvetica><FONT size=-1>Byte
2</FONT></FONT></TD>
<TD>
<TABLE border=1 cellPadding=0 cellSpacing=0 cols=1 width="100%">
<TBODY>
<TR>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>X
Movement</FONT></FONT></CENTER></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD><FONT face=Arial,Helvetica><FONT size=-1>Byte
3 </FONT></FONT></TD>
<TD>
<TABLE border=1 cellPadding=0 cellSpacing=0 cols=1 width="100%">
<TBODY>
<TR>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Y
Movement</FONT></FONT></CENTER></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BLOCKQUOTE>The
movement counters are 9-bit 2's complement integers, where the most
significant bit appears as a sign bit in Byte 1 of the movement data
packet. These counters are updated when the mouse reads its input and
finds movement has occurred. Their value is the amount of movement that
has occurred since the last movement data packet was sent to the host (ie,
after a packet is sent to the host, the movement counters are reset.) The
range of values that can be expressed by the movement counters is -255 to
+255. If this range is exceeded, the appropriate overflow bit is set and
the counter is not incremented/decremented until it is reset.
<P>As I mentioned earlier, the movement counters are reset whenever a
movement data packet is successfully sent to the host. They are also reset
after the mouse receives any command from the host other than the "Resend"
(0xFE) command. </P>
<P><B>Modes of Operation:</B> </P>
<P>Data reporting is handled according to the mode in which the mouse is
operating. There are four standard modes of operation: </P>
<UL>
<LI><I>Reset</I> - The mouse enters Reset mode at power-up or after
receiving the "Reset" (0xFF) command.
<LI><I>Stream</I> - This is the default mode (after Reset finishes
executing) and is the mode in which most software uses the mouse.
If the host has previously set the mouse to Remote mode, it may re-enter
Stream mode by sending the "Set Stream Mode" (0xEA) command to the
mouse.
<LI><I>Remote</I> - Remote mode is useful in some situations and may be
entered by sending the "Set Remote Mode" (0xF0) command to the
mouse.
<LI><I>Wrap</I> - This mode isn't particularly useful except for testing
the connection between the mouse and its host. Wrap mode may be
entered by sending the "Set Wrap Mode" (0xEE) command to the
mouse. To exit Wrap mode, the host must issue the "Reset" (0xFF)
command or "Reset Wrap Mode" (0xEC) command. If the "Reset" (0xFF)
command is recieved, the mouse will enter Reset mode. If the
"Reset Wrap Mode" (0xEC) command is received, the mouse will enter the
mode it was in prior to Wrap Mode. </LI></UL>(Note: The mouse may also
enter "extended" modes of operation, as described later in this
document. However, this is not a feature of the standard PS/2
mouse.)
<P><B>Reset Mode:</B> </P>
<P>The mouse enters reset mode at power-on or in response to the "Reset"
(0xFF) command. After entring this mode, the mouse performs a diagnostic
self-test referred to as BAT (Basic Assurance Test) and sets the follwing
default values: </P>
<UL>
<LI>Sample Rate - 100 samples/sec
<LI>Resolution - 4 counts/mm
<LI>Scaling - 1:1
<LI>Data Reporting Disabled </LI></UL>It then sends a BAT completion code
of either 0xAA (BAT successful) or 0xFC (Error). If the host receives a
response other than 0xAA, it may cycle the mouse's power supply, causing
the mouse to reset and re-execute its BAT.
<P>Following the BAT completion code (0xAA or 0xFC), the mouse sends its
device ID of 0x00. This distinguishes it from a keyboard, or a mouse in an
extended mode. I have read documents saything the host is not
<I>supposed</I> to transmit any data until it receives a device ID.
However I've found that some BIOS's will send the "Reset" (0xFF) command
immediately following the 0xAA received after a power-on reset. </P>
<P>After the mouse has sent its device ID to the host, it will enter
Stream Mode. Note that one of the default values set by the mouse is
"Data Reporting Disabled". This means the mouse will not send any
movement data packets to the host until the "Enable Data Reporting" (0xF4)
command is received. </P>
<P><B>Stream Mode:</B> </P>
<P>In stream mode, the mouse sends movement data when it detects movement
or a change in state of one or more mouse buttons. The maximum rate at
which this data reporting may occur is known as the <I>sample
rate</I>. This parameter ranges from 10 samples/sec to 200
samples/sec. Its default value is 100 samples/sec and the host may change
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -