PDA

View Full Version : Pic18f2550 HID Keyboard



amenoera
- 14th September 2014, 12:55
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, ...)

Demon
- 14th September 2014, 14:32
I don't see how someone can help with seeing all your code.

Robert

Charlie
- 14th September 2014, 14:34
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.

amenoera
- 14th September 2014, 14:55
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 .

amenoera
- 14th September 2014, 22:38
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

Demon
- 15th September 2014, 01:02
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

Demon
- 15th September 2014, 01:06
By the way, your buffer is 32 bytes long but you only use the first 8 bytes.


Robert

amenoera
- 15th September 2014, 09:28
I Told Them , Demon Is My Hero :wink: , I Will Try Today And Feedback , Many Thanks .

Demon
- 15th September 2014, 14:47
Just noticed something else, only send when you have to:



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

ruijc
- 15th September 2014, 21:39
Hi there,

Is that your entire code?

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

Regards
Rui

andywpg
- 15th September 2014, 23:27
Wouldn't it shorten things to do this:


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

amenoera
- 15th September 2014, 23:53
Many Thanks :D , 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

pedja089
- 15th September 2014, 23:58
http://www.picbasic.co.uk/forum/showthread.php?t=14320&p=99516#post99516

amenoera
- 16th September 2014, 00:09
Sorry , But Didn't work i tried it , Beside its just multimedia keybad not full qwerty & Media Keyboard .

Demon
- 16th September 2014, 01:07
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

Demon
- 16th September 2014, 01:20
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

Demon
- 16th September 2014, 01:34
I recommend read Darrel Taylor's posts from this point:

http://www.picbasic.co.uk/forum/showthread.php?t=5418&page=6&p=80434#post80434

Download that file and look how he does things.

Robert

amenoera
- 16th September 2014, 08:32
I just forget to past it here but already found in my code , thanks for mention

amenoera
- 16th September 2014, 10:13
Thanks Robert ,

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

ruijc
- 17th September 2014, 19:36
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

PJALM
- 5th November 2014, 22:56
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.