HID Keyboard Example


Closed Thread
Results 1 to 9 of 9
  1. #1
    apitaru's Avatar
    apitaru Guest

    Default HID Keyboard Example

    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

  2. #2
    Merfy's Avatar
    Merfy Guest

    Default Keyboard Descriptors

    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.
    Attached Files Attached Files

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429

    Default

    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?

  4. #4
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by Kamikaze47 View Post
    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.

  5. #5
    Join Date
    Aug 2008
    Posts
    66

    Question

    Quote Originally Posted by skimask View Post
    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.

    Code:
    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 ?

  6. #6
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429

    Default

    what speed external clock are you using?

    and what configs are you using?
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  7. #7
    Join Date
    Aug 2008
    Posts
    66

    Default

    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.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Try this
    Code:
    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
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Sep 2006
    Location
    Venezuela - Caracas
    Posts
    48

    Default

    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
    ..: Don't worry, be happy :..

Similar Threads

  1. USB hid maker help please.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2013, 15:49
  2. i cant get 18f2550 work as HID
    By Ahmadabuomar in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 13th October 2009, 17:39
  3. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 17:10
  4. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 01:04
  5. My wish: AT Keyboard and Mouse commands
    By sayzer in forum PBP Wish List
    Replies: 0
    Last Post: - 4th February 2006, 09:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts