PDA

View Full Version : HID Keyboard Example



apitaru
- 3rd December 2005, 17:08
Hi everybody,

I am attempting to extend the USBMOUSE example (provided with PBP under /usb18 folder), so the target device (18F2550 or 18F4550) would be recognized by WinXP/OsX as both an HID Mouse and Keyboard. I'm not clear on how to use the USB desc files and would appreciate any examples and advise. If anyone has an example for just a Keyboard, that would also be of great help.

Cheers
Amit Pitaru

Brooklyn, NY

Merfy
- 9th June 2006, 00:09
To implement a usb keyboard it is just a matter of setting up the descriptors properly. The hid documentation has a good example of the keyboard descriptor. http://www.usb.org/developers/devclass_docs/HID1_11.pdf

Here is the mouse example descriptor that has been modified to work as a keyboard. To send a key stroke to the PC is as simple as (similar to mouse example included with PBP):

USBOut 1, buffer, 8, endgame

after initializing the device
where buffer is 8x8bytes
1st byte = modifier keys (i.e. ctrl, alt, shift)
2nd byte = reserved
3-8 = keys pressed ( 0x04 = a, 0x05 = b, ...)

I don't know how to combine both a keyboard and a mouse together in one device but I have heard of making a composite device being one possible way. But as of yet, I have not got anything working.

I understand this is a late reply but hopefully someone else might get something from it.

Kamikaze47
- 12th June 2007, 18:27
Hi,
I realize I am resurrecting an old thread here, but I'm trying to get an 18F4550 to act as a "virtual keyboard". I've used Merfy's KBDDESC.ASM (above) and i've managed to get the PC to detect it as a keyboard, and can send keystrokes, however when I do, it seems to send the keystroke over and over and over until I send another one.

If I do this for example (and keep in mind this line is only run once):

USBOut 1, buffer, 8, endgame

where buffer=[0,0,$14,0,0,0,0,0] ' ($14=q)

the pc types "qqqqqqqqqqqqqqqqqqqqqq....." and on forever.

any suggestions?

skimask
- 12th June 2007, 18:54
Hi,
I realize I am resurrecting an old thread here, but I'm trying to get an 18F4550 to act as a "virtual keyboard". I've used Merfy's KBDDESC.ASM (above) and i've managed to get the PC to detect it as a keyboard, and can send keystrokes, however when I do, it seems to send the keystroke over and over and over until I send another one.
If I do this for example (and keep in mind this line is only run once):
USBOut 1, buffer, 8, endgame
where buffer=[0,0,$14,0,0,0,0,0] ' ($14=q)
the pc types "qqqqqqqqqqqqqqqqqqqqqq....." and on forever.
any suggestions?
Not really sure if this has anything to do with your problem...
http://www.beyondlogic.org/keyboard/keybrd.htm

Looks to me like you you're on the right track...just not all the way there yet.
You've told the PC that you've pressed the 'q' key, but you haven't told the PC that you've released it, therefore, it repeats.
The first paragraph of the link above has some good info in it on the whole keyboard theory...should give you all the answers you need.

Pic2008
- 7th June 2010, 14:48
Not really sure if this has anything to do with your problem...
http://www.beyondlogic.org/keyboard/keybrd.htm

Looks to me like you you're on the right track...just not all the way there yet.
You've told the PC that you've pressed the 'q' key, but you haven't told the PC that you've released it, therefore, it repeats.
The first paragraph of the link above has some good info in it on the whole keyboard theory...should give you all the answers you need.

I can't seem to get the USB to work with PIC18F4550 using the KBDDESC.ASM

I keep getting USB error if i plug in the PIC.



buffer Var Byte[8]
loopcnt Var Byte
state Var Byte

Define OSC 48



Pause 10

USBInit

buffer[0] = 0
buffer[1] = 0
buffer[2] = 0
buffer[3] = 0
buffer[4] = 0
buffer[5] = 0
buffer[6] = 0
buffer[7] = 0

movecursor:


buffer[0] = 0
buffer[1] = 0
buffer[2] = $14
buffer[3] = 0

endgame:
USBService ' Must service USB regularly
USBOut 1, buffer, 8, endgame ' Send buffer to endpoint 1
while(1)
wend
Goto movecursor ' Do it forever





Anyone knows what is wrong ?

Kamikaze47
- 7th June 2010, 15:20
what speed external clock are you using?

and what configs are you using?

Pic2008
- 8th June 2010, 03:00
Using 20Mhz crystal.

Config is:

__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L


__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H

I have tried using diff cap recommended in this forum.

mackrackit
- 8th June 2010, 03:22
Try this


DEFINE OSC 48
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L

mpardinho
- 6th August 2010, 17:27
I use KBDDESC.txt

USBOut 1, buffer, 8, endgame

t = $0
where buffer=[t,0,$14,0,0,0,0,0] ' ($14=q) OK

t = $2
buffer=[t,0,$33,0,0,0,0,0]' ($33 = /) error

i need send "?" = #33 + shift = $2