Author Options:

I want a PIC microcontroller to send signals to my PC as a keyboard. How to? Answered

Hey! I'm working on a custom peripheral project that so far has three levels:

1 - input, through capacitive buttons
2 - Processing, made by a PIC, still to be determined (but most likely a 16F628 SOIC)
3 - output: each capacitive button should be equivalent to a shortcut on a standard keyboard (i.e. Alt+Ctrl+S, Alt+Ctrl+2).

The interface will be USB. What kind of coding i need to make the PIC comunicate to the PC? Do i need an extra IC for the job (other than the USB controller)? 

*** You problably noted some shallowness in my knowledge on ICs.... cause this is my first time going beyond the Blinky LED. Any help will be very handy! Thanks! ***


Sending Control-Alt-Whatever is going to be more complicated than sending a single key.

A PC keyboard sends a signal each time a key is pressed or released, saying which key it was and which direction it's going. The device driver is responsible for keeping track of that and recognizing "chords" of keys. So Control-Alt-S would be a total of six distinct bytes: Control key down, Alt key down, S key down, S key up, Alt key up, Control key up. (The order of control and alt doesn't matter, but both need to be down when the S key is hit to get the result you want.)

So you might want to consider using one of the function keys instead. F1-down followed by F1-up would be a bit easier. And it would present less risk of causing keystrokes from the user to suddenly be misinterpreted as control- or alt- keys.

Hardware: I agree, use the PS/2 serial protocol and feed it into a USB converter if necessary. USB is more complexity than you want to deal with for this simple project, and the converters are cheap ($15 or less).

That was a very good explanation, indeed. I have a better vew of the situation now, thanks a lot.

I know i should go and check my sources on PIC coding, but is it any simple to implement key-down and key-up signals? Or is like programming an LCD, which requires a little library refering each letter to its correspondent hex?

Basically, it's just a matter of putting the right bytes out on a serial port. Assuming your PIC either has hardware for that, or a software library for that, or you include a UART chip in the design to do conversion between serial and parallel, it should be straightforward. I haven't checked the references cited in the other posts, but I presume they'll give you what you need.

Sure it was helpful, lemonie. Every bit of data acknowledged counts. Thanks =D

I would output the signal as if you were connecting it through ps/2. The protocol is much simpler, and you can convert it to USB with an adapter, or even the chip inside of the adapter.

Nice idea! If the chip fits in the adapter it will fit in my peripheral. Thanks, dude!