How to work with USBMOUSE ?


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default How to work with USBMOUSE ?

    Hi all, thanks for all members in our favorite forum

    I build the USBDEMO and I can play with PIC and VB6 which add new interface in our knowledge.

    now I want to update my code so I can control of mouse cursor , I saw that there are an example usbmouse but not working with PIC18F4455.
    so I need help in this problem
    Here is my code which nothing happened to mouse cursor:

    ' 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


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

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

    loopcnt var byte
    state 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...

    usbbuffer[0] = 0
    usbbuffer[1] = 0
    usbbuffer[2] = 0
    usbbuffer[3] = 0
    usbbuffer[5] = 0
    usbbuffer[6] = 0
    usbbuffer[7] = 0
    ProgramStart:

    movecursor:
    For state = 0 to 3 ' Move through each state
    For loopcnt = 1 to 16 ' 16 steps in each direction

    Branch state, [up, right, down, left]

    up:
    usbbuffer[1] = 0
    usbbuffer[2] = -2
    Goto endgame
    down:
    usbbuffer[1] = 0
    usbbuffer[2] = 2
    Goto endgame
    left:
    usbbuffer[1] = -2
    usbbuffer[2] = 0
    Goto endgame
    right:
    usbbuffer[1] = 2
    usbbuffer[2] = 0

    endgame:

    gosub DoUSBOut
    Next loopcnt
    Next state


    goto ProgramStart

    ' ************************************************** **********
    ' * receive data from the USB bus *
    ' ************************************************** **********
    DoUSBIn:
    USBBufferCount = USBBufferSizeRX ' RX buffer size
    USBService ' keep connection alive
    USBIn 1, USBBuffer, USBBufferCount, contiue ' read data, if available
    ; recived
    portb=usbbuffer[0] ' portb.7
    contiue:
    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
    Last edited by iugmoh; - 16th April 2008 at 18:00.

  2. #2

    Talking

    Oky , I have got it work now
    I discover that I must add MOUSDESC.ASM file and change USBDESC.asm file to include previous file. But I have another question how I can combine usbdemo with usbmouse so I can control mouse curser and control pins from VB6
    here is my code:
    ' 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

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

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    i NEVER EVER messed with the mouseDemo...

    BUT...You need to know which PID/VID it use.. if any (USBDemo use the default one generated with EasyHID).. unless it will never work.

    Q: Sir... how may i know the VID/PID?
    A: USBDeview is a nice & free Utility ( http://www.nirsoft.net/utils/usb_devices_view.html )
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4

    Default

    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
    Last edited by iugmoh; - 16th April 2008 at 21:32.

  5. #5

    Question

    Hi all, I want to ask how to implement right click button and left click button and scroll click button for usbmouse

  6. #6

    Default

    Oky after no replying from anyone I try by myself to make this thing, and after many searching and trial and error, I achive it and done it.
    this site help me in our work
    http://pic18fusb.online.fr/wiki/wikk...uttonsAndWheel

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Way to go!

    Thanks for the link. Now in my Bookmark list here
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 09:19
  2. Can't get POT work on P12f675 - Newbie
    By berslan in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th March 2008, 21:22
  3. How to set ICD-2 clone to work with PBP?
    By G-R-C in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th October 2006, 02:50
  4. blink.bas help cant make any 18f's work
    By Bonxy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th December 2004, 21:28
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

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