OpenCores
URL https://opencores.org/ocsvn/socgen/socgen/trunk

Subversion Repositories socgen

[/] [socgen/] [trunk/] [Projects/] [opencores.org/] [logic/] [ip/] [ps2_interface/] [doc/] [ref/] [The_PS_2_Keyboard_Interface.html] - Blame information for rev 131

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 131 jt_eaton
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
2
<html><head>
3
 
4
 
5
 
6
 
7
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
8
 
9
  <meta name="GENERATOR" content="Mozilla/4.76 [en] (Win98; U) [Netscape]">
10
 
11
  <meta name="Author" content="Adam Chapweske">
12
  <title>The PS/2 Keyboard Interface</title>
13
                                     <!--This file created 10:20 PM  3/29/01 by Claris Home Page version 3.0-->
14
 
15
  <meta name="author" content="Adam Chapweske">
16
</head><body vlink="#3333ff" alink="#3333ff" bgcolor="#ffffff" link="#3333ff">
17
   <small><b><font face="Arial,Helvetica"><font size="+3"><small>The PS/2
18
Keyboard  Interface</small></font></font></b></small><br>
19
 
20
 
21
<center></center>
22
 
23
<center>
24
<hr size="1" width="400" align="left" noshade="noshade"></center>
25
                <br>
26
   <font face="Arial,Helvetica">Source: <a href="http://www.computer-engineering.org/">http://www.Computer-Engineering.org</a></font><br>
27
    <font face="Arial,Helvetica">Author: Adam Chapweske<br>
28
   Last Updated: 04/01/03<br>
29
 
30
   <br>
31
   </font><b>Legal Information:</b><br>
32
     <br>
33
     All information within this article is provided "as is" and without
34
any   express or implied warranties, including, without limitation, the implied
35
  warranties of merchantibility and fitness for a particular purpose. &nbsp;<br>
36
    <br>
37
    This article is protected under copyright law. &nbsp;This document may
38
 be  copied only if the source, author, date, and legal information is included.<br>
39
   <br>
40
 
41
   <b>Abstract:</b><br>
42
   <br>
43
   This article tries to cover every aspect of AT and PS/2 keyboards.&nbsp;
44
    It includes information on the low-level signals and protocol, scan codes,
45
    the command set, initialization, compatibility issues, and other miscellaneous
46
    information.&nbsp; Since it's closely related, I've also included information
47
    on the PC keyboard controller.&nbsp; All code samples involving the keyboard
48
  encoder are written in assembly for <a href="http://www.microchip.com/">Microchip's</a>
49
  PIC microcontrollers.&nbsp;   All code samples related to the keyboard
50
controller   are written in x86 assembly<br>
51
 
52
 
53
<p><b>A History Lesson:</b> </p>
54
 
55
<p>The most popular keyboards in use today include: </p>
56
 
57
<ul>
58
     <li> USB keyboard - Latest keyboard supported by all new computers (Macintosh
59
    and IBM/compatible).&nbsp; These are relatively complicated to interface
60
   and are not covered in this article.</li>
61
     <li> IBM/Compatible keyboards - Also known as "AT keyboards" or "PS/2
62
   keyboards",  all modern PCs support this device.&nbsp; They're the easiest
63
   to interface,  and are the subject of this article.</li>
64
 
65
     <li> ADB keyboards - Connect to the Apple Desktop Bus of older Macintosh
66
    systems.&nbsp; These are not covered in this article&nbsp;</li>
67
 
68
</ul>
69
         IBM introduced a new keyboard with each of its major desktop computer
70
   models.&nbsp;  The original IBM PC, and later the IBM XT, used what we
71
call   the "XT keyboard."&nbsp;  These are obsolete and differ significantly
72
from   modern keyboards; the XT  keyboard is not covered in this article.&nbsp;
73
  Next came the IBM AT system  and later the IBM PS/2.&nbsp; They introduced
74
  the keyboards we use today,  and are the topic of this article.&nbsp; AT
75
 keyboards and PS/2 keyboards were very similar devices, but the PS/2 device
76
 used a smaller connector and supported a few additional features.&nbsp;
77
 
78
Nonetheless,    it remained backward compatible with AT systems and few of
79
the additional    features ever caught on (since software also wanted to
80
remain backward compatible.)&nbsp;   Below is a summary of IBM's three major
81
keyboards.
82
<p>IBM PC/XT Keyboard (1981): </p>
83
 
84
<ul>
85
     <li> 83 keys</li>
86
     <li> 5-pin DIN connector</li>
87
     <li> Simple uni-directional serial protocol</li>
88
 
89
     <li> Uses what we now refer to as scan code set 1</li>
90
     <li> No host-to-keyboard commands</li>
91
 
92
</ul>
93
         IBM AT Keyboard (1984) - Not backward compatible with XT systems<tt><a href="#A%20History%20Lesson%20FN">(1)</a></tt>.
94
 
95
<ul>
96
     <li> 84 -101 keys</li>
97
 
98
     <li> 5-pin DIN connector</li>
99
     <li> Bi-directional serial protocol</li>
100
     <li> Uses what we now refer to as scan code set 2</li>
101
     <li> Eight host-to-keyboard commands</li>
102
 
103
 
104
</ul>
105
         IBM PS/2 Keyboard (1987) - Compatible with AT systems, not compatible
106
   with  XT systems<tt><a href="#A%20History%20Lesson%20FN">(1)</a></tt>.
107
 
108
<ul>
109
     <li> 84 - 101 keys</li>
110
     <li> 6-pin mini-DIN connector</li>
111
     <li> Bi-direction serial protocol</li>
112
 
113
     <li> Offers optional scan code set 3</li>
114
     <li> 17 host-to-keyboard commands&nbsp;</li>
115
 
116
</ul>
117
         The PS/2 keyboard was originally an extension of the AT device.&nbsp;
118
   It  supported a few additional host-to-keyboard commands and featured
119
a  smaller   connector.&nbsp; These were the only differences between the
120
two  devices.&nbsp;   However, computer hardware has never been about standards
121
 as much as compatibility.&nbsp;   For this reason, any keyboard you buy
122
today  will be <i>compatible</i> with   PS/2 and AT systems, but it may not
123
fully  support all the features of the   original devices.
124
 
125
 
126
<p>Today, "AT keyboard" and "PS/2 keyboard" refers only to their connector
127
    size.&nbsp; Which settings/commands any given keyboard does or does not
128
  support is anyone's guess.&nbsp; For example, the keyboard I'm using right
129
  now has a PS/2-style connector but only fully supports seven commands, partially
130
   supports two, and merely "acknowledges" the rest.&nbsp; In contrast, my
131
 "Test"  keyboard has an AT-style connector but supports every feature/command
132
  of the original PS/2 device (plus a few extra.)&nbsp; It's important you
133
 treat modern keyboards as compatible, not standard.&nbsp; If your design
134
a keyboard-related device that relies on non-general features, it may work
135
on some systems, but not on others...         </p>
136
 
137
<p>Modern PS/2 (AT) compatible keyboards </p>
138
 
139
<ul>
140
 
141
     <li> Any number of keys (usually 101 or 104)</li>
142
     <li> 5-pin or 6-pin connector; adaptor usually included</li>
143
     <li> Bi-directional serial protocol</li>
144
     <li> Only scan code set 2 guaranteed.</li>
145
     <li> Acknowledges all commands; may not act on all of them.</li>
146
 
147
 
148
</ul>
149
         <a name="A History Lesson FN"></a> <br>
150
              <i>Footnote 1) XT keyboards use a completely different protocol
151
  than   that used by AT and PS/2 systems, making it incompatible with the
152
 newer PCs.&nbsp; However, there was a transition period where some keyboard
153
 controllers supported both XT and AT (PS/2) keyboards (through a switch,
154
jumper, or auto-sense.)&nbsp;   Also, some keyboards were made to work on
155
both types of systems (again, through the use of a switch or auto-sensing.)&nbsp;
156
If you've owned such a PC or keyboard, don't let it fool you--XT keyboards
157
are NOT compatible with modern computers.</i>
158
 
159
<p><b>General Description:</b> </p>
160
 
161
 
162
<p>Keyboards consist of a large matrix of keys, all of which are monitored
163
    by an on-board processor (called the "keyboard encoder".)&nbsp; The specific
164
    processor<tt><a href="#General%20Description%20FN">(1)</a></tt> varies
165
 from   keyboard-to-keyboard but they all basically do the same thing:&nbsp;
166
 Monitor   which key(s) are being pressed/released and send the appropriate
167
 data to  the host.&nbsp; This processor takes care of all the debouncing
168
and buffers  any data in its 16-byte buffer, if needed.&nbsp; Your motherboard
169
 contains  a "keyboard controller"<tt><a href="#General%20Description%20FN">(2)</a></tt>   that is in charge of decoding
170
 all of the data received from the keyboard  and informing your software of
171
 what's going on.&nbsp; All communication between  the host and the keyboard
172
 uses an IBM protocol.&nbsp; <br>
173
 
174
              <a name="General Description FN"></a> <br>
175
              <i>Footnote 1)&nbsp; Originally, IBM used the Intel 8048 microcontroller
176
    as its keyboard encoder. &nbsp;There are now a wide variety of keyboard
177
   encoder chips available from many different manufacturers.</i> </p>
178
                                                <i>Footnote 2) Originally,
179
 IBM used the Intel 8042 microcontroller as  its  keyboard controller.&nbsp;
180
 This has since been replaces with compatible   devices integrated in motherboards'
181
 chipsets. The keyboard controller is  covered later in this article.</i>
182
 
183
<p><b>Electrical Interface / Protocol:</b> </p>
184
 
185
 
186
<p>The AT and PS/2 keyboards use the same protocol as the PS/2 mouse.&nbsp;
187
    Click <a href="http://www.computer-engineering.org/ps2protocol">here</a>   for detailed information on
188
 this protocol. </p>
189
 
190
<p><b>Scan Codes:</b> </p>
191
 
192
<p>Your keyboard's processor spends most of its time "scanning", or   monitoring,
193
 the matrix of keys.&nbsp; If it finds that any key is being pressed,  released,
194
 or held down, the keyboard will send a packet of information known  as a
195
"scan code" to your computer.&nbsp; There are two different types of  scan
196
codes: "make codes"<i> </i>and "break codes".&nbsp; A make code is sent  when
197
a key is pressed or held down.&nbsp; A break code is sent when  a key  is
198
released.&nbsp; Every key is assigned its own unique make code and break
199
code so the host can determine exactly what happened to which key by looking
200
 at a single scan code.&nbsp; The set of make and break codes for every key
201
 comprises a "scan code set".&nbsp; There are three standard scan code sets,
202
 named one, two, and three.&nbsp; All modern keyboards default  to set two.<tt><a href="#Scancodes%20FN">(1)</a></tt> </p>
203
 
204
 
205
<p>So how do you figure out what the scan codes are for each key?&nbsp;
206
  Unfortunately, there's no simple formula for calculating this.&nbsp; If
207
  you want to know what the make code or break code is for a specific key,
208
 you'll have to look it up in a table.&nbsp; I've composed tables for all
209
make codes and break codes in all three scan code sets: </p>
210
 
211
<ul>
212
     <li> <a href="http://www.computer-engineering.org/ps2keyboard/scancodes1.html">Scan   Code Set 1</a> - Original XT scan
213
  code set; supported by some modern keyboards</li>
214
 
215
     <li> <a href="http://www.computer-engineering.org/ps2keyboard/scancodes2.html">Scan   Code Set 2</a> - Default scan
216
code  set for all modern keyboards</li>
217
     <li> <a href="http://www.computer-engineering.org/ps2keyboard/scancodes3.html">Scan   Code Set 3</a> - Optional PS/2
218
scan  code set--rarely used</li>
219
 
220
</ul>
221
         <a name="Scancodes FN"></a> <br>
222
 
223
              <i>Footnote 1) Originally, the AT keyboard only supported set
224
 two,   and the PS/2 keyboard would default to set two but supported all three.&nbsp;
225
    Most modern keyboards behave like the PS/2 device, but I have come across
226
    a few that didn't support set one, set three, or both.&nbsp; Also, if
227
you've    ever done any low-level PC programming, you've probably notice
228
the keyboard    controller supplies set ONE scan codes by default.&nbsp; This
229
is because   the keyboard controller converts all incomming scan codes to
230
set one (this   stems from retaining compatibility with software written for
231
XT systems.)&nbsp;    However, it's still set two scan codes being sent down
232
the keyboard's serial    line.&nbsp;</i>
233
 
234
<p><b>Make Codes, Break Codes, and Typematic Repeat:</b> </p>
235
 
236
<p>Whenever a key is pressed, that key's make code is sent to the computer.&nbsp;
237
    Keep in mind that a make code only represents a <u>key</u> on a keyboard--it
238
    does not represent the character printed on that key.&nbsp; This means
239
 that  there is no defined relationship between a make code and an ASCII code.&nbsp;
240
 
241
   It's up to the host&nbsp; to translate scan codes to characters or commands.
242
          </p>
243
 
244
<p>Although most set two make codes are only one-byte wide, there are   a
245
 handfull of "extended keys" whose make codes are two or four bytes wide.&nbsp;
246
    These make codes can be identified by the fact that their first byte is
247
  E0h.&nbsp;        </p>
248
 
249
<p>Just as a make code is sent to the computer whenever a key is pressed,
250
    a break code is sent whenever a key is released.&nbsp; In addition to
251
every    key having its own unique make code, they all have their own unique
252
break    code<tt><a href="#MakeBreakTypematic%20FN">(1)</a></tt>.&nbsp; Fortunately,
253
    however, you won't always have to use lookup tables to figure out a key's
254
    break code--certain relationships do exist between make codes and break
255
  codes.&nbsp; Most set two break codes are two bytes long where the first
256
 byte is F0h and the second byte is the make code for that key.&nbsp; Break
257
 codes for extended keys are usually three bytes long where the first two
258
bytes are E0h, F0h, and the last byte is the last byte of that key's make
259
code.&nbsp; As an example, I have listed below a the set two make codes and
260
break codes for a few keys:&nbsp;        </p>
261
 
262
 
263
<blockquote>
264
  <blockquote>
265
 
266
    <blockquote>&nbsp;
267
 
268
      <table width="300" border="1" cols="3">
269
         <tbody>
270
                        <tr>
271
         <td>
272
 
273
 
274
            <center>Key</center>
275
         </td>
276
          <td>
277
 
278
 
279
            <center>(Set 2) <br>
280
 
281
        Make Code</center>
282
         </td>
283
          <td>
284
 
285
 
286
            <center>(Set 2) <br>
287
        Break Code</center>
288
         </td>
289
         </tr>
290
          <tr>
291
 
292
         <td>
293
 
294
 
295
            <center>"A"</center>
296
         </td>
297
          <td>
298
 
299
 
300
            <center>1C</center>
301
         </td>
302
          <td>
303
 
304
 
305
            <center>F0,1C</center>
306
         </td>
307
 
308
         </tr>
309
          <tr>
310
         <td>
311
 
312
 
313
            <center>"5"</center>
314
         </td>
315
          <td>
316
 
317
 
318
            <center>2E</center>
319
         </td>
320
          <td>
321
 
322
 
323
            <center>F0,2E</center>
324
 
325
         </td>
326
         </tr>
327
          <tr>
328
         <td>
329
 
330
 
331
            <center>"F10"</center>
332
         </td>
333
          <td>
334
 
335
 
336
            <center>09</center>
337
         </td>
338
 
339
          <td>
340
 
341
 
342
            <center>F0,09</center>
343
         </td>
344
         </tr>
345
          <tr>
346
         <td>
347
 
348
 
349
            <center>Right Arrow</center>
350
         </td>
351
          <td>
352
 
353
 
354
            <center>E0, 74</center>
355
 
356
         </td>
357
          <td>
358
 
359
 
360
            <center>E0, F0, 74</center>
361
         </td>
362
         </tr>
363
          <tr>
364
         <td>
365
 
366
 
367
            <center>Right "Ctrl"</center>
368
         </td>
369
 
370
          <td>
371
 
372
 
373
            <center>E0, 14</center>
374
         </td>
375
          <td>
376
 
377
 
378
            <center>E0, F0, 14</center>
379
         </td>
380
         </tr>
381
 
382
 
383
        </tbody>
384
 
385
      </table>
386
 
387
         </blockquote>
388
         </blockquote>
389
         Example:&nbsp; What sequence of make codes and break codes should
390
 be  sent   to your computer for the character "G" to appear in a word processor?&nbsp;
391
    Since this is an upper-case letter, the sequence of events that need to
392
  take place are: press the "Shift" key, press the "G" key, release the "G"
393
  key, release the "Shift" key.&nbsp; The scan codes associated with these
394
 events are the following:&nbsp; make code for the "Shift" key (12h), make
395
 code for the "G" key (34h), break code for the "G" key(F0h,34h), break code
396
 for the "Shift" key (F0h,12h).&nbsp; Therefore, the data sent to your computer
397
 would be: 12h, 34h, F0h, 34h, F0h, 12h.</blockquote>
398
 
399
         If you press a key, its make code is sent to the computer.&nbsp;
400
When   you  press and hold down a key, that key becomes <i>typematic</i>,
401
which  means  the keyboard will keep sending that key's make code until the
402
key is released  or another key is pressed.&nbsp; To verify this, open a text
403
editor and hold down the "A" key.&nbsp; When you first press the key, the
404
character "a" immediately appears on your screen.&nbsp; After a short delay,
405
another "a" will appear followed by a whole stream of "a"s until you release
406
the "A" key.&nbsp; There are two important parameters here:&nbsp; the <i>typematic
407
   delay</i>, which is the short delay between the first and second "a",
408
and    the <i>typematic rate</i>, which is how many characters per second
409
will  appear  on your screen after the typematic delay.&nbsp; The typematic
410
delay  can range  from 0.25 seconds to 1.00 second and the typematic rate
411
can range  from 2.0  cps (characters per second) to 30.0 cps.&nbsp; You may
412
change the  typematic  rate and delay using the "Set Typematic Rate/Delay"
413
(0xF3) command.
414
 
415
<p>Typematic data is not buffered within the keyboard.&nbsp; In the   case
416
 where more than one key is held down, only the last key pressed becomes
417
  typematic.&nbsp; Typematic repeat then stops when that key is released,
418
  even though other keys may be held down.  </p>
419
 
420
<p><a name="MakeBreakTypematic FN"></a> <br>
421
              <i>Footnote 1) Actually, the "Pause/Break" key does not have
422
 a  break   code in scan code sets one and two.&nbsp; When this key is pressed,
423
  its make code is sent; when it's released, it doesn't send anything. &nbsp;So
424
  how do you tell when this key has been released? &nbsp;You can't.</i> </p>
425
 
426
 
427
<p><b>Reset:</b> </p>
428
 
429
<p>At power-on or software reset (see the "Reset" command) the keyboard
430
  performs a diagnostic self-test referred to as BAT (Basic Assurance Test)
431
    and loads the following default values:&nbsp; </p>
432
 
433
<ul>
434
     <li> Typematic delay 500 ms.</li>
435
     <li> Typematic rate 10.9 cps.</li>
436
 
437
     <li> Scan code set 2.</li>
438
     <li> Set all keys typematic/make/break.</li>
439
 
440
</ul>
441
 
442
<p>When entering BAT, the keyboard enables its three LED indicators,   and
443
 turns them off when BAT has completed.&nbsp; At this time, a BAT completion
444
    code of either 0xAA (BAT successful) or 0xFC (Error) is sent to the host.
445
  &nbsp; This BAT completion code must be sent 500~750 milliseconds after
446
power-on.          </p>
447
 
448
 
449
<p>Many of the keyboards I've tested ignore their CLOCK and DATA lines   until
450
<i>after</i>  the BAT completion code has been sent.&nbsp; Therefore,   an
451
"Inhibit" condition  (CLOCK line low) may not prevent the keyboard from
452
 sending its BAT completion  code. </p>
453
 
454
<p><b>Command Set:</b> </p>
455
 
456
<p>A few notes regarding commands the host can issue to the keyboard:<br>
457
           </p>
458
 
459
 
460
<ul>
461
     <li>The keyboard clears its output buffer when it recieves any command.</li>
462
     <li>If the keyboard receives an invalid command or argument, it must
463
respond  with "resend" (0xFE).</li>
464
     <li>The keyboard must not send any scancodes while processing a command.</li>
465
     <li>If the keyboard is waiting for an argument byte and it instead
466
receives  a command, it should discard the previous command and process this
467
 new one.</li>
468
 
469
</ul>
470
     Below are all the commands the host may send to the keyboard:<br>
471
 
472
 
473
<ul>
474
     <li> 0xFF (Reset) - Keyboard responds with "ack" (0xFA), then enters
475
 "Reset"  mode.&nbsp; (See "Reset"  section.)</li>
476
     <li> 0xFE (Resend) - Keyboard responds by resending the last-sent byte.
477
   &nbsp;The exception to this is if the last-sent byte was "resend" (0xFE).
478
   &nbsp;If this is the case, the keyboard resends the last non-0xFE byte.
479
 &nbsp;This  command is used by the host to indicate an error in reception.</li>
480
 
481
</ul>
482
 
483
 
484
<blockquote>The next six commands can be issued when the keyboard is  in any
485
mode, but it only effects the behavior of the keyboard when in "mode  3"
486
(ie, set to scan code set 3.) <br>
487
             </blockquote>
488
 
489
<ul>
490
     <li> *0xFD (Set Key Type Make) - Disable break codes and typematic repeat
491
 for specified keys. &nbsp;Keyboard responds with "ack" (0xFA), then disables
492
 scanning (if enabled) and reads a list of keys from the host. &nbsp;These
493
  keys are specified by their set 3 make codes. &nbsp;Keyboard responds to
494
 each make code with "ack". &nbsp;Host terminates this list by sending an
495
invalid set 3 make code (eg, a valid command.) &nbsp;The keyboard then re-enables
496
  scanning (if previously disabled).</li>
497
     <li> *0xFC (Set Key Type Make/Break) - Similar to previous command,
498
 except  this one only disables typematic repeat.</li>
499
 
500
     <li> *0xFB (Set Key Type Typematic) - Similar to previous two, except
501
  this one only disables break codes.</li>
502
     <li> *0xFA (Set All Keys Typematic/Make/Break) - Keyboard responds with
503
 "ack" (0xFA). &nbsp;Sets all keys to their normal setting (generate scan
504
codes on make, break, and typematic repeat)</li>
505
     <li> *0xF9 (Set All Keys Make) - Keyboard responds with "ack" (0xFA).
506
  &nbsp;Similar to 0xFD, except applies to all keys.</li>
507
     <li> *0xF8 (Set All Keys Make/Break) - Keyboard responds with "ack"
508
 (0xFA).  &nbsp;Similar to 0xFC, except applies to all keys.</li>
509
 
510
     <li> *0xF7 (Set All Keys Typematic) - Keyboard responds with "ack" (0xFA).
511
  &nbsp;Similar to 0xFB, except applies to all keys.</li>
512
     <li> 0xF6 (Set Default) - Load default typematic rate/delay (10.9cps
513
 /  500ms), key types (all keys typematic/make/break), and scan code set (2).</li>
514
     <li> 0xF5 (Disable) - Keyboard stops scanning, loads default values
515
 (see   "Set Default" command), and waits further instructions.</li>
516
     <li> 0xF4 (Enable) - Re-enables keyboard after disabled using previous
517
   command.</li>
518
 
519
     <li> 0xF3 (Set Typematic Rate/Delay) - Host follows this command with
520
   one argument byte that defines the typematic rate and delay as follows:</li>
521
     <br>
522
        .
523
  <center><b>Repeat Rate</b></center>
524
 
525
  <center>
526
  <table width="90%" border="1" cellpadding="0" cellspacing="0">
527
         <tbody>
528
                    <tr>
529
 
530
         <td>
531
 
532
        <center>Bits 0-4</center>
533
         </td>
534
          <td>
535
 
536
        <center>Rate(cps)</center>
537
         </td>
538
          <td bgcolor="#cccccc">&nbsp;</td>
539
          <td>
540
 
541
        <center>Bits 0-4</center>
542
 
543
         </td>
544
          <td>
545
 
546
        <center>Rate(cps)</center>
547
         </td>
548
          <td bgcolor="#cccccc">&nbsp;</td>
549
          <td>
550
 
551
        <center>Bits 0-4</center>
552
         </td>
553
          <td>
554
 
555
        <center>Rate(cps)</center>
556
 
557
         </td>
558
          <td bgcolor="#cccccc">&nbsp;</td>
559
          <td>
560
 
561
        <center>Bits 0-4</center>
562
         </td>
563
          <td>
564
 
565
        <center>Rate(cps)</center>
566
         </td>
567
         </tr>
568
 
569
          <tr>
570
         <td>
571
 
572
        <center><tt>00h</tt></center>
573
         </td>
574
          <td>
575
 
576
        <center><tt>30.0</tt></center>
577
         </td>
578
          <td bgcolor="#cccccc">&nbsp;</td>
579
          <td>
580
 
581
        <center><tt>08h</tt></center>
582
 
583
         </td>
584
          <td>
585
 
586
        <center><tt>15.0</tt></center>
587
         </td>
588
          <td bgcolor="#cccccc">&nbsp;</td>
589
          <td>
590
 
591
        <center><tt>10h</tt></center>
592
         </td>
593
          <td>
594
 
595
        <center><tt>7.5</tt></center>
596
 
597
         </td>
598
          <td bgcolor="#cccccc">&nbsp;</td>
599
          <td>
600
 
601
        <center><tt>18h</tt></center>
602
         </td>
603
          <td>
604
 
605
        <center><tt>3.7</tt></center>
606
         </td>
607
         </tr>
608
 
609
          <tr>
610
         <td>
611
 
612
        <center><tt>01h</tt></center>
613
         </td>
614
          <td>
615
 
616
        <center><tt>26.7</tt></center>
617
         </td>
618
          <td bgcolor="#cccccc">&nbsp;</td>
619
          <td>
620
 
621
        <center><tt>09h</tt></center>
622
 
623
         </td>
624
          <td>
625
 
626
        <center><tt>13.3</tt></center>
627
         </td>
628
          <td bgcolor="#cccccc">&nbsp;</td>
629
          <td>
630
 
631
        <center><tt>11h</tt></center>
632
         </td>
633
          <td>
634
 
635
        <center><tt>6.7</tt></center>
636
 
637
         </td>
638
          <td bgcolor="#cccccc">&nbsp;</td>
639
          <td>
640
 
641
        <center><tt>19h</tt></center>
642
         </td>
643
          <td>
644
 
645
        <center><tt>3.3</tt></center>
646
         </td>
647
         </tr>
648
 
649
          <tr>
650
         <td>
651
 
652
        <center><tt>02h</tt></center>
653
         </td>
654
          <td>
655
 
656
        <center><tt>24.0</tt></center>
657
         </td>
658
          <td bgcolor="#cccccc">&nbsp;</td>
659
          <td>
660
 
661
        <center><tt>0Ah</tt></center>
662
 
663
         </td>
664
          <td>
665
 
666
        <center><tt>12.0</tt></center>
667
         </td>
668
          <td bgcolor="#cccccc">&nbsp;</td>
669
          <td>
670
 
671
        <center><tt>12h</tt></center>
672
         </td>
673
          <td>
674
 
675
        <center><tt>6.0</tt></center>
676
 
677
         </td>
678
          <td bgcolor="#cccccc">&nbsp;</td>
679
          <td>
680
 
681
        <center><tt>1Ah</tt></center>
682
         </td>
683
          <td>
684
 
685
        <center><tt>3.0</tt></center>
686
         </td>
687
         </tr>
688
 
689
          <tr>
690
         <td>
691
 
692
        <center><tt>03h</tt></center>
693
         </td>
694
          <td>
695
 
696
        <center><tt>21.8</tt></center>
697
         </td>
698
          <td bgcolor="#cccccc">&nbsp;</td>
699
          <td>
700
 
701
        <center><tt>0Bh</tt></center>
702
 
703
         </td>
704
          <td>
705
 
706
        <center><tt>10.9</tt></center>
707
         </td>
708
          <td bgcolor="#cccccc">&nbsp;</td>
709
          <td>
710
 
711
        <center><tt>13h</tt></center>
712
         </td>
713
          <td>
714
 
715
        <center><tt>5.5</tt></center>
716
 
717
         </td>
718
          <td bgcolor="#cccccc">&nbsp;</td>
719
          <td>
720
 
721
        <center><tt>1Bh</tt></center>
722
         </td>
723
          <td>
724
 
725
        <center><tt>2.7</tt></center>
726
         </td>
727
         </tr>
728
 
729
          <tr>
730
         <td>
731
 
732
        <center><tt>04h</tt></center>
733
         </td>
734
          <td>
735
 
736
        <center><tt>20.7</tt></center>
737
         </td>
738
          <td bgcolor="#cccccc">&nbsp;</td>
739
          <td>
740
 
741
        <center><tt>0Ch</tt></center>
742
 
743
         </td>
744
          <td>
745
 
746
        <center><tt>10.0</tt></center>
747
         </td>
748
          <td bgcolor="#cccccc">&nbsp;</td>
749
          <td>
750
 
751
        <center><tt>14h</tt></center>
752
         </td>
753
          <td>
754
 
755
        <center><tt>5.0</tt></center>
756
 
757
         </td>
758
          <td bgcolor="#cccccc">&nbsp;</td>
759
          <td>
760
 
761
        <center><tt>1Ch</tt></center>
762
         </td>
763
          <td align="center">
764
                      <font face="Courier New, Courier, monospace"><small>2.5</small></font><br>
765
                  </td>
766
         </tr>
767
 
768
          <tr>
769
         <td>
770
 
771
        <center><tt>05h</tt></center>
772
         </td>
773
          <td>
774
 
775
        <center><tt>18.5</tt></center>
776
         </td>
777
          <td bgcolor="#cccccc">&nbsp;</td>
778
          <td>
779
 
780
        <center><tt>0Dh</tt></center>
781
 
782
         </td>
783
          <td>
784
 
785
        <center><tt>9.2</tt></center>
786
         </td>
787
          <td bgcolor="#cccccc">&nbsp;</td>
788
          <td>
789
 
790
        <center><tt>15h</tt></center>
791
         </td>
792
          <td>
793
 
794
        <center><tt>4.6</tt></center>
795
 
796
         </td>
797
          <td bgcolor="#cccccc">&nbsp;</td>
798
          <td>
799
 
800
        <center><tt>1Dh</tt></center>
801
         </td>
802
          <td>
803
 
804
        <center><tt>2.3</tt></center>
805
         </td>
806
         </tr>
807
 
808
          <tr>
809
         <td>
810
 
811
        <center><tt>06h</tt></center>
812
         </td>
813
          <td>
814
 
815
        <center><tt>17.1</tt></center>
816
         </td>
817
          <td bgcolor="#cccccc">&nbsp;</td>
818
          <td>
819
 
820
        <center><tt>0Eh</tt></center>
821
 
822
         </td>
823
          <td>
824
 
825
        <center><tt>8.6</tt></center>
826
         </td>
827
          <td bgcolor="#cccccc">&nbsp;</td>
828
          <td>
829
 
830
        <center><tt>16h</tt></center>
831
         </td>
832
          <td>
833
 
834
        <center><tt>4.3</tt></center>
835
 
836
         </td>
837
          <td bgcolor="#cccccc">&nbsp;</td>
838
          <td>
839
 
840
        <center><tt>1Eh</tt></center>
841
         </td>
842
          <td>
843
 
844
        <center><tt>2.1</tt></center>
845
         </td>
846
         </tr>
847
 
848
          <tr>
849
         <td>
850
 
851
        <center><tt>07h</tt></center>
852
         </td>
853
          <td>
854
 
855
        <center><tt>16.0</tt></center>
856
         </td>
857
          <td bgcolor="#cccccc">&nbsp;</td>
858
          <td>
859
 
860
        <center><tt>0Fh</tt></center>
861
 
862
         </td>
863
          <td>
864
 
865
        <center><tt>8.0</tt></center>
866
         </td>
867
          <td bgcolor="#cccccc">&nbsp;</td>
868
          <td>
869
 
870
        <center><tt>17h</tt></center>
871
         </td>
872
          <td>
873
 
874
        <center><tt>4.0</tt></center>
875
 
876
         </td>
877
          <td bgcolor="#cccccc">&nbsp;</td>
878
          <td>
879
 
880
        <center><tt>1Fh</tt></center>
881
         </td>
882
          <td align="center">
883
                 <small><font face="Courier New, Courier, monospace">2.0</font></small><br>
884
                  </td>
885
         </tr>
886
 
887
 
888
 
889
    </tbody>
890
  </table>
891
 
892
  <div align="center">            </div>
893
            </center>
894
 
895
  <center>
896
  <p><b>Delay</b></p>
897
                </center>
898
 
899
  <center>
900
  <table width="217" border="1" cellpadding="0" cellspacing="0" cols="2">
901
 
902
         <tbody>
903
                    <tr>
904
         <td>
905
 
906
        <center>Bits 5-6</center>
907
         </td>
908
          <td>
909
 
910
        <center>Delay (seconds)</center>
911
         </td>
912
         </tr>
913
 
914
          <tr>
915
         <td>
916
 
917
        <center>00b</center>
918
         </td>
919
          <td>
920
 
921
        <center>0.25</center>
922
         </td>
923
         </tr>
924
          <tr>
925
 
926
         <td>
927
 
928
        <center>01b</center>
929
         </td>
930
          <td>
931
 
932
        <center>0.50</center>
933
         </td>
934
         </tr>
935
          <tr>
936
         <td>
937
 
938
        <center>10b</center>
939
 
940
         </td>
941
          <td>
942
 
943
        <center>0.75</center>
944
         </td>
945
         </tr>
946
          <tr>
947
         <td>
948
 
949
        <center>11b</center>
950
         </td>
951
 
952
          <td>
953
 
954
        <center>1.00</center>
955
         </td>
956
         </tr>
957
 
958
 
959
    </tbody>
960
  </table>
961
                </center>
962
     <br>
963
        &nbsp; <li> *0xF2 (Read ID) - The keyboard responds by sending a
964
two-byte     device ID of 0xAB, 0x83. (0xAB is sent first, followed by 0x83.)</li>
965
 
966
     <li> *0xF0 (Set Scan Code Set) -&nbsp; Keyboard responds with "ack",
967
 then reads argument byte from the host. &nbsp;This argument byte may be 0x01,
968
  0x02, or 0x03 to select scan code set 1, 2, or 3, respectively.&nbsp; The
969
  keyboard responds to this argument byte with "ack". &nbsp;If the argument
970
  byte is 0x00, the keyboard responds with "ack" followed by the current scan
971
  code set.</li>
972
     <li> 0xEE (Echo) - The keyboard responds with "Echo" (0xEE).</li>
973
     <li> 0xED (Set/Reset LEDs) - The host follows this command with one
974
 argument    byte, that specifies the state of the keyboard's Num Lock, Caps
975
 Lock, and   Scroll Lock LEDs.&nbsp; This argument byte is defined as follows:</li>
976
 
977
 
978
</ul>
979
 
980
<center>
981
<table width="400" border="0" cellpadding="3" cellspacing="0" cols="8">
982
         <tbody>
983
                  <tr valign="CENTER" align="center">
984
         <td>MSb</td>
985
          <td><br>
986
                    </td>
987
          <td><br>
988
 
989
                    </td>
990
          <td><br>
991
                    </td>
992
          <td><br>
993
                    </td>
994
          <td><br>
995
                    </td>
996
          <td><br>
997
                    </td>
998
 
999
          <td>LSb</td>
1000
         </tr>
1001
 
1002
  </tbody>
1003
</table>
1004
              </center>
1005
 
1006
<center>
1007
<table width="400" border="1" cellpadding="2" cellspacing="0" cols="8">
1008
         <tbody>
1009
                  <tr valign="CENTER" align="center">
1010
 
1011
         <td>Always 0</td>
1012
          <td>Always 0</td>
1013
          <td>Always 0</td>
1014
          <td>Always 0</td>
1015
          <td>Always 0</td>
1016
          <td>Caps Lock</td>
1017
 
1018
          <td>Num Lock</td>
1019
          <td>Scroll Lock</td>
1020
         </tr>
1021
 
1022
  </tbody>
1023
</table>
1024
              </center>
1025
 
1026
<blockquote>
1027
  <blockquote>
1028
 
1029
    <blockquote>
1030
 
1031
      <ul>
1032
 
1033
 
1034
        <ul>
1035
             <li> "Scroll Lock" - Scroll Lock LED off(0)/on(1)</li>
1036
             <li> "Num Lock" - Num Lock LED off(0)/on(1)</li>
1037
             <li> "Caps Lock" - Caps Lock LED off(0)/on(1)</li>
1038
 
1039
        </ul>
1040
 
1041
      </ul>
1042
 
1043
         </blockquote>
1044
         </blockquote>
1045
         </blockquote>
1046
         *Originally available in PS/2 keyboards only.
1047
 
1048
<p><b>Emulation:</b> </p>
1049
 
1050
<ul>
1051
        Click here   for keyboard/mouse routines.&nbsp; Source in MPASM for
1052
 PIC microcontrollers.
1053
 
1054
</ul>
1055
         <b>The i8042 Keyboard Controller:</b>
1056
 
1057
<p>Up to this point in the article, all information has been presented
1058
from a hardware point-of-view.&nbsp; However, if you're writing low-level
1059
    keyboard-related software for the host PC, you won't be communicating
1060
directly    with the keyboard.&nbsp; Instead, a keyboard controller provides
1061
an interface    between the keyboard and the peripheral bus.&nbsp; This controller
1062
takes   care of all the signal-level and protocol details, as well as providing
1063
 some  conversion, interpretation, and handling of scan codes and commands.&nbsp;
1064
         </p>
1065
 
1066
<p>An Intel 8042/compatible microcontroller is used as the PC's keyboard
1067
  controller.&nbsp; In modern computers, this microcontroller is hidden within
1068
   the motherboard's chipset, which integrates many controllers in a single
1069
  package.&nbsp; Nonetheless, this device is still there, and the keyboard
1070
 controller is still commonly referred to as "the 8042". </p>
1071
 
1072
 
1073
<p>Depending on the motherboard, the keyboard controller may operate   in
1074
 one of two modes: "AT-compatible" mode, or "PS/2-compatible" mode.&nbsp;
1075
   The latter is used if a PS/2 mouse is supported by the motherboard.&nbsp;
1076
    If this is the case, the 8042 acts as the keyboard controller and the
1077
mouse    controller.&nbsp; The keyboard controller auto-detects which mode
1078
it is  to use according to how it's wired to the keyboard port. </p>
1079
 
1080
<p>The 8042 contains the following registers: </p>
1081
 
1082
<ul>
1083
     <li> A one-byte input buffer - contains byte read from keyboard; read-only</li>
1084
 
1085
     <li> A one-byte output buffer - contains byte to-be-written to keyboard;
1086
    write-only</li>
1087
     <li> A one-byte status register - 8 status flags; read-only</li>
1088
     <li> A one-byte control register - 7 control flags; read/write&nbsp;</li>
1089
 
1090
</ul>
1091
         The first three registers (input, output, status) are directly accessible
1092
    via ports 0x60 and 0x64.&nbsp; The last register (control) is read using
1093
   the "Read Command Byte" command, and written using the "Write Command Byte"
1094
   command.&nbsp; The following table shows how the peripheral ports are
1095
used    to interface the 8042: <br>
1096
 
1097
        &nbsp;
1098
<center>
1099
<table border="1" cellpadding="3" cellspacing="0">
1100
         <tbody>
1101
                  <tr>
1102
         <td>
1103
 
1104
      <center>Port</center>
1105
         </td>
1106
          <td>
1107
 
1108
      <center>Read /&nbsp; <br>
1109
 
1110
        Write</center>
1111
         </td>
1112
          <td>
1113
 
1114
      <center>Function</center>
1115
         </td>
1116
         </tr>
1117
          <tr>
1118
         <td>0x60</td>
1119
 
1120
          <td>Read</td>
1121
          <td>Read Input Buffer</td>
1122
         </tr>
1123
          <tr>
1124
         <td>0x60</td>
1125
          <td>Write</td>
1126
          <td>Write Output Buffer</td>
1127
 
1128
         </tr>
1129
          <tr>
1130
         <td>0x64</td>
1131
          <td>Read</td>
1132
          <td>Read Status Register</td>
1133
         </tr>
1134
          <tr>
1135
 
1136
         <td>0x64</td>
1137
          <td>Write</td>
1138
          <td>Send Command</td>
1139
         </tr>
1140
 
1141
  </tbody>
1142
</table>
1143
              </center>
1144
 
1145
 
1146
<p>Writing to port 0x64 doesn't write to any specific register, but   sends
1147
 a command for the 8042 to interpret.&nbsp; If the command accepts a  parameter,
1148
 this parameter is sent to port 0x60.&nbsp; Likewise, any results   returned
1149
 by the command may be read from port 0x60. </p>
1150
 
1151
<p>When describing the 8042, I may occasionally refer to its physical   I/O
1152
 pins.&nbsp; These pins are defined below: </p>
1153
 
1154
<p><u>AT-compatible mode</u> </p>
1155
 
1156
<center>
1157
 
1158
<table border="0" cellpadding="5" cellspacing="0">
1159
         <tbody>
1160
                  <tr>
1161
         <td>Port 1 (Input Port):
1162
 
1163
      <center>
1164
 
1165
      <table border="1" cellpadding="2" cellspacing="0">
1166
         <tbody>
1167
                        <tr>
1168
         <td>Pin</td>
1169
          <td>Name</td>
1170
 
1171
          <td>Function</td>
1172
         </tr>
1173
          <tr>
1174
         <td>0</td>
1175
          <td>P10</td>
1176
          <td> <br>
1177
        Undefined <br>
1178
 
1179
        .</td>
1180
         </tr>
1181
          <tr>
1182
         <td>1</td>
1183
          <td>P11</td>
1184
          <td> <br>
1185
        Undefined <br>
1186
 
1187
        .</td>
1188
         </tr>
1189
          <tr>
1190
         <td>2</td>
1191
          <td>P12</td>
1192
          <td> <br>
1193
        Undefined <br>
1194
 
1195
        .</td>
1196
         </tr>
1197
          <tr>
1198
         <td>3</td>
1199
          <td>P13</td>
1200
          <td> <br>
1201
        Undefined <br>
1202
 
1203
        .</td>
1204
         </tr>
1205
          <tr>
1206
         <td>4</td>
1207
          <td>P14</td>
1208
          <td>External RAM <br>
1209
        1: Enable external RAM <br>
1210
 
1211
        0: Disable external RAM</td>
1212
         </tr>
1213
          <tr>
1214
         <td>5</td>
1215
          <td>P15</td>
1216
          <td>Manufacturing Setting <br>
1217
        1: Setting enabled <br>
1218
 
1219
        0: Setting disabled</td>
1220
         </tr>
1221
          <tr>
1222
         <td>6</td>
1223
          <td>P16</td>
1224
          <td>Display Type Switch <br>
1225
        1: Color display <br>
1226
 
1227
        0: Monochrome</td>
1228
         </tr>
1229
          <tr>
1230
         <td>7</td>
1231
          <td>P17</td>
1232
          <td>Keyboard Inhibit Switch <br>
1233
        1: Keyboard enabled <br>
1234
 
1235
        0: Keyboard inhibited</td>
1236
         </tr>
1237
 
1238
 
1239
        </tbody>
1240
 
1241
      </table>
1242
                    </center>
1243
         </td>
1244
          <td>Port 2 (Output Port):
1245
 
1246
      <table border="1" cellpadding="2" cellspacing="0">
1247
         <tbody>
1248
 
1249
                        <tr>
1250
         <td>Pin</td>
1251
          <td>Name</td>
1252
          <td>Function</td>
1253
         </tr>
1254
          <tr>
1255
         <td>0</td>
1256
 
1257
          <td>P20</td>
1258
          <td>System Reset <br>
1259
        1: Normal <br>
1260
        0: Reset computer</td>
1261
         </tr>
1262
          <tr>
1263
         <td>1</td>
1264
 
1265
          <td>P21</td>
1266
          <td> <br>
1267
        Gate A20 <br>
1268
        .</td>
1269
         </tr>
1270
          <tr>
1271
         <td>2</td>
1272
 
1273
          <td>P22</td>
1274
          <td> <br>
1275
        Undefined <br>
1276
        .</td>
1277
         </tr>
1278
          <tr>
1279
         <td>3</td>
1280
 
1281
          <td>P23</td>
1282
          <td> <br>
1283
        Undefined <br>
1284
        .</td>
1285
         </tr>
1286
          <tr>
1287
         <td>4</td>
1288
 
1289
          <td>P24</td>
1290
          <td> <br>
1291
        Input Buffer Full <br>
1292
        .</td>
1293
         </tr>
1294
          <tr>
1295
         <td>5</td>
1296
 
1297
          <td>P25</td>
1298
          <td> <br>
1299
        Output Buffer Empty <br>
1300
        .</td>
1301
         </tr>
1302
          <tr>
1303
         <td>6</td>
1304
 
1305
          <td>P26</td>
1306
          <td>Keyboard Clock <br>
1307
        1: Pull Clock low <br>
1308
        0: High-Z</td>
1309
         </tr>
1310
          <tr>
1311
         <td>7</td>
1312
 
1313
          <td>P27</td>
1314
          <td>Keyboard Data: <br>
1315
        1: Pull Data low <br>
1316
        0: High-Z</td>
1317
         </tr>
1318
 
1319
 
1320
        </tbody>
1321
 
1322
      </table>
1323
 
1324
         </td>
1325
          <td>Port 3 (Test Port):
1326
 
1327
      <center>
1328
 
1329
      <table border="1" cellpadding="2" cellspacing="0">
1330
         <tbody>
1331
                        <tr>
1332
         <td>Pin</td>
1333
          <td>Name</td>
1334
          <td>Function</td>
1335
 
1336
         </tr>
1337
          <tr>
1338
         <td>0</td>
1339
          <td>T0</td>
1340
          <td>Keyboard Clock&nbsp; <br>
1341
        (Input) <br>
1342
 
1343
        .</td>
1344
         </tr>
1345
          <tr>
1346
         <td>1</td>
1347
          <td>T1</td>
1348
          <td>Keyboard Data <br>
1349
        (Input) <br>
1350
 
1351
        .</td>
1352
         </tr>
1353
          <tr>
1354
         <td>2</td>
1355
          <td>--</td>
1356
          <td> <br>
1357
        Undefined <br>
1358
 
1359
        .</td>
1360
         </tr>
1361
          <tr>
1362
         <td>3</td>
1363
          <td>--</td>
1364
          <td> <br>
1365
        Undefined <br>
1366
 
1367
        .</td>
1368
         </tr>
1369
          <tr>
1370
         <td>4</td>
1371
          <td>--</td>
1372
          <td> <br>
1373
        Undefined <br>
1374
 
1375
        .</td>
1376
         </tr>
1377
          <tr>
1378
         <td>5</td>
1379
          <td>--</td>
1380
          <td> <br>
1381
        Undefined <br>
1382
 
1383
        .</td>
1384
         </tr>
1385
          <tr>
1386
         <td>6</td>
1387
          <td>--</td>
1388
          <td> <br>
1389
        Undefined <br>
1390
 
1391
        .</td>
1392
         </tr>
1393
          <tr>
1394
         <td>7</td>
1395
          <td>--</td>
1396
          <td> <br>
1397
        Undefined <br>
1398
 
1399
        .</td>
1400
         </tr>
1401
 
1402
 
1403
        </tbody>
1404
 
1405
      </table>
1406
                    </center>
1407
         </td>
1408
         </tr>
1409
 
1410
  </tbody>
1411
</table>
1412
 
1413
              </center>
1414
 
1415
<p><u>PS/2-compatible mode</u> </p>
1416
 
1417
<center>
1418
<table border="0" cellpadding="5" cellspacing="0">
1419
         <tbody>
1420
                  <tr>
1421
         <td>Port 1 (Input Port):
1422
 
1423
      <center>
1424
 
1425
      <table border="1" cellpadding="2" cellspacing="0">
1426
 
1427
         <tbody>
1428
                        <tr>
1429
         <td>Pin</td>
1430
          <td>Name</td>
1431
          <td>Function</td>
1432
         </tr>
1433
          <tr>
1434
 
1435
         <td>0</td>
1436
          <td>P10</td>
1437
          <td>Keyboard Data <br>
1438
        (Input) <br>
1439
        .</td>
1440
         </tr>
1441
 
1442
          <tr>
1443
         <td>1</td>
1444
          <td>P11</td>
1445
          <td>Mouse Data <br>
1446
        (Input) <br>
1447
        .</td>
1448
 
1449
         </tr>
1450
          <tr>
1451
         <td>2</td>
1452
          <td>P12</td>
1453
          <td> <br>
1454
        Undefined <br>
1455
        .</td>
1456
 
1457
         </tr>
1458
          <tr>
1459
         <td>3</td>
1460
          <td>P13</td>
1461
          <td> <br>
1462
        Undefined <br>
1463
        .</td>
1464
 
1465
         </tr>
1466
          <tr>
1467
         <td>4</td>
1468
          <td>P14</td>
1469
          <td>External RAM <br>
1470
        1: Enable external RAM <br>
1471
        0: Disable external RAM</td>
1472
 
1473
         </tr>
1474
          <tr>
1475
         <td>5</td>
1476
          <td>P15</td>
1477
          <td>Manufacturing Setting <br>
1478
        1: Setting enabled <br>
1479
        0: Setting disabled</td>
1480
 
1481
         </tr>
1482
          <tr>
1483
         <td>6</td>
1484
          <td>P16</td>
1485
          <td>Display Type Switch <br>
1486
        1: Color display <br>
1487
        0: Monochrome</td>
1488
 
1489
         </tr>
1490
          <tr>
1491
         <td>7</td>
1492
          <td>P17</td>
1493
          <td>Keyboard Inhibit Switch <br>
1494
        1: Keyboard enabled <br>
1495
        0: Keyboard disabled</td>
1496
 
1497
         </tr>
1498
 
1499
 
1500
        </tbody>
1501
 
1502
      </table>
1503
                    </center>
1504
         </td>
1505
          <td>Port 2 (Output Port):
1506
 
1507
      <center>
1508
 
1509
      <table border="1" cellpadding="2" cellspacing="0">
1510
         <tbody>
1511
                        <tr>
1512
 
1513
         <td>Pin</td>
1514
          <td>Name</td>
1515
          <td>Function</td>
1516
         </tr>
1517
          <tr>
1518
         <td>0</td>
1519
          <td>P20</td>
1520
 
1521
          <td>System Reset <br>
1522
        1: Normal <br>
1523
        0: Reset computer</td>
1524
         </tr>
1525
          <tr>
1526
         <td>1</td>
1527
          <td>P21</td>
1528
 
1529
          <td> <br>
1530
        Gate A20 <br>
1531
        .</td>
1532
         </tr>
1533
          <tr>
1534
         <td>2</td>
1535
          <td>P22</td>
1536
 
1537
          <td>Mouse Data: <br>
1538
        1: Pull Data low <br>
1539
        0: High-Z</td>
1540
         </tr>
1541
          <tr>
1542
         <td>3</td>
1543
          <td>P23</td>
1544
 
1545
          <td>Mouse Clock: <br>
1546
        1: Pull Clock low <br>
1547
        0: High-Z</td>
1548
         </tr>
1549
          <tr>
1550
         <td>4</td>
1551
          <td>P24</td>
1552
 
1553
          <td>Keyboard IBF interrupt: <br>
1554
        1: Assert IRQ 1 <br>
1555
        0: De-assert IRQ 1</td>
1556
         </tr>
1557
          <tr>
1558
         <td>5</td>
1559
          <td>P25</td>
1560
 
1561
          <td>Mouse IBF interrupt: <br>
1562
        1: Assert IRQ 12 <br>
1563
        0: De-assert IRQ 12</td>
1564
         </tr>
1565
          <tr>
1566
         <td>6</td>
1567
          <td>P26</td>
1568
 
1569
          <td>Keyboard Clock: <br>
1570
        1: Pull Clock low <br>
1571
        0: High-Z</td>
1572
         </tr>
1573
          <tr>
1574
         <td>7</td>
1575
          <td>P27</td>
1576
 
1577
          <td>Keyboard Data: <br>
1578
        1: Pull Data low <br>
1579
        0: High-Z</td>
1580
         </tr>
1581
 
1582
 
1583
        </tbody>
1584
 
1585
      </table>
1586
                    </center>
1587
         </td>
1588
 
1589
          <td>Port 3 (Test Port):
1590
 
1591
      <center>
1592
 
1593
      <table border="1" cellpadding="2" cellspacing="0">
1594
         <tbody>
1595
                        <tr>
1596
         <td>Pin</td>
1597
          <td>Name</td>
1598
          <td>Function</td>
1599
 
1600
         </tr>
1601
          <tr>
1602
         <td>0</td>
1603
          <td>T0</td>
1604
          <td>Keyboard Clock <br>
1605
        (Input) <br>
1606
        .</td>
1607
 
1608
         </tr>
1609
          <tr>
1610
         <td>1</td>
1611
          <td>T1</td>
1612
          <td>Mouse Clock <br>
1613
        (Input) <br>
1614
        .</td>
1615
 
1616
         </tr>
1617
          <tr>
1618
         <td>2</td>
1619
          <td>--</td>
1620
          <td> <br>
1621
        Undefined <br>
1622
        .</td>
1623
 
1624
         </tr>
1625
          <tr>
1626
         <td>3</td>
1627
          <td>--</td>
1628
          <td> <br>
1629
        Undefined <br>
1630
        .</td>
1631
 
1632
         </tr>
1633
          <tr>
1634
         <td>4</td>
1635
          <td>--</td>
1636
          <td> <br>
1637
        Undefined <br>
1638
        .</td>
1639
 
1640
         </tr>
1641
          <tr>
1642
         <td>5</td>
1643
          <td>--</td>
1644
          <td> <br>
1645
        Undefined <br>
1646
        .</td>
1647
 
1648
         </tr>
1649
          <tr>
1650
         <td>6</td>
1651
          <td>--</td>
1652
          <td> <br>
1653
        Undefined <br>
1654
        .</td>
1655
 
1656
         </tr>
1657
          <tr>
1658
         <td>7</td>
1659
          <td>--</td>
1660
          <td> <br>
1661
        Undefined <br>
1662
        .</td>
1663
 
1664
         </tr>
1665
 
1666
 
1667
        </tbody>
1668
 
1669
      </table>
1670
                    </center>
1671
         </td>
1672
         </tr>
1673
 
1674
  </tbody>
1675
</table>
1676
              </center>
1677
 
1678
 
1679
<p>(Note: Reading keyboard controller datasheets can be confusing--it   will
1680
 refer to the "input buffer" as the "output buffer" and vice versa.&nbsp;
1681
   This makes sense from the point-of-view of someone writing firmware for
1682
  the controller, but for somebody used to interfacing the controller, this
1683
  can cause problems.&nbsp; Throughout this document, I only refer to the
1684
"input   buffer" as the one containing input from the keyboard, and the "output
1685
  buffer"   as the one that contains output to be sent to the keyboard.)
1686
</p>
1687
 
1688
<p><i>Status Register:</i> </p>
1689
 
1690
<p>The 8042's status flags are read from port 0x64.&nbsp; They contain
1691
error information, status information, and indicate whether or not data
1692
is present in the input and output buffers.&nbsp; The flags are defined as
1693
 follows:        <br>
1694
 
1695
        &nbsp; </p>
1696
 
1697
<center>
1698
<table border="0" cellpadding="0" cellspacing="0">
1699
         <tbody>
1700
                  <tr>
1701
         <td><br>
1702
                    </td>
1703
          <td>
1704
 
1705
      <center>
1706
 
1707
      <table width="400" border="0" cellpadding="3" cellspacing="0" cols="8">
1708
 
1709
         <tbody>
1710
                        <tr>
1711
         <td>MSb</td>
1712
          <td><br>
1713
                          </td>
1714
          <td><br>
1715
                          </td>
1716
          <td><br>
1717
 
1718
                          </td>
1719
          <td><br>
1720
                          </td>
1721
          <td><br>
1722
                          </td>
1723
          <td><br>
1724
                          </td>
1725
          <td>
1726
 
1727
 
1728
            <div align="right">LSb</div>
1729
 
1730
         </td>
1731
         </tr>
1732
 
1733
 
1734
        </tbody>
1735
 
1736
      </table>
1737
                    </center>
1738
         </td>
1739
         </tr>
1740
          <tr>
1741
         <td>AT-compatible mode:</td>
1742
 
1743
          <td>
1744
 
1745
      <center>
1746
 
1747
      <table width="400" border="1" cellpadding="2" cellspacing="0" cols="8">
1748
         <tbody>
1749
                        <tr>
1750
         <td>
1751
 
1752
 
1753
            <center>PERR</center>
1754
         </td>
1755
          <td>
1756
 
1757
 
1758
            <center>RxTO</center>
1759
 
1760
         </td>
1761
          <td>
1762
 
1763
 
1764
            <center>TxTO</center>
1765
         </td>
1766
          <td>
1767
 
1768
 
1769
            <center>INH</center>
1770
         </td>
1771
          <td>
1772
 
1773
 
1774
            <center>A2</center>
1775
 
1776
         </td>
1777
          <td>
1778
 
1779
 
1780
            <center>SYS</center>
1781
         </td>
1782
          <td>
1783
 
1784
 
1785
            <center>IBF</center>
1786
         </td>
1787
          <td>
1788
 
1789
 
1790
            <center>OBF</center>
1791
 
1792
         </td>
1793
         </tr>
1794
 
1795
 
1796
        </tbody>
1797
 
1798
      </table>
1799
                    </center>
1800
         </td>
1801
         </tr>
1802
          <tr>
1803
         <td>PS/2-compatible mode:&nbsp;</td>
1804
 
1805
          <td>
1806
 
1807
      <center>
1808
 
1809
      <table width="400" border="1" cellpadding="2" cellspacing="0" cols="8">
1810
         <tbody>
1811
                        <tr>
1812
         <td>
1813
 
1814
 
1815
            <center>PERR</center>
1816
         </td>
1817
          <td>
1818
 
1819
 
1820
            <center>TO</center>
1821
 
1822
         </td>
1823
          <td>
1824
 
1825
 
1826
            <center>MOBF</center>
1827
         </td>
1828
          <td>
1829
 
1830
 
1831
            <center>INH</center>
1832
         </td>
1833
          <td>
1834
 
1835
 
1836
            <center>A2</center>
1837
 
1838
         </td>
1839
          <td>
1840
 
1841
 
1842
            <center>SYS</center>
1843
         </td>
1844
          <td>
1845
 
1846
 
1847
            <center>IBF</center>
1848
         </td>
1849
          <td>
1850
 
1851
 
1852
            <center>OBF</center>
1853
 
1854
         </td>
1855
         </tr>
1856
 
1857
 
1858
        </tbody>
1859
 
1860
      </table>
1861
                    </center>
1862
         </td>
1863
         </tr>
1864
 
1865
  </tbody>
1866
</table>
1867
              </center>
1868
 
1869
 
1870
<ul>
1871
     <li> OBF (Output Buffer Full) - Indicates when it's okay to write to
1872
 output   buffer.</li>
1873
     <br>
1874
        0: Output buffer empty - Okay to write to port 0x60 <br>
1875
        1: Output buffer full - Don't write to port 0x60 <li> IBF (Input
1876
Buffer    Full) - Indicates when input is available in the input buffer.</li>
1877
     <br>
1878
 
1879
        0: Input buffer empty - No unread input at port 0x60 <br>
1880
        1: Input buffer full - New input can be read from port 0x60 <li>
1881
SYS   (System   flag) - Post reads this to determine if power-on reset, or
1882
software   reset.</li>
1883
     <br>
1884
        0: Power-up value - System is in power-on reset. <br>
1885
        1: BAT code received - System has already beed initialized. <li>
1886
A2  (Address   line A2) - Used internally by the keyboard controller</li>
1887
 
1888
     <br>
1889
        0: A2 = 0 - Port 0x60 was last written to <br>
1890
        1: A2 = 1 - Port 0x64 was last written to <li> INH (Inhibit flag)
1891
-  Indicates   whether or not keyboard communication is inhibited.</li>
1892
     <br>
1893
        0: Keyboard Clock = 0 - Keyboard is inhibited <br>
1894
        1: Keyboard Clock = 1 - Keyboard is not inhibited <li> TxTO (Transmit
1895
  Timeout)  - Indicates keyboard isn't accepting input (kbd may not be plugged
1896
  in).</li>
1897
 
1898
     <br>
1899
        0: No Error - Keyboard accepted the last byte written to it. <br>
1900
        1: Timeout error - Keyboard didn't generate clock signals within
1901
15  ms  of  "request-to-send". <li> RxTO (Receive Timeout) - Indicates keyboard
1902
  didn't   respond to a command (kbd probably broke)</li>
1903
     <br>
1904
        0: No Error - Keyboard responded to last byte. <br>
1905
        1: Timeout error - Keyboard didn't generate clock signals within
1906
20  ms  of  command reception. <li> PERR (Parity Error) - Indicates communication
1907
   error  with keyboard (possibly noisy/loose connection)</li>
1908
 
1909
     <br>
1910
        0: No Error - Odd parity received and proper command response recieved.
1911
           <br>
1912
        1: Parity Error - Even parity received or 0xFE received as command
1913
 response.            <li> MOBF (Mouse Output Buffer Full) - Similar to OBF,
1914
 except for   PS/2 mouse.</li>
1915
     <br>
1916
        0: Output buffer empty - Okay to write to auxillary device's output
1917
 buffer            <br>
1918
        1: Output buffer full - Don't write to port auxillary device's output
1919
  buffer           <li> TO (General Timout) - Indicates timeout during command
1920
  write  or response. (Same as TxTO + RxTO.)</li>
1921
 
1922
     <br>
1923
        0: No Error - Keyboard received and responded to last command. <br>
1924
        1: Timeout Error - See TxTO and RxTO for more information.
1925
 
1926
</ul>
1927
         [EG: On my PC, the normal value of the 8042's "Status" register
1928
is  14h   = 00010100b.&nbsp; This indicates keyboard communication is not
1929
inhibited,    and the 8042 has already completed its self-test ("BAT").&nbsp;
1930
The "Status"    register is accessed by reading from port 64h ("IN AL, 64h")]
1931
 
1932
<p><i>Reading keyboard input:</i> </p>
1933
 
1934
 
1935
<p>When the 8042 recieves a valid scan code from the keyboard, it is   converted
1936
 to its set 1 equivalent.&nbsp; The converted scan code is then  placed in
1937
 the input buffer, the IBF (Input Buffer Full) flag is set, and IRQ 1 is asserted.&nbsp;
1938
 Furthermore, when any byte is received from the keyboard, the 8042 inhibits
1939
 further reception (by pulling the "Clock" line low), so no other scan codes
1940
 will be received until the input buffer is emptied.        </p>
1941
 
1942
<p>If enabled, IRQ 1 will activate the keyboard driver, pointed to by interrupt
1943
 vector 0x09.&nbsp; The driver reads the scan code from port 0x60, which causes
1944
 the 8042 to de-assert IRQ 1 and reset the IBF flag.&nbsp; The scan code
1945
is  then processed by the driver, which responds to special key combinations
1946
and updates an area of the system RAM reserved for keyboard input.       </p>
1947
 
1948
<p>If you don't want to patch into interrupt 0x09, you may poll the   keyboard
1949
 controller for input.&nbsp; This is accomplished by disabling the   8042's
1950
 IBF Interrupt and polling the IBF flag.&nbsp; This flag is set (1)   when
1951
 data is available in the input buffer, and is cleared (0) when data  is read
1952
 from the input buffer.&nbsp; Reading the input buffer is accomplished
1953
 by reading from port 0x60, and the IBF flag is at port 0x64, bit 1.&nbsp;
1954
   The following assembly code illustrates this: </p>
1955
 
1956
 
1957
<p><tt>kbRead:</tt> <br>
1958
              <tt>WaitLoop:&nbsp;&nbsp;&nbsp; in&nbsp;&nbsp;&nbsp;&nbsp;
1959
al,   64h&nbsp;&nbsp;&nbsp;&nbsp;   ; Read Status byte</tt> <br>
1960
              <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1961
    and&nbsp;&nbsp;&nbsp; al, 10b&nbsp;&nbsp;&nbsp;&nbsp; ; Test IBF flag
1962
(Status&lt;1&gt;)</tt>          <br>
1963
 
1964
              <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1965
    jz&nbsp;&nbsp;&nbsp;&nbsp; WaitLoop&nbsp;&nbsp;&nbsp; ; Wait for IBF =
1966
 1</tt>         <br>
1967
              <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1968
    in&nbsp;&nbsp;&nbsp;&nbsp; al, 60h&nbsp;&nbsp;&nbsp;&nbsp; ; Read input
1969
  buffer</tt>        </p>
1970
 
1971
 
1972
<p><i>Writing to keyboard:</i> </p>
1973
 
1974
<p>When you write to the 8042's output buffer (via port 0x60), the controller
1975
 sets the OBF ("Output Buffer Full") flag and processes the data.&nbsp;  The
1976
 8042 will send this data to the keyboard and wait for a response.&nbsp;
1977
If the keyboard does not accept or generate a response within a given amount
1978
    of time, the appropriate timeout flag will be set (see Status register
1979
 definition  for more info.)&nbsp; If an incorrect parity bit is read, the
1980
 8042 will send  the "Resend" (0xFE) command to the keyboard.&nbsp; If the
1981
 keyboard continues  to send erroneous bytes, the "Parity Error" flag is set
1982
 in the Status register.&nbsp;  If no errors occur, the response byte is
1983
placed  in the input buffer, the IBF ("Input Buffer Full") flag is set, and
1984
IRQ 1  is activated, signaling the keyboard driver. </p>
1985
 
1986
 
1987
<p>The following assembly code shows how to write to the output buffer.&nbsp;
1988
    (Remember, after you write to the output buffer, you should use int 9h
1989
 or  poll port 64h to get the keyboard's response.) </p>
1990
 
1991
<p><tt>kbWrite:</tt> <br>
1992
              <tt>WaitLoop:&nbsp;&nbsp;&nbsp; in&nbsp;&nbsp;&nbsp;&nbsp;
1993
al,   64h&nbsp;&nbsp;&nbsp;&nbsp;   ; Read Status byte</tt> <br>
1994
 
1995
              <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1996
    and&nbsp;&nbsp;&nbsp; al, 01b&nbsp;&nbsp;&nbsp;&nbsp; ; Test OBF flag
1997
(Status&lt;0&gt;)</tt>          <br>
1998
              <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1999
    jnz&nbsp;&nbsp;&nbsp; WaitLoop&nbsp;&nbsp;&nbsp; ; Wait for OBF = 0</tt>
2000
         <br>
2001
 
2002
              <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2003
    out&nbsp;&nbsp;&nbsp; 60h, cl&nbsp;&nbsp;&nbsp;&nbsp; ; Write data to
2004
output    buffer</tt> </p>
2005
 
2006
<p><i>Keyboard Controller Commands:</i> </p>
2007
 
2008
<p>Commands are sent to the keyboard controller by writing to port 0x64.&nbsp;
2009
 Command parameters are written to port 0x60 after teh command is sent.&nbsp;
2010
 Results are returned on port 0x60.&nbsp; Always test the OBF ("Output Buffer
2011
 Full") flag before writing commands or parameters to the 8042. </p>
2012
 
2013
 
2014
<ul>
2015
     <li> 0x20 (Read Command Byte) - Returns command byte.&nbsp; (See "Write
2016
    Command Byte" below).</li>
2017
     <li> 0x60 (Write Command Byte) - Stores parameter as command byte.&nbsp;
2018
    Command byte defined as follows:</li>
2019
 
2020
</ul>
2021
 
2022
 
2023
<center>
2024
<table border="0" cellpadding="0" cellspacing="0">
2025
         <tbody>
2026
                  <tr>
2027
         <td><br>
2028
                    </td>
2029
          <td>
2030
 
2031
      <center>
2032
 
2033
      <table width="400" border="0" cellpadding="3" cellspacing="0" cols="8">
2034
         <tbody>
2035
 
2036
                        <tr>
2037
         <td>MSb</td>
2038
          <td><br>
2039
                          </td>
2040
          <td><br>
2041
                          </td>
2042
          <td><br>
2043
                          </td>
2044
 
2045
          <td><br>
2046
                          </td>
2047
          <td><br>
2048
                          </td>
2049
          <td><br>
2050
                          </td>
2051
          <td>
2052
 
2053
 
2054
            <div align="right">LSb</div>
2055
         </td>
2056
 
2057
         </tr>
2058
 
2059
 
2060
        </tbody>
2061
 
2062
      </table>
2063
                    </center>
2064
         </td>
2065
         </tr>
2066
          <tr>
2067
         <td>AT-compatible mode:</td>
2068
          <td>
2069
 
2070
      <center>
2071
 
2072
      <table width="400" border="1" cellpadding="2" cellspacing="0" cols="8">
2073
 
2074
         <tbody>
2075
                        <tr>
2076
         <td>
2077
 
2078
 
2079
            <center>--</center>
2080
         </td>
2081
          <td>
2082
 
2083
 
2084
            <center>XLAT</center>
2085
         </td>
2086
          <td>
2087
 
2088
 
2089
            <center>PC</center>
2090
 
2091
         </td>
2092
          <td>
2093
 
2094
 
2095
            <center>_EN</center>
2096
         </td>
2097
          <td>
2098
 
2099
 
2100
            <center>OVR</center>
2101
         </td>
2102
          <td>
2103
 
2104
 
2105
            <center>SYS</center>
2106
 
2107
         </td>
2108
          <td>
2109
 
2110
 
2111
            <center>--</center>
2112
         </td>
2113
          <td>
2114
 
2115
 
2116
            <center>INT</center>
2117
         </td>
2118
         </tr>
2119
 
2120
 
2121
        </tbody>
2122
 
2123
      </table>
2124
 
2125
                    </center>
2126
         </td>
2127
         </tr>
2128
          <tr>
2129
         <td>PS/2-compatible mode:&nbsp;</td>
2130
          <td>
2131
 
2132
      <center>
2133
 
2134
      <table width="400" border="1" cellpadding="2" cellspacing="0" cols="8">
2135
         <tbody>
2136
 
2137
                        <tr>
2138
         <td>
2139
 
2140
 
2141
            <center>--</center>
2142
         </td>
2143
          <td>
2144
 
2145
 
2146
            <center>XLAT</center>
2147
         </td>
2148
          <td>
2149
 
2150
 
2151
            <center>_EN2</center>
2152
 
2153
         </td>
2154
          <td>
2155
 
2156
 
2157
            <center>_EN</center>
2158
         </td>
2159
          <td>
2160
 
2161
 
2162
            <center>--</center>
2163
         </td>
2164
          <td>
2165
 
2166
 
2167
            <center>SYS</center>
2168
 
2169
         </td>
2170
          <td>
2171
 
2172
 
2173
            <center>INT2</center>
2174
         </td>
2175
          <td>
2176
 
2177
 
2178
            <center>INT</center>
2179
         </td>
2180
         </tr>
2181
 
2182
 
2183
        </tbody>
2184
 
2185
      </table>
2186
 
2187
                    </center>
2188
         </td>
2189
         </tr>
2190
 
2191
  </tbody>
2192
</table>
2193
              </center>
2194
 
2195
<ul>
2196
 
2197
  <ul>
2198
       <li> INT (Input Buffer Full Interrupt) - When set, IRQ 1 is generated
2199
   when  data is available in the input buffer.</li>
2200
 
2201
       <br>
2202
        0: IBF Interrupt Disabled - You must poll STATUS&lt;IBF&gt; to read
2203
 input.              <br>
2204
        1: IBF Interrupt Enabled - Keyboard driver at software int 0x09 handles
2205
   input.            <li> SYS (System Flag) - Used to manually set/clear SYS
2206
   flag in Status register.</li>
2207
       <br>
2208
        0: Power-on value - Tells POST to perform power-on tests/initialization.
2209
             <br>
2210
 
2211
        1: BAT code received - Tells POST to perform "warm boot" tests/initiailization.
2212
              <li> OVR (Inhibit Override) - Overrides keyboard's "inhibit"
2213
 switch  on older motherboards.</li>
2214
       <br>
2215
        0: Inhibit switch enabled - Keyboard inhibited if pin P17 is high.
2216
     <br>
2217
        1: Inhibit switch disabled - Keyboard not inhibited even if P17 =
2218
high.              <li>  _EN (Disable keyboard) - Disables/enables keyboard
2219
interface.</li>
2220
       <br>
2221
 
2222
        0: Enable - Keyboard interface enabled. <br>
2223
        1: Disable - All keyboard communication is disabled. <li> PC ("PC
2224
Mode")    - ???Enables keyboard interface somehow???</li>
2225
       <br>
2226
        0: Disable - ??? <br>
2227
        1: Enable - ??? <li> XLAT (Translate Scan Codes) - Enables/disables
2228
 translation   to set 1 scan codes.</li>
2229
 
2230
       <br>
2231
        0: Translation disabled - Data appears at input buffer exactly as
2232
read   from  keyboard <br>
2233
        1: Translation enabled - Scan codes translated to set 1 before put
2234
 in  input  buffer <li> INT2 (Mouse Input Buffer Full Interrupt) - When set,
2235
 IRQ  12 is  generated when mouse data is available.</li>
2236
       <br>
2237
        0: Auxillary IBF Interrupt Disabled -&nbsp; <br>
2238
        1: Auxillary IBF Interrupt Enabled -&nbsp; <li> _EN2 (Disable Mouse)
2239
  -  Disables/enables  mouse interface.</li>
2240
 
2241
       <br>
2242
        0: Enable - Auxillary PS/2 device interface enabled <br>
2243
        1: Disable - Auxillary PS/2 device interface disabled
2244
 
2245
  </ul>
2246
 
2247
</ul>
2248
 
2249
<ul>
2250
     <li> ?0x90-0x9F (Write to output port) - Writes command's lower nibble
2251
   to lower nibble of output port (see Output Port definition.)</li>
2252
     <li> ?0xA1 (Get version number) - Returns firmware version number.</li>
2253
 
2254
     <li> ?0xA4 (Get password) - Returns 0xFA if password exists; otherwise,
2255
    0xF1.</li>
2256
     <li> ?0xA5 (Set password) - Set the new password by sending a null-terminated
2257
    string of scan codes as this command's parameter.</li>
2258
     <li> ?0xA6 (Check password) - Compares keyboard input with current password.</li>
2259
     <li> 0xA7 (Disable mouse interface) - PS/2 mode only.&nbsp; Similar
2260
 to   "Disable keyboard interface" (0xAD) command.</li>
2261
 
2262
     <li> 0xA8 (Enable mouse interface) - PS/2 mode only.&nbsp; Similar to
2263
  "Enable  keyboard interface" (0xAE) command.</li>
2264
     <li> 0xA9 (Mouse interface test) - Returns 0x00 if okay, 0x01 if Clock
2265
   line stuck low, 0x02 if clock line stuck high, 0x03 if data line stuck
2266
low,   and 0x04 if data line stuck high.</li>
2267
     <li> 0xAA (Controller self-test) - Returns 0x55 if okay.</li>
2268
     <li> 0xAB (Keyboard interface test) - Returns 0x00 if okay, 0x01 if
2269
 Clock   line stuck low, 0x02 if clock line stuck high, 0x03 if data line
2270
stuck  low,   and 0x04 if data line stuck high.</li>
2271
 
2272
     <li> 0xAD (Disable keyboard interface) - Sets bit 4 of command byte
2273
 and   disables all communication with keyboard.</li>
2274
     <li> 0xAE (Enable keyboard interface) - Clears bit 4 of command byte
2275
 and  re-enables communication with keyboard.</li>
2276
     <li> 0xAF (Get version)</li>
2277
     <li> 0xC0 (Read input port) - Returns values on input port (see Input
2278
   Port definition.)</li>
2279
     <li> 0xC1 (Copy input port LSn) - PS/2 mode only. Copy input port's
2280
 low   nibble to Status register (see Input Port definition)</li>
2281
 
2282
     <li> 0xC2 (Copy input port MSn) - PS/2 mode only. Copy input port's
2283
 high   nibble to Status register (see Input Port definition.)</li>
2284
     <li> 0xD0 (Read output port) - Returns values on output port (see Output
2285
    Port definition.)&nbsp;</li>
2286
     <li> 0xD1 (Write output port) - Write parameter to output port (see
2287
 Output   Port definition.)</li>
2288
     <li> 0xD2 (Write keyboard buffer) - Parameter written to input buffer
2289
   as if received from keyboard.</li>
2290
     <li> 0xD3 (Write mouse buffer) - Parameter written to input buffer as
2291
  if received from mouse.</li>
2292
 
2293
     <li> 0xD4 (Write mouse Device) - Sends parameter to the auxillary PS/2
2294
   device.</li>
2295
     <li> 0xE0 (Read test port) - Returns values on test port (see Test Port
2296
   definition.)</li>
2297
     <li> 0xF0-0xFF (Pulse output port) - Pulses command's lower nibble onto
2298
   lower nibble of output port (see Output Port definition.)</li>
2299
 
2300
</ul>
2301
 
2302
<p><br>
2303
              <i>Modern Keyboard Controllers:</i> </p>
2304
 
2305
 
2306
<p>So far, I've only discussed the 8042 keyboard controller.&nbsp; Although
2307
 modern keyboard controllers remain compatible with the original device, compatibility
2308
 is their only requirement (and their goal.) </p>
2309
 
2310
<p>My motherboard's keyboard controller is a great example of this.&nbsp;
2311
    I connected a microcontroller+LCD in parallel to my keyboard to see what
2312
   data is sent by the keyboard controller.&nbsp; At power-up, the keyboard
2313
  controller sent the "Set LED state" command to turn off all LEDs, then reads
2314
  the keyboard's ID.&nbsp; When I tried writing data to the output buffer,
2315
 I found the keyboard controller only forwards the "Set LED state" command
2316
 and "Set Typematic Rate/Delay" command.&nbsp; It does not allow any other
2317
 commands to be sent to the keyboard.&nbsp; However, it does emulate the
2318
keyboard's   response by placing "acknowledge" (0xFA) in the input buffer
2319
when appropriate   (or 0xEE in response to the "Echo" command.)&nbsp; Furthermore,
2320
if the keyboard   sends it an erroneous byte, the keyboard controller takes
2321
care of error handling  (sends the "Retry" command; if byte still erroneous;
2322
sends error code to keyboard and places error code in input buffer.) </p>
2323
 
2324
 
2325
<p>Once again, keep in mind chipset designers are more interested in   compatibility
2326
 than standardization.&nbsp; </p>
2327
 
2328
<p><b>Initialization:</b> </p>
2329
 
2330
<p>The following is the communication between my computer and keyboard
2331
when it boots-up.&nbsp; I beleive the first three commands were initiated
2332
    by the keyboad controller, the next command (which enables Num lock LED)
2333
   was sent by the BIOS, then the rest of the commands were sent my the OS
2334
 (Win98SE).&nbsp;  Remember, these results are specific to my computer, but
2335
 it should give you  a general idea as to what happens at startup. </p>
2336
 
2337
<blockquote><tt>Keyboard: AA&nbsp; Self-test passed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2338
    ;Keyboard controller init</tt> <br>
2339
 
2340
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; ED&nbsp; Set/Reset Status
2341
 Indicators&nbsp;</tt>            <br>
2342
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2343
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; 00&nbsp; Turn off all LEDs</tt>
2344
            <br>
2345
 
2346
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2347
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; F2&nbsp; Read ID</tt> <br>
2348
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2349
 
2350
                <tt>Keyboard: AB&nbsp; First byte of ID</tt> <br>
2351
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; ED&nbsp; Set/Reset Status
2352
 Indicators&nbsp;&nbsp;&nbsp;&nbsp;    ;BIOS init</tt> <br>
2353
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2354
 
2355
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; 02&nbsp; Turn on Num Lock
2356
 LED</tt>            <br>
2357
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2358
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; F3&nbsp; Set Typematic
2359
Rate/Delay&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     ;Windows init</tt>
2360
 
2361
  <br>
2362
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2363
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; 20&nbsp; 500 ms / 30.0
2364
reports/sec</tt>             <br>
2365
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2366
 
2367
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; F4&nbsp; Enable</tt> <br>
2368
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2369
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; F3&nbsp; Set Typematic
2370
Rate/delay</tt>             <br>
2371
 
2372
                <tt>Keyboard: FA&nbsp; Acknowledge</tt> <br>
2373
                <tt>Host:&nbsp;&nbsp;&nbsp;&nbsp; 00&nbsp; 250 ms / 30.0
2374
reports/sec</tt>             <br>
2375
                <tt>Keyboard: FA&nbsp; Acknowledge</tt></blockquote>
2376
 
2377
     <br>
2378
 <br>
2379
 
2380
</body></html>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.