USB CDC Communications for Dummies!


Results 1 to 40 of 105

Threaded View

  1. #11
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default USB CDC_DEMO with DT_INTS

    Here is some PBP 2.60 code (cut and pasted) from Darrel, with the "Hello World" example added in. Darrel's main code is taken from another thread, located here: http://www.picbasic.co.uk/forum/show...4292#post94292 . It uses DT_INTS ( instant interrupts ) to service the USB. As always, DT_INTS can then also be used for all types of other things, while the USB connection is kept alive.

    Name:  schematic-large.gif
Views: 13809
Size:  28.8 KB

    Code:
    '  Compilation of this program requires that specific support files be
    '  available in the source directory.  For detailed information, see
    '  the file PBP\USB18\USB.TXT.
    
    '  Config files for PIC18F4550 with 20 mhz crystal
    
    asm
            __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
            __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
            __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_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
    endasm
    DEFINE OSC 48
    
    INCLUDE "cdc_desc.bas" 'Descriptor file    for CDC    serial demo
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"  ; Include if using PBP interrupts
    buffer    Var    Byte[16]
    cnt    Var    Byte
    ASM
    INT_LIST  macro     ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler     USB_INT,  _DoUSBSERVICE,   ASM,  yes
            INT_Handler     INT_INT,    _Handle_INT,   PBP,  yes
        endm
        INT_CREATE             ; Creates the Low Priority interrupt processor
    
        ;INT_ENABLE  USB_INT   ;we will do this after we initialize USB
        INT_ENABLE  INT_INT
    ENDASM
    
    
    ;----[Initialise USB and Interrupts]----------------------------------------
        PAUSE 100                    ; Allow VUSB to stabilize
        USBINIT                      ; initialize the USB driver
        USBSERVICE                   ; service it once
        UIE = $7F                    ; enable USB interrupts
        UEIE = $9F                   ; enable USB Error interrupts
    @   INT_ENABLE  USB_INT
    
    ;----[Main program loop]----------------------------------------------------
    Main:
        cnt = 16        ' Specify input buffer size
        USBIn 3, buffer, cnt, main
    
    ' Message received
        buffer[0] = "H"
        buffer[1] = "e"
        buffer[2] = "l"
        buffer[3] = "l"
        buffer[4] = "o"
        buffer[5] = " "
        buffer[6] = "W"
        buffer[7] = "o"
        buffer[8] = "r"
        buffer[9] = "l"
        buffer[10] = "d"
        buffer[11] = 13
        buffer[12] = 10
        buffer[13] = 0
    
    outloop:
        USBOut 3, buffer, 14, outloop
    
    GOTO Main
    
    ;----[Interrupt handler -- Service USB]-------------------------------------
    DoUSBSERVICE:
          USBSERVICE                   ; Run the SERVICE routines
    @ INT_RETURN
    
    ;----[Interrupt handler -- INT]
    Handle_INT:
     ; something here
    @ INT_RETURN
    Last edited by ScaleRobotics; - 31st December 2010 at 19:51.
    http://www.scalerobotics.com

Similar Threads

  1. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 20:17
  2. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 00:04
  3. USB CDC help..
    By jchandir in forum USB
    Replies: 6
    Last Post: - 22nd November 2008, 21:23
  4. Replies: 4
    Last Post: - 5th November 2008, 16:21
  5. USB PIC without USB Connection
    By Tissy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th December 2005, 17:39

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