Ali - Re: " Show us you command of computer, tell how your keyboard works. "
The keyboard is implemented using a two dimensional array of Key switches These are SPST contact switches which are arranged in n-rows by m-columns.
The array is scanned by a controller chip (8048/8042 or custom) to detect if a key is pressed or, if previously pressed, released. This is done by driving the n-row lines high, sequentially (one by one) while each of the m columns is sensed sequentially for each row-scan. These drive/sense lines are generally implemented by the I/O ports on the Keyboard microcontroller.
If a key press/release is detected, a scan-code is sent to the computer. This is done by the 5-wire keyboard connector - Power, ground, Keyboard Clock, Keyboard Data, and RESET. These are contained in the plug (usually DIN-type) that goes into the back of your PC. Some buffering may be done in the keyboard (local storage), if the CPU doesn't respond promptly.
Note - the SCAN CODE is a CODE representing the key that is pressed and IS NOT itself the logical representation of that key - the SCAN CODE is a number from 1 to 102 (assuming a 102 key keyboard), where each number repreesnts one of the 102 physical keys). The Scan Code is generated by the Keyboard Controller device, generally from a look-up table contained in ROM/EPROM on the microcontroller.
The Keyboard Clock/Keyboard Data lines are fed into some logic circuitry in the chip set that, when Data is present (signifying a Key has been pressesd or released), generate a signal which is sent to the Interrupt controller on the chip set (it used to be Interrupt 1).
This Hardware Interrupt causes the main processor (CPU) to stop (after completing its current instruction) and branch to a software routine in the BIOS chip (software Interrupt 16Hex). This routine, the Keyboard Routine, is then executed by the main CPU.
The software routine begins to read the data from the keyboard (Keyboard Data Line) which is physically routed from the keyboard connector into an I/O port on the chip set. This I/O port is read by the CPU as part of the Keyboard BIOS routine, using standard hardware I/O read operations.
For reference, Ali - BIOS means Basic Input Outout System/Software
The data comes in serially, clocked into the I/O port by the Keyboard Clock line. The CPU reads each bit, then stores it in an internal register until 16 bits are read - two bytes. These two bytes contain the scan code of the key that was pressed and the status of the auxiliary keys - "CTRL", "ALT", etc.
The Keyboard BIOS routine uses the Scan Code read in from the I/O port to "get" the value of the key that was depressed. This is done be using the Scan Code as an index into an array in the BIOS which contains the logical chracter represented by the Scan Code and the Special keys. For example, if physical key #20 is pressed, the scan code 20 is sent to the computer and read by the BIOS. The BIOS Keyboard routine, using a look-up table stored in the BIOS itself, translates that 20 into the logical key being pressed, for example, the letter "t", assuming that the "SHIFT " key was not pressed. If the SCAN CODE for the Shift Key was also sent (obviously indicating one of the SHIFT keys was depressed), AND a SCAN CODE of 20 is read next, then the BIOS routine returns an upper case "T".
The Key value returned by the BIOS routine is stored in the AEX register (Actually one byte of this register, the AL sub-register) IF the key represnts a standard ASCII value (0,1...9, a...z, A...Z).
IF a non-ASCII value is read (for example "ALT U"), the AL register is set to ZERO and the AH register (also part of the AEX register) is filled with the special Key-COde combination representing ALT U, in this example.
Application programs receive their keyboard input by simply reading the value in the AL (or AL & AH) registers following a Keyboard-generated Interrupt.
That's basically how the Keyboard Works - the actual BIOS code is quite involved in detecting the special key combinations, etc.
I hope this helps you better understand the functioning of a PC's keyboard. I assume you are taking a beginning class in PCs and need this information to help pass a homework problem or exam. Since you like to copy things from technical people, go right ahead and copy this for your homework or exam - I understand!
Paul |