USBDemo, something to learn USB a little bit


Closed Thread
Results 1 to 40 of 279

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    This example use a 4MHz crystal (as stated in the code and in post #1), and i suggest something higher than 220nF and you don't need the 1.5K resistor as i set the internal one.

    Now if you want to stick with the 20MHZ crystal, you'll need to modify the first __CONFIG line to
    Code:
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    all should be fine after that.
    Last edited by mister_e; - 22nd February 2007 at 01:24.
    Steve

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

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    For 20mhz, you also need ...
    Code:
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEM_OFF_1H & _IESO_OFF_1H
    DT

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


    Did you find this post helpful? Yes | No

    Default

    <table><tr><td></td><td>Newbie mistake from me... At least heaven's voice saved the day </td></tr></table>
    Last edited by mister_e; - 22nd February 2007 at 01:41.
    Steve

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

  4. #4
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Cool

    This message will now be rendered useless. I wanted to delete it, but since I can't, I've put this stupid line here.
    Last edited by SterlingY; - 14th March 2007 at 01:20.

  5. #5
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Angry

    Hi,

    Having a problem with the MCHID.DLL.

    My HID device works well on my development PC - but when I plug it into another PC (both running XP), windows automatically assigns it's own HID.DLL, and thus the device doesnt work. (It appears in devicemanager correctly)

    How do I force XP to use the MCHID.DLL when there are no .inf files to use?

    Cheers
    Squib.

  6. #6
    Join Date
    Feb 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    I've always MCHID.DLL in the same dir as the executable :-) that helps

  7. #7
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Unhappy Driver Woes

    Yeah but... let me clarify,

    I've made a USB HID device (rudder pedals for my flight sim to replace my old gameport rudder pedals) and used Easy HID to make the necessary files.

    When I plug it into the my Development PC with PBP etc installed, windows detects and it installs them perfectly! The pedals shows up in the game controllers list automatically and I can use them properly, ie calibrate them.

    But when I plug the pedals into my Gaming PC, windows detects them and intalls a driver for it (show up in the system device list), but it doesn't show up in the game controllers list, thus I can't use the peddals.

    I've tried other pc and the same happens.

    I'm not creating any application to go with these pedals, I just want to plug them into any pc and have it work.

    I'm not sure if it is a driver issue, or just a blonde moment. LOL.

    Cheers

  8. #8
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    mister e,

    Great stuff. A lot of good things to learn in your example.

    So I've decided to make my own version, but I have run into a hurdle with EasyHID. Has anyone had trouble installing it? I need to mcHID.dll, but I can't install the software on my XP64 machine. The setup.exe program just seems to hang, without ever bringing up the install screen. And on my win2K machine, I get an error that it can't create the mcHID in the winnt/system32 folder.

    Any thoughts?

    -Sterling
    Last edited by SterlingY; - 15th March 2007 at 03:09.

  9. #9


    Did you find this post helpful? Yes | No

    Thumbs up I am Still Hoping Something Can be Done

    Hi, This really is a nice post, I am going to work with it, i will have to use 18f2550 since it is the available part around here.

    1. Any problem with it being the 2550? someone said "Thank god you didn´t choose the 2550" before.

    2. I guess i`ve read the answer to this but...: Usb Communications require somehow a "master"(host) and a "slave"? if this is so, i would never be able to communicate two pics through USB would I?, where i am going is that i intend to control USB devices but this could never be done if this is true, has anyone figured something without buyign those ugly USB HOST controllers? they really are a pain in the a.. you can´t find them at all(not here).

    I have a uC develpment to control by serial (rS232) port some GSM phones, but the newer models dont support serial but USB, what should be done to transfer data between a uc and them?

    It seems to me like an step backwards the fact that usb had lost the simplicity of RS232 communications in this matter.

    thanks for the hobby time again
    Last edited by Josuetas; - 5th April 2007 at 14:01.

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


    Did you find this post helpful? Yes | No

    Default

    1. There's no real problem with the 2550. It was just an inside between me and Malc about a previous thread on some behaviour to program this specific PIC with his PIC programmer. not much. Don't worry.

    2. You can't use a PIC to PIC USB comm unless you really want to waste your time to develop a host controller... not something i would do. Hence why there's a few available on the market.

    USB is not as simple as RS232 of course, it's another and really different animal.

    Good luck!
    Steve

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

  11. #11
    Join Date
    Feb 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    I lately bought the book of Jan Axelson and this realy helped me. Here the link of Amazon
    USB Complete: Everything You Need to Develop Custom USB Peripherals

    Good Luck ;-)

  12. #12
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Josuetas View Post

    1. Any problem with it being the 2550? someone said "Thank god you didn´t choose the 2550" before.
    Don't be put off by my comments. As Steve mentioned it was a "toung in cheek" jibe as poor old Steve and I spent days trying to get an 18F2550 programmed with some bit of code using my cheap JDM programmer and some freeware loaders !

  13. #13
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    Can i use this demo with DasyLab Or Labview ? I using both software from long time for DAQ.
    Thanks

    .

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by precision View Post
    Can i use this demo with DasyLab Or Labview ? I using both software from long time for DAQ.
    Thanks

    .
    Sorry, i don't use them

    Johan, it's really a trough hole PLCC44 socket
    Digikey:
    A-CCS44-Z-R


    OR
    940-44-044-24-000000

    OR
    8444-11B1-RK-TP
    Steve

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

  15. #15
    Join Date
    Jun 2007
    Posts
    56


    Did you find this post helpful? Yes | No

    Default

    Steve

    Yes, it is indeed just a plain PLCC socket,

    I was mistaking it as something else , I thought it was a " mini" plcc44,that fits inside DIP 40 socket, but after I look more closer, it is bigger than the DIP

    I never use PLCC44 socket before, will it fit to QFN 8x8 type PIC 18F4431 ?

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


    Did you find this post helpful? Yes | No

    Default

    Nope, it's really 2 different animal. Even if possible, good luck with home made soldering for QFN packages

    the easiest home made soldering would be DIP or TQFP packages.

    But yes you can buy some QFN adapter.. make sure you're wallet is ready for that talking about those no solder type... kind of ZIFF for QFN... see those

    http://www.ironwoodelectronics.com/c...-P-Z-01Dwg.pdf
    http://qfp-adapter.com/Site/QFN-MLF-...cket-TOPs.htm#
    Last edited by mister_e; - 14th July 2007 at 15:15.
    Steve

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

  17. #17
    bj49's Avatar
    bj49 Guest


    Did you find this post helpful? Yes | No

    Thumbs up thanks for the USB demo

    Thanks to Mister_E's USB demo and DT's ints18 and this forum I have my USB board PICF4550@ 48 Mhz running a single DS1820 displaying on VB6 and it took less than 1/2 a day and its stable and fast!

    This is my first post and I would like to congratulate this forum for the information that is available and the generosity of people like mister_e and darren taylor and others for sharing their experience;it is invaluable for me
    This demo should be pinned!

  18. #18
    selimkara's Avatar
    selimkara Guest


    Did you find this post helpful? Yes | No

    Default CDC problem in UsbDemo program...

    First of all, I would like to thank everybody here.,especially, Mister_E, Darrel Taylor and Squibcakes. I have downloaded the usbdemo and it works great.
    I have programmed the pic while including the line INCLUDE "CDCDESC.ASM" in USBDESC.asm.
    But I could not use this with VB6 with MSCOMM1. Namely, I want to use as CDC the given VB6 code. Please could you help me?
    Thanks,
    Selim

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


    Did you find this post helpful? Yes | No

    Default

    @selimkara
    is there any specific reason why you really want to use CDC ?

    @Josuetas
    There's probably few way to do what you want, using something like a header. Such HSERIN WAIT(YourHeader) so when you receive/send data, you may want to check/set few or only one Byte. Then the Slave/Master do what he has to do if the header match.
    Steve

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

  20. #20
    selimkara's Avatar
    selimkara Guest


    Did you find this post helpful? Yes | No

    Default Thanks Steve, but..

    Thanks for your rapid response and interest. We are working in Physics dept. at Trakya University. Our aim is to control some experimental structures (for example temperature, light intensity...). To do so, we need a less complex and short VB6 procedure. I think using virtual comm port is very useful to do this. Am I wrong? We had succeeded similar connection, using CDC via MSCOMM in VB6 with a short code. But in pic side, we could not set interrupts. Your code(pic) is very useful and simple. So we want to use your pic code and change your VB code to adapt MSCOMM (virtual comport). You may ask why we don't use serial comm.because there's no comm port on new laptops, so we must learn to use USB.
    If I'm not misunderstand, in the following conversation (#36) between you and Squibcakes, Squib reported that he succeeded this. I would like to know how? I think some changes must be made at pic code. If you or squib have tips about this or have complete codes, I'd be grateful. Thanks for your previous suggestions. We'll also utilize them.

    sincerely
    Selim

    #36---------------------------------------------------
    Mr_E
    Yeah ok well thanks for your input anyway - always welcome I'm happy to edit the the .inc file and leave it at that.

    Great news! I finally got the CDC virtual comport working!!!!!!

    Now I can send data via USB (virtual comport) and out of the Pic 18F4550 USART! and vice versa!
    -------------------------------------------------------
    I'm stoked that this actually works!

    Squib

  21. #21
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by selimkara View Post
    T
    If I'm not misunderstand, in the following conversation (#36) between you and Squibcakes, Squib reported that he succeeded this. I would like to know how? I think some changes must be made at pic code. If you or squib have tips about this or have complete codes, I'd be grateful. Thanks for your previous suggestions. We'll also utilize them.

    The post was regarding setting the config fuses by way of changing the 18f4550.inc file.
    I never actually used CDC with the USB demo, totally separate and apart

    As Steve said, you don't need to use CDC to send you data back to the PC. This code uses HID interface and the VB program displays the data coming from the PIC.

    As far as VB is concerned I have no clue - One day I should learn it!

    Squib

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    I'm able to use Steve's demo along with Darrel's include, but it only works when the MeLabs U2 USB programmer is connected. If I unplug the programmer, the 18F4550 is no longer recognized:

    Code:
    '***************************************************************************
    '*  Name    : USBLabX1_RH.pbp                                              *
    '*  Author  : Steve Monfette/Darrel Taylor/Demon                    *
    '*  Date    : Jan 11 2012                                                  *
    '*  Version : 3.0                                                          *
    '*  Notes   : This is a re-creation of mister-e's USBdemo for DT_HID       *
    '*          : Meant to work with mister-e's GUI                            *
    '*          : Modified for Lab X1                                          *
    '*  Hardware : PIC 18F4550, 20mhz crystal                                  *
    '*           : Lab X1 Experimental Board, 9.5V wall adapter                *
    '*           : MeLabs U2 Programmer v4.32                                  *
    '*  Software : PIC Basic Pro v2.60C                                        *
    '*           : MicroCode Studio Plus v2.2.1.1                              *
    '*           : MPASM WIN Assembler v4.02 (mplab tools/MPASM Suite)         *
    '*  PIC mods : plastic USB connector hot-glued onto top of PIC             *
    '*           : D- wired to C4 (pin 23) directly to top of pins             *
    '*           : D+ wired to C5 (pin 24) directly to top of pins             *
    '*           : two 0.1uF ceramic caps in parallel across VUSB and VSS      *
    '***************************************************************************
    '--- if you use these, you must comment the ones in the .inc file ---
    @   __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    @   __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_46_2L & _VREGEN_ON_2L
    @   __CONFIG    _CONFIG2H, _WDT_OFF_2H
    @   __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    
    DEFINE OSC 48
    
    DEFINE  LCD_DREG      PORTD         ' Set LCD data port
    DEFINE  LCD_DBIT      4             ' Set starting data bit
    DEFINE  LCD_RSREG     PORTE         ' Set LCD register select port
    DEFINE  LCD_RSBIT     0             ' Set LCD register select bit
    DEFINE  LCD_EREG      PORTE         ' Set LCD enable port
    DEFINE  LCD_EBIT      1             ' Set LCD enable bit
    DEFINE  LCD_BITS      4             ' Set LCD bus size
    DEFINE  LCD_LINES     2             ' Set number of lines on LCD
    DEFINE  LCD_COMMANDUS 2000          ' Set command delay time in microseconds
    DEFINE  LCD_DATAUS    50            ' Set data delay time in microseconds
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; PBP Re-entry for external interrupt
    
    ASM
    INT_LIST  macro    ; IntSource,     Label,   Type, ResetFlag?
            INT_Handler   USB_Handler
            INT_Handler   INT_INT,   _ToggleLED1, PBP,    yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    @   INT_ENABLE   INT_INT        ; enable external (INT) interrupts
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Mr E/DT/RH"
    DEFINE USB_PRODUCTNAME "USBLabX1"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     8    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ------------
    ; --- They can be assigned to any pin, and no further action is required --- 
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    DEFINE USB_PLUGGEDLED  PORTD,0 ; LED indicates if USB is connected
    DEFINE USB_TXLED       PORTD,1 ;  "      "     data being sent to PC
    DEFINE USB_RXLED       PORTD,2 ;  "      "     data being received from PC
    
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 8  ; Number of bits in ADCIN result
    
        TRISA = %00000011               ' Set port A pins to 6 output, 2 input
        TRISB = %00001111               ' Set port B pins to 4 output, 4 input
                                        ' B0 = External Interrupt
        TRISC = %00000000               ' Set all port C pins to output
        TRISD = %00000000               ' Set all port D pins to output
        TRISE = %00000000               ' Set all port E pins to output
    
    ;--- Variables -------------------------------------------------------------
    Value0      VAR  WORD : Value0 = 0
    Value1      VAR  WORD : Value1 = 0
    DUTY1       VAR  WORD
    DUTY2       VAR  WORD
    LED1        VAR PORTD.3
    WS_CHAR     VAR BYTE
    WS_BYTE     VAR BYTE
    WS_LOOPW    VAR WORD
    ;--- Initialize ------------------------------------------------------------
        ADCON2.7 = 0       ; left justify    (Change this if ADFM in diff register)
        ADCON1 = %00001101     ; AN0 & AN1 analog
        INTCON2 = %00000000    ; Pull-up resistors, falling edge
    
        PORTB = %00000000      ; Set output on keypad to prevent floating pins
    
    
        PAUSE   2000                     ' Wait for USB to initalize
        LCDOUT  $FE,1,"LabX1 18F4550 USB"
        PORTD = 0                       ' Clear LEDs from LCD operations
        ARRAYWRITE USBTXBuffer, ["Lab X1  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        
    ;--- The Main Loop ---------------------------------------------------------
    Main:
        FOR WS_LOOPW = 0 to 1000           ; Check for incomming USB data while waiting
    @       ON_USBRX_GOSUB  _HandleRX
            PAUSE 1
        NEXT WS_LOOPW
        
        ADCIN 0, Value0            ; Send A/D about once/sec
        ADCIN 1, Value1
        ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTD.3, 0, 0, 0, 0, 0]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
    
        GOTO Main
    end
    
    ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
    HandleRX:
        ARRAYREAD  USBRXBuffer,[WS_BYTE, DUTY1.LowByte, DUTY1.HighByte, _
                                        DUTY2.LowByte, DUTY2.HighByte]
        LCDOUT  $FE,$C0,BIN WS_BYTE
        PORTD = 0                       ' Clear LEDs from LCD operations
    return
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
        TOGGLE LED1
        ARRAYWRITE USBTXBuffer, ["Button  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        PORTB = 0               ' Set output on keypad to prevent floating pins
    @ INT_RETURN
    On the Lab X1:
    - PWM logic is not active.
    - buttons 1, 2, 3 and 4 on the keypad activate Port A2 LED.
    - AN 0 and 1 work as expected.

    On the PC:
    - Port B is displayed on the LCD.

    Any idea why Windows XP Home would need the USB programmer connected in order to recognize the PIC?

    Everything works fine if I reconnect the programmer.

    Robert
    Last edited by Demon; - 4th October 2016 at 17:13.

  23. #23
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Robert,

    Check the ground from your USB connector.

    Plugging in the programmer will give a common ground with the computer.
    If there is no ground from your USB connector, it will disconnect when you unplug the U2.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Yup, that fixed that problem.

    But if I leave the programmer connected, it garbles a few characters on the LCD?

    Cleaned up code (replaced PAUSE for LOOP):

    Code:
    '***************************************************************************
    '*  Name    : USBLabX1_RH.pbp                                              *
    '*  Author  : Steve Monfette/Darrel Taylor/Demon                    *
    '*  Date    : Jan 11 2012                                                  *
    '*  Version : 3.0                                                          *
    '*  Notes   : This is a re-creation of mister-e's USBdemo for DT_HID       *
    '*          : Meant to work with mister-e's GUI                            *
    '*          : Modified for Lab X1                                          *
    '*  Hardware : PIC 18F4550, 20mhz crystal                                  *
    '*           : Lab X1 Experimental Board, 9.5V wall adapter                *
    '*           : MeLabs U2 Programmer v4.32                                  *
    '*  Software : PIC Basic Pro v2.60C                                        *
    '*           : MicroCode Studio Plus v2.2.1.1                              *
    '*           : MPASM WIN Assembler v4.02 (mplab tools/MPASM Suite)         *
    '*  PIC mods : plastic USB connector hot-glued onto top of PIC             *
    '*           : D- wired to C4 (pin 23) directly to top of pins             *
    '*           : D+ wired to C5 (pin 24) directly to top of pins             *
    '*           : two 0.1uF ceramic caps in parallel across VUSB and VSS      *
    '***************************************************************************
    '--- if you use these, you must comment the ones in the .inc file ---
    @   __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    @   __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
    @   __CONFIG    _CONFIG2H, _WDT_OFF_2H
    @   __CONFIG    _CONFIG3H, _CCP2MX_OFF_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    
    DEFINE OSC 48
    CLEAR 
    
    DEFINE  LCD_DREG      PORTD         ' Set LCD data port
    DEFINE  LCD_DBIT      4             ' Set starting data bit
    DEFINE  LCD_RSREG     PORTE         ' Set LCD register select port
    DEFINE  LCD_RSBIT     0             ' Set LCD register select bit
    DEFINE  LCD_EREG      PORTE         ' Set LCD enable port
    DEFINE  LCD_EBIT      1             ' Set LCD enable bit
    DEFINE  LCD_BITS      4             ' Set LCD bus size
    DEFINE  LCD_LINES     2             ' Set number of lines on LCD
    DEFINE  LCD_COMMANDUS 2000          ' Set command delay time in microseconds
    DEFINE  LCD_DATAUS    50            ' Set data delay time in microseconds
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; PBP Re-entry for external interrupt
    
    ASM
    INT_LIST  macro    ; IntSource,     Label,   Type, ResetFlag?
            INT_Handler   USB_Handler
            INT_Handler   INT_INT,   _ToggleLED1, PBP,    yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    @   INT_ENABLE   INT_INT        ; enable external (INT) interrupts
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Mr E/DT/RH"
    DEFINE USB_PRODUCTNAME "USBLabX1"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     8    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ------------
    ; --- They can be assigned to any pin, and no further action is required --- 
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    DEFINE USB_PLUGGEDLED  PORTD,0 ; LED indicates if USB is connected
    DEFINE USB_TXLED       PORTD,1 ;  "      "     data being sent to PC
    DEFINE USB_RXLED       PORTD,2 ;  "      "     data being received from PC
    
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 8  ; Number of bits in ADCIN result
    
        TRISA = %00000011               ' Set port A pins to 6 output, 2 input
        TRISB = %00001111               ' Set port B pins to 4 output, 4 input
                                        ' B0 = External Interrupt
        TRISC = %00000000               ' Set all port C pins to output
        TRISD = %00000000               ' Set all port D pins to output
        TRISE = %00000000               ' Set all port E pins to output
    
    ;--- Variables -------------------------------------------------------------
    Value0      VAR  WORD : Value0 = 0
    Value1      VAR  WORD : Value1 = 0
    DUTY1       VAR  WORD
    DUTY2       VAR  WORD
    LED1        VAR PORTD.3
    WS_CHAR     VAR BYTE
    WS_BYTE     VAR BYTE
    WS_LOOPW    VAR WORD
    ;--- Initialize ------------------------------------------------------------
        ADCON2.7 = 0       ; left justify    (Change this if ADFM in diff register)
        ADCON1 = %00001101     ; AN0 & AN1 analog
        INTCON2 = %00000000    ; Pull-up resistors, falling edge
    
        PORTB = %00000000      ; Set output on keypad to prevent floating pins
    
        LCDOUT  $FE,1                   ' Initiate first command to LCD
        PORTD = 0                       ' Clear LEDs from LCD operations
    
        FOR WS_LOOPW = 0 to 1000        ' Wait for LCD to initalize
            PAUSE 1
        NEXT WS_LOOPW
        LCDOUT  $FE,1,"LabX1 18F4550 USB"
        PORTD = 0                       ' Clear LEDs from LCD operations
    
        FOR WS_LOOPW = 0 to 1000        ' Wait for USB to initalize
            PAUSE 1
        NEXT WS_LOOPW
        ARRAYWRITE USBTXBuffer, ["Lab X1  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        
    ;--- The Main Loop ---------------------------------------------------------
    Main:
        FOR WS_LOOPW = 0 to 1000           ; Check for incomming USB data while waiting
    @       ON_USBRX_GOSUB  _HandleRX
            PAUSE 1
        NEXT WS_LOOPW
        
        ADCIN 0, Value0            ; Send A/D about once/sec
        ADCIN 1, Value1
        ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTD.3, 0, 0, 0, 0, 0]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
    
        GOTO Main
    end
    
    ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
    HandleRX:
        ARRAYREAD  USBRXBuffer,[WS_BYTE, DUTY1.LowByte, DUTY1.HighByte, _
                                        DUTY2.LowByte, DUTY2.HighByte]
        LCDOUT  $FE,$C0,BIN WS_BYTE
        PORTD = 0                       ' Clear LEDs from LCD operations
    return
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
        TOGGLE LED1
        ARRAYWRITE USBTXBuffer, ["Button  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        PORTB = 0               ' Set output on keypad to prevent floating pins
    @ INT_RETURN
    Sharing the USB NEG only seems to affect the LCD. If I unplug the programmer, Port B updates properly on the LCD, everything runs fine.

    Uh oh, just realized I might have misunderstood. There's also a GROUND eyelet coming from the USB cable, is that the ground you were referring to? If so, would that go to VSS instead of the NEG?
    Last edited by Demon; - 4th October 2016 at 17:13.

  25. #25
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Pin 4 of the USB connector is Ground.
    It and the Shield should be connected to VSS on the LAB-X1.

    Have you removed the MAX232 chip?
    You've set the RX pin to output, which is likely to cause high currents if the MAX232 is still there.
    DT

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


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    Quote Originally Posted by Darrel Taylor View Post
    Pin 4 of the USB connector is Ground.
    It and the Shield should be connected to VSS on the LAB-X1.
    ...
    Tried both USB pin 4 (black wire) and the eyelet from the shielding connected to VSS, same garbles on LCD.

    I used one of the VSS pins on the PIC, does it have to be a special VSS contact on the Lab X1?


    Quote Originally Posted by Darrel Taylor View Post
    ...
    Have you removed the MAX232 chip?
    You've set the RX pin to output, which is likely to cause high currents if the MAX232 is still there.
    I didn't remove the MAX232, but I installed headers on my Lab X1. The jumpers for RX and TX pins are disabled, same with VUSB pin.


    EDIT: I didn't have the recommended capacitors so I used two 0.1uF ceramic caps in parallel across VUSB and VSS. Could that be a problem?
    Last edited by Demon; - 21st January 2012 at 04:45.

  27. #27
    Join Date
    Dec 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    DataToSend's array size is 8. i want to make it 16. i mean i want to send 16 variable at the same time. not 8. can anybody help me?

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  3. Replies: 9
    Last Post: - 31st July 2008, 08:56
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 3

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts