Pic18f2550 HID Keyboard


Closed Thread
Results 1 to 21 of 21
  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,588

    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,588

    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,588

    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!

  8. #8
    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 .

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

    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

  10. #10

    Default Re: Pic18f2550 HID Keyboard

    Hi there,

    Is that your entire code?

    Shouldn't be also something like: " include KBDDESC.ASM " in the main code ?

    Regards
    Rui

  11. #11
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    157

    Default Re: Pic18f2550 HID Keyboard

    Wouldn't it shorten things to do this:

    Code:
    if portb.7 = 1 then
        FOR i = 0 to 7
             IF i = 2 then
                 USBBuffer[i] = $33 ; 33=";"
             ELSE
                 USBBuffer[i] = 0
             ENDIF
        NEXT i
        gosub DoUSBOut
    ELSE
    ....clear buffer...
    ENDIF
    Last edited by andywpg; - 16th September 2014 at 00:29.
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  12. #12
    Join Date
    Jun 2007
    Posts
    25

    Default Re: Pic18f2550 HID Keyboard

    Many Thanks , Its Working Now , And The Code Is Down , But Any One Knows How Can I Include Multimedia Keys (Play,Stopn, Mute . . .etc) , i know i must add it to usb descreptor but i never knows how , i read alot without luck .


    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
    INCLUDE "DT_INTS-18.bas"
    ASM
    INT_LIST macro
    INT_Handler USB_INT, _DoUSBService, ASM, yes
    endm
    INT_CREATE
    endasm
    USBBufferSizeTX con 8
    USBBufferSizeRX con 8
    USBBufferCount Var Byte
    USBBufferIn var byte[8]
    USBBufferOut Var Byte[8]
    DataToSend var byte[8]
    asm
    SendUSB macro array
    variable i=0
    while i<8
    MOVE?BB (array+i),(_USBBufferOut+i)
    i+=1
    endw
    L?CALL _DoUSBOut
    endm
    endasm
    SwHwInit:
    GOSUB DoUSBinit:
    Start:
    clear
    if portb.7 = 1 then
    DATATOSEND[1] = 0
    DATATOSEND[2] = 0
    DATATOSEND[3] = $51 ; if i change it to be "80" >> volume up, it didnt work .
    DATATOSEND[4] = 0
    DATATOSEND[5] = 0
    DATATOSEND[6] = 0
    DATATOSEND[7] = 0
    gosub DoUSBOut
    else
    clear
    DATATOSEND[1] = 0
    DATATOSEND[2] = 0
    DATATOSEND[3] = 0
    DATATOSEND[4] = 0
    DATATOSEND[5] = 0
    DATATOSEND[6] = 0
    DATATOSEND[7] = 0
    endif
    @ SendUSB _DataToSend
    gosub dousbin
    goto start
    DoUSBIn:
    @ INT_DISABLE USB_INT
    USBBufferCount = USBBufferSizeRX
    USBService
    USBIn 1, USBBufferin, USBBufferCount, Timeout
    Timeout:
    @ INT_ENABLE USB_INT

    DoUSBOut:
    @ INT_DISABLE USB_INT
    WaitPC:
    USBBufferCount = USBBufferSizeTX
    USBService
    USBOut 1, USBBufferOut, USBBufferCount, Waitpc
    @ INT_ENABLE USB_INT
    return
    usb_device_state var byte EXT
    CONFIGURED_STATE CON EXT
    DoUSBinit:
    pause 500
    usbinit
    repeat
    usbservice
    until usb_device_state = CONFIGURED_STATE
    @ INT_ENABLE USB_INT
    return
    DoUSBService:
    usbservice
    @ INT_RETURN
    Attached Files Attached Files

  13. #13
    Join Date
    Sep 2009
    Posts
    737

  14. #14
    Join Date
    Jun 2007
    Posts
    25

    Default Re: Pic18f2550 HID Keyboard

    Sorry , But Didn't work i tried it , Beside its just multimedia keybad not full qwerty & Media Keyboard .

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

    Default Re: Pic18f2550 HID Keyboard

    You forgot element zero (length of 8 is from 0 to 7):

    DATATOSEND[0] = 0

    I can't help you with the keyboard command, sorry.

    Robert

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

    Default Re: Pic18f2550 HID Keyboard

    Code:
    DoUSBinit:
    pause 500
    usbinit 
    repeat 
    usbservice
    until usb_device_state = CONFIGURED_STATE
    @ INT_ENABLE USB_INT
    return
    1. That PAUSE can screw up USB.

    2. DT INT takes care of USB INIT for you.

    3. You shouldn't have to write your own assembler routines for USB, they should be available in DT INT.

    4. I didn't see ReEnterPBP-18.bas included.

    Robert

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

    Default Re: Pic18f2550 HID Keyboard

    I recommend read Darrel Taylor's posts from this point:

    http://www.picbasic.co.uk/forum/show...0434#post80434

    Download that file and look how he does things.

    Robert

  18. #18
    Join Date
    Jun 2007
    Posts
    25

    Default Re: Pic18f2550 HID Keyboard

    I just forget to past it here but already found in my code , thanks for mention

  19. #19
    Join Date
    Jun 2007
    Posts
    25

    Default Re: Pic18f2550 HID Keyboard

    Thanks Robert ,

    Already Did Now But , Doesn't Help In My Situation (Multimedia & qwerty Keyboard) .

  20. #20

    Default Re: Pic18f2550 HID Keyboard

    Hi all,

    I don't mean to turn my question into an off topic but,

    can someone explain me how the descriptor works without being included in the main program ( my question above ) ?

    Thanks

    Regards
    Rui

  21. #21
    Join Date
    Jan 2006
    Location
    Toronto
    Posts
    109

    Default Re: Pic18f2550 HID Keyboard

    I am confused, you asked how to add multimedia keys so he linked to my HID multimedia keypad and u simply say it doesn't work and its not a full keyboard. What exactly do you want then?

    I do use Darrels interrupt routines in mine as they work way better for this type of job but did not include the actual files as I just thought it was better to get them from Darrel.
    Last edited by PJALM; - 6th November 2014 at 00:02.

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, 15:05
  2. HID Keyboard Example
    By apitaru in forum USB
    Replies: 8
    Last Post: - 6th August 2010, 17:27
  3. PIC18F2550 Newbie
    By JeffnDana in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th April 2007, 16:13
  4. Replies: 3
    Last Post: - 18th January 2006, 15:12
  5. USB, PIC18F2550 and VB
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th November 2005, 19:37

Members who have read this thread : 2

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