⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ps-2 mouse interfacing.htm

📁 PS2 mouse very good info
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0045)http://www.computer-engineering.org/ps2mouse/ -->
<HTML><HEAD><TITLE>PS/2 Mouse Interfacing</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2180" 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 vLink=#3333ff aLink=#3333ff link=#3333ff bgColor=#ffffff><SMALL><B><FONT 
face=Arial,Helvetica><FONT size=+3><SMALL>The PS/2 Mouse 
Interface</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: 
04/01/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. &nbsp;<BR><BR>This article 
is protected under copyright law. &nbsp;This document may be copied only if the 
source, author, date, and legal information is 
included.<BR><BR><B>Abstract:</B><BR><BR>This article attempts to explain every 
aspect of the PS/2 mouse interface including the physical and electrical 
interface, low-level protocol, modes of operation, commands, and extensions. 
&nbsp;All code samples involving the mouse encoder are written in assembly for 
<A href="http://www.microchip.com/">Microchip's</A> PIC microcontrollers.&nbsp; 
All code samples related to the auxiliary device controller (keyboard 
controller) are written in x86 assembly<BR><BR><B>General 
Description:</B><BR><BR>There are many types of pointing devices available for 
modern PCs, including mice, trackballs, touchpads, electronic whiteboards, etc. 
&nbsp;Virtually all of these pointing devices communicate with a computer using 
one of two interfaces: Universal Serial Bus (USB) or the PS/2 Mouse Interface. 
&nbsp;See the following table for a comparison:<BR>
<BLOCKQUOTE>
  <TABLE cellSpacing=0 cellPadding=2 width=500 border=1>
    <TBODY>
    <TR>
      <TD vAlign=top align=middle width="33%"><BR></TD>
      <TD vAlign=top align=middle width="33%"><B>USB (v1.1)</B><BR></TD>
      <TD vAlign=top align=middle><B>&nbsp;PS/2 Mouse Interface </B><BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle width="33%">Number of Devices 
      Supported<BR></TD>
      <TD vAlign=top align=middle width="33%">Up to 127<BR></TD>
      <TD vAlign=top align=middle>One<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle width="33%">Maximum Data Rate<BR></TD>
      <TD vAlign=top align=middle width="33%">12 Mbps<BR></TD>
      <TD vAlign=top align=middle>40 kbps<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle width="33%">Power (max)<BR></TD>
      <TD vAlign=top align=middle width="33%">5V @ 500mA<BR></TD>
      <TD vAlign=top align=middle>5V @ 100mA<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle width="33%">Hot-Pluggable?<BR></TD>
      <TD vAlign=top align=middle width="33%">Yes<BR></TD>
      <TD vAlign=top align=middle>No<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle width="33%">Documentation<BR></TD>
      <TD vAlign=top align=middle width="33%">Well-documented: <A 
        href="http://www.usb.org/">http://www.usb.org/</A><BR></TD>
      <TD vAlign=top align=middle>Out-of-print <BR>(IBM Tech 
    Reference)<BR></TD></TR></TBODY></TABLE><BR></BLOCKQUOTE>Older pointing device 
interfaces include the Apple Desktop Bus (ADB), RS-232 serial port, and the bus 
mouse interface. &nbsp;These are obsolete and are not covered in this 
article.<BR><BR>The PS/2 mouse interface originally appeared in IBM's "Personal 
System/2" computers in the late 80's. &nbsp;It still remains a widely-supported 
interface for the sake of constantly maintaining backward compatibility. 
&nbsp;However, USB has quickly caught on these last few years and will 
eventually replace the PS/2 mouse interface entirely.<BR><BR>The PS/2 mouse 
interface uses a bidirectional serial protocol to transmit movement and 
button-position data to the computer's auxiliary device controller (keyboard 
controller). &nbsp;The computer, in turn, may send a number of commands to the 
mouse to set the report rate, resolution, reset the mouse, disable the mouse, 
etc. &nbsp;The computer also provides the mouse with an overload-protected 5V 
power supply.<BR>
<P><B>Electrical Interface / Protocol:</B> </P>
<P>The PS/2 mouse uses the same protocol as the PS/2 keyboard (aka AT 
keyboard).&nbsp; Click <A 
href="http://www.computer-engineering.org/ps2protocol">here</A> for detailed 
information on this protocol. </P>
<P><B>Inputs, Resolution, and Scaling:</B> </P>
<P>The standard PS/2 mouse interface 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.&nbsp; There 
are many PS/2 pointing devices that have additional inputs and may report data 
differently than described in this document.&nbsp; 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.&nbsp; These&nbsp; are 9-bit 2's 
complement values and each has an associated overflow flag.&nbsp; 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.)&nbsp; The movement counters represent the amount of movement that has 
occurred since the last movment data packet was sent to the host (ie, they do 
not represent absolute positions.) </P>
<P>When the mouse reads its inputs, it records the current state of its buttons 
and 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://www.computer-engineering.org/ps2mouse/#Footnotes">(1)</A> value of 
these counters.&nbsp; This parameter is <I>scaling</I>.&nbsp; By default, the 
mouse uses 1:1 scaling, which has no effect on the reported mouse 
movement.&nbsp; However, the host may select 2:1 scaling by sending the "Set 
Scaling 2:1" (0xE7) command.&nbsp; If 2:1 scaling is enabled, the mouse will 
apply the following algorithm to the counters before sending their contents to 
the host: <BR></P>
<BLOCKQUOTE>
  <TABLE cellSpacing=0 cellPadding=2 width=300 border=1>
    <TBODY>
    <TR>
      <TD vAlign=top align=middle>Movement Counter<BR></TD>
      <TD vAlign=top align=middle>Reported Movement<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle>0<BR></TD>
      <TD vAlign=top align=middle>0<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle>1<BR></TD>
      <TD vAlign=top align=middle>1<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle>2<BR></TD>
      <TD vAlign=top align=middle>1<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle>3<BR></TD>
      <TD vAlign=top align=middle>3<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle>4<BR></TD>
      <TD vAlign=top align=middle>6<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle>5<BR></TD>
      <TD vAlign=top align=middle>9<BR></TD></TR>
    <TR>
      <TD vAlign=top align=middle>N &gt; 5<BR></TD>
      <TD vAlign=top align=middle>2 * N<BR></TD></TR></TBODY></TABLE></BLOCKQUOTE>
<CENTER>
<DIV align=center></DIV></CENTER>
<CENTER></CENTER>
<CENTER>
<DIV align=center></DIV></CENTER>
<P><B><BR>Movement Data Packet:</B> </P>
<P>The standard PS/2 mouse sends movement/button information to the host using 
the following 3-byte packet <A 
href="http://www.computer-engineering.org/ps2mouse/#Footnotes">(4)</A>:&nbsp; 
</P>
<BLOCKQUOTE>
  <TABLE cellSpacing=0 cellPadding=0 width=650 border=0>
    <TBODY>
    <TR>
      <TD><BR><FONT face=Arial,Helvetica><FONT size=-1>Byte 
        1&nbsp;</FONT></FONT></TD>
      <TD>
        <TABLE cols=8 cellPadding=0 width="100%" border=0>
          <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 cellSpacing=0 cols=8 cellPadding=0 width="100%" border=1>
          <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 cellSpacing=0 cols=1 cellPadding=0 width="100%" border=1>
          <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&nbsp;</FONT></FONT></TD>
      <TD>
        <TABLE cellSpacing=0 cols=1 cellPadding=0 width="100%" border=1>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -