📄 ps-2 mouse interfacing.htm
字号:
right, the Z-counter is incremented by <I>two</I> and if it is scrolled
left, the Z-counter is decremented by <I>two</I>. This seems like an
odd way to implement the second scrolling wheel, but it works since the
placement of the two wheels make it impossible to use both of them at the
same time (and if you try to trick the software and use both at the same
time, it will ignore the horizontal wheel.)
<P><B>Command Set:</B> </P>
<P>The following are the only commands that may be sent to the mouse... If
the mouse is in Stream mode, the host should disable data reporting
(command 0xF5) before sending any other commands... </P>
<UL>
<LI>0xFF (Reset) - The mouse responds to this command with "acknowledge"
(0xFA) then enters Reset Mode.
<LI>0xFE (Resend) - The host sends this command whenever it receives
invalid data from the mouse. The mouse responds by resending the last<A
href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/mouse/mouse.html#Footnotes">(2)</A>
packet<A
href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/mouse/mouse.html#Footnotes">(3)</A>
it sent to the host. If the mouse responds to the "Resend"
command with another invalid packet, the host may either issue another
"Resend" command, issue an "Error" command, cycle the mouse's power
supply to reset the mouse, or it may inhibit communication (by bringing
the Clock line low). The action taken depends on the host.
<LI>0xF6 (Set Defaults) - The mouse responds with "acknowledge" (0xFA)
then loads the following values: Sampling rate = 100, Resolution =
4 counts/mm, Scaling = 1:1, Disable Data Reporting. The mouse then
resets its movement counters and enters stream mode.
<LI>0xF5 (Disable Data Reporting) - The mouse responds with
"acknowledge" (0xFA) then disables data reporting and resets its
movement counters. This only effects data reporting in Stream mode
and does not disable sampling. Disabled stream mode funcions the
same as remote mode.
<LI>0xF4 (Enable Data Reporting) - The mouse responds with "acknowledge"
(0xFA) then enables data reporting and resets its movement
counters. This command may be issued while the mouse is in Remote
Mode (or Stream mode), but it will only effect data reporting in Stream
mode.
<LI>0xF3 (Set Sample Rate) - The mouse responds with "acknowledge"
(0xFA) then reads one more byte from the host. The mouse saves
this byte as the new sample rate. After receiving the sample rate, the
mouse again responds with "acknowledge" (0xFA) and resets its movement
counters. Valid sample rates are 10, 20, 40, 60, 80, 100, and 200
samples/sec.
<LI>0xF2 (Get Device ID) - The mouse responds with "acknowledge" (0xFA)
followed by its device ID (0x00 for the standard PS/2 mouse.) The
mouse should also reset its movement counters.
<LI>0xF0 (Set Remote Mode) - The mouse responds with "acknowledge"
(0xFA) then resets its movement counters and enters remote mode.
<LI>0xEE (Set Wrap Mode) - The mouse responds with "acknowledge" (0xFA)
then resets its movement counters and enters wrap mode.
<LI>0xEC (Reset Wrap Mode) - The mouse responds with "acknowledge"
(0xFA) then resets its movement counters and enters the mode it was in
prior to wrap mode (Stream Mode or Remote Mode.)
<LI>0xEB (Read Data) - The mouse responds with acknowledge (0xFA) then
sends a movement data packet. This is the only way to read data in
Remote Mode. After the data packets has been successfully sent, it
resets its movement counters.
<LI>0xEA (Set Stream Mode) - The mouse responds with "acknowledge" then
resets its movement counters and enters steram mode.
<LI>0xE9 (Status Request) - The mouse responds with "acknowledge" then
sends the following 3-byte status packet (then resets its movement
counters.):
<UL>
<LI>
<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>Always
0</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT
size=-1>Mode</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT
size=-1>Enable</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT
size=-1>Scaling</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Always
0</FONT></FONT></CENTER></TD>
<TD>
<CENTER><FONT face=Arial,Helvetica><FONT size=-1>Left
Btn</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></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>Resolution</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>Sample
Rate</FONT></FONT></CENTER></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<P><I>Right, Middle, Left Btn</I> = 1 if button pressed; 0 if button
is not pressed. <BR><I>Scaling</I> = 1 if scaling is 2:1; 0 if scaling
is 1:1. (See commands 0xE7 and 0xE6) <BR><I>Enable</I> = 1 if data
reporting is enabled; 0 if data reporting is disabled. (See commands
0xF5 and 0xF4) <BR><I>Mode</I> = 1 if Remote Mode is enabled; 0 if
Stream mode is enabled. (See commands 0xF0 and 0xEA)
<BR> </P></LI></UL>
<LI>0xE8 (Set Resolution) - The mouse responds with acknowledge (0xFA)
then reads one byte from the host and again responds with acknowledge
(0xFA) then resets its movement counters. The byte read from the
host determines the resolution as follows: <BR>
<CENTER>
<TABLE border=1 width=300>
<TBODY>
<TR>
<TD>
<CENTER>Byte Read from Host</CENTER></TD>
<TD>
<CENTER>Resolution</CENTER></TD></TR>
<TR>
<TD>
<CENTER>0x00</CENTER></TD>
<TD>
<CENTER>1 count/mm</CENTER></TD></TR>
<TR>
<TD>
<CENTER>0x01</CENTER></TD>
<TD>
<CENTER>2 count/mm</CENTER></TD></TR>
<TR>
<TD>
<CENTER>0x02</CENTER></TD>
<TD>
<CENTER>4 count/mm</CENTER></TD></TR>
<TR>
<TD>
<CENTER>0x03</CENTER></TD>
<TD>
<CENTER>8 count/mm</CENTER></TD></TR></TBODY></TABLE></CENTER></LI></UL>
<UL>
<LI>0xE7 (Set Scaling 2:1) - The mouse responds with acknowledge (0xFA)
then enables 2:1 scaling (discussed earlier in this document.)
<LI>0xE6 (Set Scaling 1:1) - The mouse responds with acknowledge (0xFA)
then enables 1:1 scaling (discussed earlier in this document.)
</LI></UL>The only commands the standard PS/2 mouse will send to the host
are the "Resend" (0xFE) and "Error" (0xFC) commands. They both work
the same as they do as host-to-device commands.
<P><B>Initialization:</B> </P>
<P>The PS/2 mouse is normally detected/initialized only when the computer
is booting up. That is, the mouse is not hot-pluggable and you must
restart your computer whenever you add/remove a PS/2 mouse (furthermore,
some motherboards may be damaged if you add/remove a PS/2 mouse while the
computer is running.) </P>
<P>The initial detection of the PS/2 mouse occurrs during POST. If a
mouse is detected, the BIOS will allow the operating system to
configure/enable the mouse. Otherwise, it will inhibit communication
on the mouse's bus. If you boot the computer with a mouse attached,
then detach/reattach the mouse while in Windows, the OS <I>may</I> be able
to detect the mouse was reattached. Microsoft tried to support this,
but it only works about 50% of the time. </P>
<P>The following is the communication between my computer (running
Win98SE) and mouse when it boots up with a standard PS/2 mouse
attached. It is fairly typical of how a PS/2 mouse is initialized
and if you want to emulate a PS/2 mouse it must (at minimum) be able to
support the following sequence of commands... </P>
<UL>
<LI><TT>Power-on Reset:</TT> <BR><TT>Mouse: AA Self-test
passed</TT> <BR><TT>Mouse: 00 Mouse ID</TT> <BR><TT>Host:
FF Reset command</TT> <BR><TT>Mouse: FA Acknowledge</TT>
<BR><TT>Mouse: AA Self-test passed</TT> <BR><TT>Mouse: 00
Mouse ID</TT> <BR><TT>Host: FF Reset command</TT>
<BR><TT>Mouse: FA Acknowledge</TT> <BR><TT>Mouse: AA
Self-test passed</TT> <BR><TT>Mouse: 00 Mouse ID</TT>
<BR><TT>Host: FF Reset command</TT> <BR><TT>Mouse: FA
Acknowledge</TT> <BR><TT>Mouse: AA Self-test passed</TT>
<BR><TT>Mouse: 00 Mouse ID</TT> <BR><TT>Host: F3 Set
Sample Rate : Attempt to Enter Microsoft</TT> <BR><TT>Mouse:
FA Acknowledge : Scrolling
Mouse mode</TT> <BR><TT>Host: C8 decimal
200 :</TT> <BR><TT>Mouse: FA
Acknowledge :</TT>
<BR><TT>Host: F3 Set Sample Rate :</TT>
<BR><TT>Mouse: FA Acknowledge
:</TT> <BR><TT>Host: 64 decimal
100 :</TT> <BR><TT>Mouse: FA
Acknowledge :</TT>
<BR><TT>Host: F3 Set Sample Rate :</TT>
<BR><TT>Mouse: FA Acknowledge
:</TT> <BR><TT>Host: 50 decimal
80 :</TT> <BR><TT>Mouse:
FA Acknowledge :</TT>
<BR><TT>Host: F2 Read Device Type :</TT>
<BR><TT>Mouse: FA Acknowledge
:</TT> <BR><TT>Mouse: 00 Mouse
ID : Response 03
if microsoft scrolling mouse</TT> <BR><TT>Host: F3 Set
Sample Rate </TT> <BR><TT>Mouse: FA Acknowledge</TT>
<BR><TT>Host: 0A decimal 10</TT> <BR><TT>Mouse: FA
Acknowledge</TT> <BR><TT>Host: F2 Read Device Type</TT>
<BR><TT>Mouse: FA Acknowledge</TT> <BR><TT>Mouse: 00 Mouse
ID</TT> <BR><TT>Host: E8 Set resolution</TT> <BR><TT>Mouse:
FA Acknowledge</TT> <BR><TT>Host: 03 8 Counts/mm</TT>
<BR><TT>Mouse: FA Acknowledge</TT> <BR><TT>Host: E6
Set Scaling 1:1</TT> <BR><TT>Mouse: FA Acknowledge</TT>
<BR><TT>Host: F3 Set Sample Rate</TT> <BR><TT>Mouse:
FA Acknowledge</TT> <BR><TT>Host: 28 decimal 40</TT>
<BR><TT>Mouse: FA Acknowledge</TT> <BR><TT>Host: F4
Enable</TT> <BR><TT>Mouse: FA Acknowledge</TT>
<BR><TT>Initialization complete...</TT>
<P><TT>If I then press the Left Button...</TT> <BR><TT>Mouse: 09 1 1
00001001; bit0 = Left button state; bit3 = always 1</TT> <BR><TT>Mouse:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -