Information Technology Reference
In-Depth Information
start=(start1 &0xff)+((start2 &0xff)<<8);
end=(end1 & 0xff)+((end2 & 0xff)<<8);
if (start>end)
printf("Value = %u\n",start-end);
else /* roll-over has occurred */
printf("Value = %u\n",start+(0xffff-end));
} while (!kbhit()) ;
return(0);
}
Program 10.1 uses Counter 0 which is loaded from address 40h. It has a 16-bit counter regis-
ter and has a 1.2 MHz clock as its input. It thus rolls-over every 55 ms.
In a sample test run of the above program the output value varied from 62 to 2740, with a
static value of 1400. The joystick could be easily calibrated with these values, which are the
extremes for either x or y . Note that AY is tested with:
do
{
inval=_inp(0x201); /* read button status of joystick */
} while ((inval & 2)==1); /* wait till set to a 0 */
and BX is tested with:
do
{
inval=_inp(0x201); /* read button status of joystick */
} while ((inval & 4)==1); /* wait till set to a 0 */
10.3 Keyboard
Figure 10.5 shows the main connections in the keyboard interface. It uses a 5-pin DIN socket
for the connection. The data is sent from the keyboard to the PC in an 11-bit SDU (serial data
unit) format over the KBD Data line. When a key has been pressed the IRQ1 interrupt line is
activated. The keyboard interface IC scans the keys on the keyboard by activating the X-
decoder lines and then sensing the Y-decoder lines to see if there has been a keypress. It then
decodes this to sense if a key has changed its state. It then converts the keypress or release to
a code which it sends to the keyboard controller on the PC. The format of the code is in the
form of an RS-232 interface with eight data bits, one parity bit, one start bit and one stop bit.
Unlike RS-232, it uses a synchronous transfer where the clock speed is defined by the KDB
clock line.
It is very unlikely that a programmer would ever need to interface directly with the key-
board, as there are a whole host of standard functions that are well tested and interface well
with the operating system. It is always advisable to use the standard input keyboard func-
tions, over direct interfacing. Typically the operating system takes over control of all input
key presses and sends these to the required process, thus it is not a good idea to interrupt the
flow.
Search WWH ::




Custom Search