Pic18f2550 HID Keyboard


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Posts
    25

    Default Pic18f2550 HID Keyboard

    Dears ,
    many Thanks For The Useful Info I Found Here To Achieve My Project , But Only I have One Concern i Cant Deal With It .

    i Can Connect The Pic To My Pc And Recognized , But When I Try To Send The below Character Or Any Other Character Its Repeated Forever I Don't Know Why .

    Bufferout[0] = 0
    Bufferout[1] = 0
    Bufferout[2] = $33
    Bufferout[3] = 0
    Bufferout[4] = 0
    Bufferout[5] = 0
    Bufferout[6] = 0
    Bufferout[7] = 0

    Output : ";;;;;;;;;;;;;;;;;;;;;;;;; . . . Forever"
    while :

    1st byte = modifier keys (i.e. ctrl, alt, shift)
    2nd byte = reserved
    3-8 = keys pressed ( 0x04 = a, 0x05 = b, ...)

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598

    Default Re: Pic18f2550 HID Keyboard

    I don't see how someone can help with seeing all your code.

    Robert

  3. #3
    Join Date
    Dec 2010
    Posts
    409

    Default Re: Pic18f2550 HID Keyboard

    You need to set the value, then send it, then clear it after it is sent once. Everytime you receive a poll, you will respond with whatever you have in the array. If your character is still there, you send it again.

  4. #4
    Join Date
    Jun 2007
    Posts
    25

    Default Re: Pic18f2550 HID Keyboard

    Dear Demon ,

    You Are Right , But Am In Work Now And i Cant Provide thE Full Code From Here , Anyway I Will Provide It ASAP ,And Thanks Again I Remember Last Time You Helped Me .

    Dear Charlie ,

    Can You Explain In Details Please , I Will Be Thanks If Code Is Provided , Many Thanks For Your Reply .

  5. #5
    Join Date
    Jun 2007
    Posts
    25

    Default Re: Pic18f2550 HID Keyboard

    Here Is My Code & USB Description attached .
    all i need is when i make portb pin 7 high then pic send char ";" .


    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 &_XINST_OFF_4L

    USBBufferSizeMax con 32 ' maximum buffer size
    USBBufferSizeTX con 32 ' input
    USBBufferSizeRX con 32 ' output

    ' the USB buffer...
    USBBuffer Var Byte[USBBufferSizeMax]
    USBBufferCount Var Byte

    ' ************************************************** **********
    ' * main program loop - remember, you must keep the USB *
    ' * connection alive with a call to USBService every couple *
    ' * of milliseconds or so... *
    ' ************************************************** **********
    usbinit ' initialise USB...
    ProgramStart:

    if portb.7 = 1 then
    USBBuffer[0] = 0
    USBBuffer[1] = 0
    USBBuffer[2] = $33 ; 33 = ";"
    USBBuffer[3] = 0
    USBBuffer[4] = 0
    USBBuffer[5] = 0
    USBBuffer[6] = 0
    USBBuffer[7] = 0
    ENDIF





    gosub DoUSBIn
    gosub DoUSBOut
    goto ProgramStart

    ' ************************************************** **********
    ' * receive data from the USB bus *
    ' ************************************************** **********
    DoUSBIn:
    USBBufferCount = USBBufferSizeRX ' RX buffer size
    USBService ' keep connection alive
    USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available
    return

    ' ************************************************** **********
    ' * wait for USB interface to attach *
    ' ************************************************** **********
    DoUSBOut:
    USBBufferCount = USBBufferSizeTX ' TX buffer size
    USBService ' keep connection alive
    USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
    return
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598

    Default Re: Pic18f2550 HID Keyboard

    Code:
    if portb.7 = 1 then
    USBBuffer[0] = 0
    USBBuffer[1] = 0
    USBBuffer[2] = $33 ; 33 = ";"
    USBBuffer[3] = 0
    USBBuffer[4] = 0
    USBBuffer[5] = 0
    USBBuffer[6] = 0
    USBBuffer[7] = 0
    ELSE
    ....clear buffer...
    ENDIF

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598

    Default Re: Pic18f2550 HID Keyboard

    Just noticed something else, only send when you have to:

    Quote Originally Posted by Demon View Post
    Code:
    if portb.7 = 1 then
    USBBuffer[0] = 0
    USBBuffer[1] = 0
    USBBuffer[2] = $33 ; 33 = ";"
    USBBuffer[3] = 0
    USBBuffer[4] = 0
    USBBuffer[5] = 0
    USBBuffer[6] = 0
    USBBuffer[7] = 0
    gosub DoUSBOut
    ELSE
    ....clear buffer...
    ENDIF
    Robert

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598

    Default Re: Pic18f2550 HID Keyboard

    By the way, your buffer is 32 bytes long but you only use the first 8 bytes.


    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  9. #9
    Join Date
    Jun 2007
    Posts
    25

    Default Re: Pic18f2550 HID Keyboard

    I Told Them , Demon Is My Hero , I Will Try Today And Feedback , Many Thanks .

Similar Threads

  1. USB HID is slower than often using PIC18f2550
    By Ahmadabuomar in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th November 2010, 14:05
  2. HID Keyboard Example
    By apitaru in forum USB
    Replies: 8
    Last Post: - 6th August 2010, 16:27
  3. PIC18F2550 Newbie
    By JeffnDana in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th April 2007, 15:13
  4. Replies: 3
    Last Post: - 18th January 2006, 14:12
  5. USB, PIC18F2550 and VB
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th November 2005, 18:37

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