📄 at keyboard interfacing.htm
字号:
<TD>
<CENTER><TT>13.3</TT></CENTER></TD>
<TD bgColor=#cccccc> </TD>
<TD>
<CENTER><TT>1Eh</TT></CENTER></TD>
<TD>
<CENTER><TT>26.7</TT></CENTER></TD></TR>
<TR>
<TD>
<CENTER><TT>07h</TT></CENTER></TD>
<TD>
<CENTER><TT>3.7</TT></CENTER></TD>
<TD bgColor=#cccccc> </TD>
<TD>
<CENTER><TT>0Fh</TT></CENTER></TD>
<TD>
<CENTER><TT>7.5</TT></CENTER></TD>
<TD bgColor=#cccccc> </TD>
<TD>
<CENTER><TT>17h</TT></CENTER></TD>
<TD>
<CENTER><TT>15.0</TT></CENTER></TD>
<TD bgColor=#cccccc> </TD>
<TD>
<CENTER><TT>1Fh</TT></CENTER></TD>
<TD>
<CENTER><TT>30.0</TT></CENTER></TD></TR></TBODY></TABLE></CENTER>
<CENTER>
<P><B>Delay</B></P></CENTER>
<CENTER>
<TABLE border=1 cellPadding=0 cellSpacing=0 cols=2 width=217>
<TBODY>
<TR>
<TD>
<CENTER>Bits 5-6</CENTER></TD>
<TD>
<CENTER>Delay (seconds)</CENTER></TD></TR>
<TR>
<TD>
<CENTER>00b</CENTER></TD>
<TD>
<CENTER>0.25</CENTER></TD></TR>
<TR>
<TD>
<CENTER>01b</CENTER></TD>
<TD>
<CENTER>0.50</CENTER></TD></TR>
<TR>
<TD>
<CENTER>10b</CENTER></TD>
<TD>
<CENTER>0.75</CENTER></TD></TR>
<TR>
<TD>
<CENTER>11b</CENTER></TD>
<TD>
<CENTER>1.00</CENTER></TD></TR></TBODY></TABLE></CENTER><BR>
<LI>*0xF2 (Read ID) - The keyboard responds by sending a two-byte device
ID of 0xAB, 0x83. (0xAB is sent first, followed by 0x83.)
<LI>*0xF0 (Set Scan Code Set) - Keyboard responds with "ack", then
reads argument byte from the host. This argument byte may be 0x01,
0x02, or 0x03 to select scan code set 1, 2, or 3, respectively.
The keyboard responds to this argument byte with "ack". If the
argument byte is 0x00, the keyboard responds with "ack" followed by the
current scan code set.
<LI>0xEE (Echo) - The keyboard responds with "Echo" (0xEE).
<LI>0xED (Set/Reset LEDs) - The host follows this command with one
argument byte, that specifies the state of the keyboard's Num Lock, Caps
Lock, and Scroll Lock LEDs. This argument byte is defined as
follows: </LI></UL>
<CENTER>
<TABLE border=0 cellPadding=3 cellSpacing=0 cols=8 width=400>
<TBODY>
<TR align=middle vAlign=center>
<TD>MSb</TD>
<TD><BR></TD>
<TD><BR></TD>
<TD><BR></TD>
<TD><BR></TD>
<TD><BR></TD>
<TD><BR></TD>
<TD>LSb</TD></TR></TBODY></TABLE></CENTER>
<CENTER>
<TABLE border=1 cellPadding=2 cellSpacing=0 cols=8 width=400>
<TBODY>
<TR align=middle vAlign=center>
<TD>Always 0</TD>
<TD>Always 0</TD>
<TD>Always 0</TD>
<TD>Always 0</TD>
<TD>Always 0</TD>
<TD>Caps Lock</TD>
<TD>Num Lock</TD>
<TD>Scroll Lock</TD></TR></TBODY></TABLE></CENTER>
<BLOCKQUOTE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<UL>
<UL>
<LI>"Scroll Lock" - Scroll Lock LED off(0)/on(1)
<LI>"Num Lock" - Num Lock LED off(0)/on(1)
<LI>"Caps Lock" - Caps Lock LED off(0)/on(1)
</LI></UL></UL></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE>*Originally
available in PS/2 keyboards only.
<P><B>Emulation:</B> </P>
<UL>Click <A
href="http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/code/ps2/Device.html">here</A>
for keyboard/mouse routines. Source in MPASM for PIC
microcontrollers. </UL><B>The i8042 Keyboard Controller:</B>
<P>Up to this point in the article, all information has been presented
from a hardware point-of-view. However, if you're writing low-level
keyboard-related software for the host PC, you won't be communicating
directly with the keyboard. Instead, a keyboard controller provides
an interface between the keyboard and the peripheral bus. This
controller takes care of all the signal-level and protocol details, as
well as providing some conversion, interpretation, and handling of scan
codes and commands. </P>
<P>An Intel 8042/compatible microcontroller is used as the PC's keyboard
controller. In modern computers, this microcontroller is hidden
within the motherboard's chipset, which integrates many controllers in a
single package. Nonetheless, this device is still there, and the
keyboard controller is still commonly referred to as "the 8042". </P>
<P>Depending on the motherboard, the keyboard controller may operate in
one of two modes: "AT-compatible" mode, or "PS/2-compatible" mode.
The latter is used if a PS/2 mouse is supported by the motherboard.
If this is the case, the 8042 acts as the keyboard controller and the
mouse controller. The keyboard controller auto-detects which mode it
is to use according to how it's wired to the keyboard port. </P>
<P>The 8042 contains the following registers: </P>
<UL>
<LI>A one-byte input buffer - contains byte read from keyboard;
read-only
<LI>A one-byte output buffer - contains byte to-be-written to keyboard;
write-only
<LI>A one-byte status register - 8 status flags; read-only
<LI>A one-byte control register - 7 control flags; read/write
</LI></UL>The first three registers (input, output, status) are directly
accessible via ports 0x60 and 0x64. The last register (control) is
read using the "Read Command Byte" command, and written using the "Write
Command Byte" command. The following table shows how the peripheral
ports are used to interface the 8042: <BR>
<CENTER>
<TABLE border=1 cellPadding=3 cellSpacing=0>
<TBODY>
<TR>
<TD>
<CENTER>Port</CENTER></TD>
<TD>
<CENTER>Read / <BR>Write</CENTER></TD>
<TD>
<CENTER>Function</CENTER></TD></TR>
<TR>
<TD>0x60</TD>
<TD>Read</TD>
<TD>Read Input Buffer</TD></TR>
<TR>
<TD>0x60</TD>
<TD>Write</TD>
<TD>Write Output Buffer</TD></TR>
<TR>
<TD>0x64</TD>
<TD>Read</TD>
<TD>Read Status Register</TD></TR>
<TR>
<TD>0x64</TD>
<TD>Write</TD>
<TD>Send Command</TD></TR></TBODY></TABLE></CENTER>
<P>Writing to port 0x64 doesn't write to any specific register, but sends
a command for the 8042 to interpret. If the command accepts a
parameter, this parameter is sent to port 0x60. Likewise, any
results returned by the command may be read from port 0x60. </P>
<P>When describing the 8042, I may occasionally refer to its physical I/O
pins. These pins are defined below: </P>
<P><U>AT-compatible mode</U> </P>
<CENTER>
<TABLE border=0 cellPadding=5 cellSpacing=0>
<TBODY>
<TR>
<TD>Port 1 (Input Port):
<CENTER>
<TABLE border=1 cellPadding=2 cellSpacing=0>
<TBODY>
<TR>
<TD>Pin</TD>
<TD>Name</TD>
<TD>Function</TD></TR>
<TR>
<TD>0</TD>
<TD>P10</TD>
<TD><BR>Undefined <BR>.</TD></TR>
<TR>
<TD>1</TD>
<TD>P11</TD>
<TD><BR>Undefined <BR>.</TD></TR>
<TR>
<TD>2</TD>
<TD>P12</TD>
<TD><BR>Undefined <BR>.</TD></TR>
<TR>
<TD>3</TD>
<TD>P13</TD>
<TD><BR>Undefined <BR>.</TD></TR>
<TR>
<TD>4</TD>
<TD>P14</TD>
<TD>External RAM <BR>1: Enable external RAM <BR>0: Disable
external RAM</TD></TR>
<TR>
<TD>5</TD>
<TD>P15</TD>
<TD>Manufacturing Setting <BR>1: Setting enabled <BR>0:
Setting disabled</TD></TR>
<TR>
<TD>6</TD>
<TD>P16</TD>
<TD>Display Type Switch <BR>1: Color display <BR>0:
Monochrome</TD></TR>
<TR>
<TD>7</TD>
<TD>P17</TD>
<TD>Keyboard Inhibit Switch <BR>1: Keyboard enabled <BR>0:
Keyboard inhibited</TD></TR></TBODY></TABLE></CENTER></TD>
<TD>Port 2 (Output Port):
<TABLE border=1 cellPadding=2 cellSpacing=0>
<TBODY>
<TR>
<TD>Pin</TD>
<TD>Name</TD>
<TD>Function</TD></TR>
<TR>
<TD>0</TD>
<TD>P20</TD>
<TD>System Reset <BR>1: Normal <BR>0: Reset computer</TD></TR>
<TR>
<TD>1</TD>
<TD>P21</TD>
<TD><BR>Gate A20 <BR>.</TD></TR>
<TR>
<TD>2</TD>
<TD>P22</TD>
<TD><BR>Undefined <BR>.</TD></TR>
<TR>
<TD>3</TD>
<TD>P23</TD>
<TD><BR>Undefined <BR>.</TD></TR>
<TR>
<TD>4</TD>
<TD>P24</TD>
<TD><BR>Input Buffer Full <BR>.</TD></TR>
<TR>
<TD>5</TD>
<TD>P25</TD>
<TD><BR>Output Buffer Empty <BR>.</TD></TR>
<TR>
<TD>6</TD>
<TD>P26</TD>
<TD>Keyboard Clock <BR>1: Pull Clock low <BR>0: High-Z</TD></TR>
<TR>
<TD>7</TD>
<TD>P27</TD>
<TD>Keyboard Data: <BR>1: Pull Data low <BR>0:
High-Z</TD></TR></TBODY></TABLE></TD>
<TD>Port 3 (Test Port):
<CENTER>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -