Page 1 of 1

Problem with keyboard input routine

Posted: Sun Jul 17, 2005 4:40 pm
by Supermonkey
Heres the code for it:

Code: Select all

unsigned char kin(){
    unsigned char buf;
    rkey = 0;
    buf = "";
    while(rkey == 0){
        if(curkey > 0){
     buf = kbdus[curkey];
     puts("");
   }
    }
    return buf;
}
As you can see it should return the last charecter the user inputs.

buf is the buffer the charecter is stored in, kbdus is a list of charecter values, curkey is the current scancode value and rkey is 1 if the return key is pressed. But it just seems to return nothing, and I don't know why? Any ideas? its probably a really stupid mistake....

cheers

Jonny

Re:Problem with keyboard input routine

Posted: Sun Jul 17, 2005 5:41 pm
by AR
Why are you doing puts() and writing a NULL string? You can set "buf" to 0 rather than "" (although they should be the same thing).

What is "rkey"? If "rkey" is changed before "curkey" then it will return while "buf" is still NULL. If you are changing both values in the ISR then you have probably created a race condition where EIP is just after the If, "rkey" is changed then the ISR returns, the while checks "rkey" and leaves without the If executing.