You are here:

C/Steady keyboard LED oscillation

Advertisement


Question
I would like to work this program as follows
below with clean oscillating pulses.

The output is through the keyboard LEDs
(nums caps scroll).

The problem here is the computer seems to
interrupt and the output seen from the
LED is inconsistent.

I would like to get this up to perhaps 1khz
or better if that is possible.

How, Why and What is the operation?
What can I do to remedy this?
Is it possible?


#include <stdio.h>
#include <dos.h>
#include <conio.h>

int main(void)
{
clrscr();

poke(0x0000,0x0417,0);

while(!kbhit())
       {

        poke(0x0000,0x0417,16);
        gotoxy(1,1);
        cprintf("Num Lock LED is now on    r");

  delay(10);

        poke(0x0000,0x0417,0);
        gotoxy(1,1);
        cprintf("Num Lock LED is now oFF    r");

  delay(10);

  }

return 0;
}

Answer
Dear joseph!
 
 Of course you accessing the far memory location  , ( where the information of a keyboard is stored  , the matter of fact is poke is a function! so you know very well about the complexity in calling a function  , instead you can directly access the memory using a far pointer just like this

char far* ptr = ( char far*) 0x417;
/* The above pointer pointing the mem location 0x417 */

Let me revise the bit information !
BIT STATUS
0 : Right shift pressed
1 : Left Shift
2 : Ctrl pressed
3 : Alt key pressed
4 : scroll lock state
5 : num lock pressed
6 : Caps lock pressed
7 : Insert state
   
 just to change the value at the caps lock key ( no matter what the value it actually holds )

* ptr = * ptr | 64 ;
 The above statement just set the 6th bit ( to 1 ) which enables the caps lock LED to 1
( this operation is really fast you may not able to see the toggling of LED ) so by adjusting the necessary bits you can perform the given operation at a very high speed!

Thanks and regards !
Prince M. Premnath.  

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.