Documente Academic
Documente Profesional
Documente Cultură
Cs609@vu.edu.pk
Lecture # 22
Using the described information we can design a protocol for correctly writing on the
keyboard device as described below.
Keyboard is a typically an input device but some data can also be send to the keyboard
device. This data is used as some control information by the keyboard. One such
information is the typematic rate. This type matic rate can be conveyed to the keyboard as
described by the slide below.
Other such control information is the LED status. Every keyboard has three LEDs for
representing the status of Num Lock, Caps Lock and the Scroll Lock. If the device driver
needs to change the status then the LED status byte should be written on the keyboard as
described below. But before writing this byte the keyboard should be told that the control
byte is to be written. This is done by sending the code 0XED before sending the status
byte using the above described protocol.
Keyboard LEDs
LED Status byte
2 1 0
Scroll Lock
Num Lock
Caps Lock
#include <dos.h>
#include <conio.h>
char st [80];
int SendKbdRate(unsigned char data , int maxtry)
{
unsigned char ch;
do{
do{
ch=inport(0x64);
}while (ch&0x02);
outport(0x60,data);
do{
ch = inport(0x64);
}while (ch&0x01);
if (ch==0xfa)
{ puts("success\n");
break;
}
maxtry = maxtry - 1;
} while (maxtry != 0);
if (maxtry==0)
return 1;
else
return 0;
}
The above program has function SendKbdRate(). This function takes 2 parameters, first
one is value to be sent and the second one is the maximum number of retries it performs
if the byte cannot be sent. This function implements the described protocol. It first waits
for the IBF to be cleared and then starts trying to send the byte. The functions stops trying
either if 0xFA is received (success) or if the number of retries end (failure).
void main ()
{
//clrscr();
SendKbdRate(0xf3,3);
SendKbdRate(0x7f,3);
gets(st);
SendKbdRate(0xf3,3);
SendKbdRate(0,3);
gets(st);
}
Now this function is used to change the typematic rate. Firstly 0XF3 is written to indicate
that the typematic rate is to be changed then the typematic rate is set to 0x7F and a strng
can be type to experience the new typematic rate. Again this rate is set to 0. This program
will not work if you have booted the system in windows. First boot the system in DOS
and then run this program.
#include <bios.h>
#include <dos.h>
char st [80];
unsigned char far *kbd =
(unsigned char far *) 0x00400017;
int SendKbdRate(unsigned char data , int maxtry)
{
unsigned char ch;
do{
do{
ch=inport(0x64);
}while (ch&0x02);
outport(0x60,data);
do{
ch = inport(0x64);
}while (ch&0x01);
ch=inport(0x60);
if (ch==0xfa)
{ puts("success\n");
break;
}
maxtry = maxtry - 1;
} while (maxtry != 0);
if (maxtry==0)
return 1;
else
return 0;
}
void main ()
{
//clrscr();
SendKbdRate(0xed,3);
SendKbdRate(0x7,3);
puts("Enter a string ");
gets(st);
*kbd=(*kbd )|0x70;
puts("Enter a string ");
gets(st);
}
Again the same function is being used in this program to turn on the keyboard LEDs.
Firstly 0xED is sent to indicate the operation and then 7 is written to turn on all the
LEDs. But tuning on the LEDs like this will not change the keyboard status indicated by
the byte at 40:17H. If the status for the device driver usage is to changes as well then the
corresponding at 40:17H can be set by ORing it with 0x70. This program will not work if
you have booted the system in windows. First boot the system in DOS and then run this
program.
DMA Controller
DMA
DMA is a device which can acquire complete control of the buses and hence can be used
to transfer data directly from port to memory or vice versa. Transferring data like this can
prove faster because a transfer will consume 2 bus cycles if it is performed using the
processor. So in this approach the processor is bypasses and its cycles are stolen and are
used by the DMA controller.