thanks mister alot and I don't know how to thank you.
I now can plug in using vb6 but no data recieved or nothing transmited to PIC I don't now why
' Pic Configuration
' =================
asm
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC3_PLL4_1L & _USBDIV_2_1L ;20Mhz
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H ;20Mhz
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48
buffer Var Byte[4]
loopcnt Var Byte
state Var Byte
trisb=0
portb=0
trise=255
symbol rightbut=porta.2
symbol leftbut=porta.3
symbol upbut=porta.4
symbol downbut=porta.5
ADCON1 = %00001101 ' AN<1:0> Analog, other digital
USBInit
buffer[0] = 0
buffer[1] = 0
buffer[2] = 0
buffer[3] = 0
movecursor:
gosub DoUSBIn
state=4
if rightbut=1 then state=0
if leftbut=1 then state=1
if upbut=1 then state=2
if downbut=1 then state=3
USBService ' Must service USB regularly
Branch state, [up, right, down, left,movecursor]
up:
buffer[1] = 0
buffer[2] = -2
Goto endgame
down:
buffer[1] = 0
buffer[2] = 2
Goto endgame
left:
buffer[1] = -2
buffer[2] = 0
Goto endgame
right:
buffer[1] = 2
buffer[2] = 0
endgame:
USBService ' Must service USB regularly
USBOut 1, buffer, 4, endgame ' Send buffer to endpoint 1
;Next loopcnt
; Next state
Goto movecursor ' Do it forever
' ************************************************** **********
' * receive data from the USB bus *
' ************************************************** **********
DoUSBIn:
state=8
USBService ' keep connection alive
USBIn 1, buffer, state, contiue ' read data, if available
; recived
portb=buffer[0] ' portb.7
contiue:
return
Bookmarks