Information Technology Reference
In-Depth Information
2 Program 10.2
/* This program may not work in Windows 95/98/NT/2000 */
/* as it tries to take direct control of the keyboard */
#include <stdio.h>
#include <conio.h>
int main(void)
{
unsigned int inval, hit=0;
char ch;
_outp(0x21,0x02); /* disable IRQ1 */
do
{
do
{
inval=_inp(0x64); /* read status register */
if ((inval & 0x01)==0x01) /* set for output buffer */
{
puts("Key pressed");
ch=_inp(0x60); /* read key from buffer */
printf("%c",ch);
hit=1;
}
} while (hit==0);
hit=0;
if (ch==0x1) break; /* wait for ESC key */
} while (1);
_outp(0x21,0); /* enable IRQ1 */
return(0);
}
10.4 Mouse and keyboard interface
Modern PCs typically use the 8242 device to provide for a PS/2 mouse and keyboard func-
tion, as illustrated in Figure 10.8. It can be seen that the two interrupts which are available
are IRQ1 (the keyboard interrupt) and IRQ12 (PS/2 style mouse). If the mouse connects to the
serial port then the IRQ12 line does not cause an interrupt. All clock frequencies are derived
from the keyboard clock frequency (see Figure 10.8). Notice that the interface for the PS/2-
style mouse is identical to the keyboard connection. They are interfaced through the same
registers (60h and 64h).
IRQ1
IRQ12
KBDCLK
Mouse
interface
KEYLOCK
MSDATA
MSCLK
+5V
GND
8242PCPL
DD[7:0]
IOR#
IOW#
MSCLK
MSDATA
KBDATA
KBCLK
K/B
interface
KBDATA
KBDCLK
+5V
GND
Figure 10.8
Mouse and keyboard interface
 
Search WWH ::




Custom Search