Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

PS/2 Keyboard with C

Altera_Forum
Honored Contributor II
997 Views

Hello, 

 

i am trying to make a PS/2 Keyboard work with my FPGA and C language. 

 

I tried to capture sequences from the keyboard by using the following code : 

 

while(1) { while(1) { if(*ps2Data!=1) { printf("%d", *ps2Data); printf("%d", *ps2Data); printf("%d", *ps2Data); printf("%d", *ps2Data); printf("\n"); break; } } usleep(500000); } 

 

However the sequences that i had captured are not always the same for 1 key they can be the same for two different keys. 

For instance, when i pressed the 0 from the keypad it gave this (from the console) : 

0001 

0001 

0101 

0001 

0001 

0001 

0001 

 

And when i pressed the letter "N" i had : 

0001 

0101 

0001 

0001 

0001 

0001 

0001 

 

 

I know that there is a sequence when the key is pushed and an other one when the key is released, but i don't think that this is my problem. 

 

Actually i only need the 0-9 digits from the keypad which should be easier to implement (i guess). 

 

How could i do to capture the right sequences from the keyboard by using C ? 

 

Thank you for helping me :)
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
279 Views

What ps2Data is? Is it a pointer to the rx register of your ps2 serial port? 

Why do you read it 4 times? 

And, what's the meaning of if(*ps2Data!=1) ? 

Usually you need to test a "rx ready" bit on rx status register in order to know if new data word is available.
0 Kudos
Reply