Proton BASIC Compiler - Proton CDC


  • PicŪ Basic


  • Using Proton CDC

    It's taken a while to get my head around the CDC example but I've finally have Les's example working.
    The CDC_Descriptor and other "include files" are taken from the original descriptor files found in the PDS\Samples directory and not the new Proton Microchip USB Routines.
    Using a breadboard with a PIC18F2455, 4Mhz clock module and 470uF from Vusb to ground.


    [PHP]
    '************************************************* ***************
    '* Name : GP_USB_CDC.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 18 May 2013 *
    '* Version : 1.0 *
    '* Notes : Use PDS original HID/CDC routines not the updated *
    '* : Loads Proton CDC Virtual Com Port on connecting *
    '************************************************* ***************
    ' Les Johnson's general purpose USB CDC test program.
    '
    ' Transmits data from several different buffers.
    ' And displays the contents of the Usbin buffer on the LCD
    '
    ' Uses transmit and receive detection using the Carry flag (STATUS.0)
    '
    ' Communicate via the serial terminal set to the com port that the USB connects too.
    '

    Declare Xtal = 48 'Set the oscillator speed to 48MHz
    Device = 18F2455
    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings

    Declare Reminders Off
    @ CONFIG_REQ = 0 ; Override Compiler's configuration settings
    Asm-
    Config PLLDIV = 1 ;No prescale (4 MHz oscillator input drives PLL directly)
    Config CPUDIV = OSC1_PLL2 ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
    Config USBDIV = 2 ;USB clock source comes from the 96 MHz PLL divided by 2
    Config FOSC = XTPLL_XT ;XT oscillator, PLL enabled (XTPLL)
    Config FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    Config IESO = OFF ;Oscillator Switchover mode disabled
    Config PWRT = OFF ;PWRT disabled
    Config BOR = On ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    Config BORV = 3 ;Minimum setting
    Config VREGEN = On ;USB voltage regulator enabled
    Config WDT = OFF ;WDT disabled (control is placed on the SWDTEN bit)
    Config WDTPS = 32768 ;1:32768
    Config CCP2MX = On ;CCP2 input/output is multiplexed with RC1
    Config PBADEN = OFF ;PORTB<4:0> pins are configured as digital I/O on Reset
    Config LPT1OSC = OFF ;Timer1 configured for higher power operation
    Config MCLRE = On ;MCLR pin enabled; RE3 input pin disabled
    Config STVREN = On ;Stack full/underflow will cause Reset
    Config LVP = OFF ;Single-Supply ICSP disabled
    Config XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Config Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    Config CP0 = OFF ;Block 0 (000800-001FFFh) is not code-protected
    Config CP1 = OFF ;Block 1 (002000-003FFFh) is not code-protected
    Config CP2 = OFF ;Block 2 (004000-005FFFh) is not code-protected
    Config CPB = OFF ;Boot block (000000-0007FFh) is not code-protected
    Config CPD = OFF ;Data EEPROM is not code-protected
    Config WRT0 = OFF ;Block 0 (000800-001FFFh) is not write-protected
    Config WRT1 = OFF ;Block 1 (002000-003FFFh) is not write-protected
    Config WRT2 = OFF ;Block 2 (004000-005FFFh) is not write-protected
    Config WRTC = OFF ;Configuration registers (300000-3000FFh) are not write-protected
    Config WRTB = OFF ;Boot block (000000-0007FFh) is not write-protected
    Config WRTD = OFF ;Data EEPROM is not write-protected
    Config EBTR0 = OFF ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
    Config EBTR1 = OFF ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
    Config EBTR2 = OFF ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
    Config EBTRB = OFF ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
    Endasm-
    Declare Reminders On

    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------

    Declare LCD_Type 0 ' Type of LCD Used is Alpha
    Declare LCD_DTPin PORTB.0 ' use lower 4 data bits
    Declare LCD_RSPin PORTB.4 ' RS pin on RB4
    Declare LCD_ENPin PORTB.5 ' E pin on RB5
    Declare LCD_Lines 2
    '

    Include "CDC_Descriptor.inc" ' Include the CDC descriptors and the USB routines

    Dim MyWord As Word ' General purpose variable
    Dim Array1[20] As Byte ' Used to hold some output characters
    Dim Out_Buffer As String * 20 ' Used to hold some output characters
    Dim In_Buffer As String * 20 ' Used to hold some input characters
    Dim Code_String As Code = " Code Memory Buffer\n\r",0

    Symbol Carry_Flag = STATUS.0 ' Set if microcontroller does not have control over the DP buffer

    '------------------------------------------------------------------------
    ' The main program loop starts here
    Main:
    DelayMS 10 ' Wait for things to stabilise
    All_Digital = True ' Set PORTA and PORTD to digital mode
    Clear ' Clear all RAM before we start
    Cls ' Clear the LCD

    USBInit ' Initialise USB

    Repeat ' \
    USBPoll ' Wait for the USB interface to become attached
    Until USB_tConnected = 1 Or USB_tConfigured = 1 ' /

    Array1 = " Array Buffer\n\r" ' Fill the array with Null terminated characters
    Out_Buffer = " String Buffer\n\r" ' Fill the string with Null terminated characters

    MyWord = 0 ' Reset the counting variable
    While 1 = 1 ' Create an infinite loop
    Repeat ' Wait for USB input
    USBIn 3, In_Buffer, Auto ' Poll the USB and Receive some data from endpoint 3
    Until Carry_Flag = 0 ' Keep looking until data is able to be received

    Print At 1,1,"USB Buffer"
    Print At 2,1,In_Buffer ' Display the contents of the USB buffer on line 2 of the LCD
    Clear In_Buffer ' Then clear the buffer for the next time

    __USBOut_Buffer = " USB Buffer\n\r" ' Place characters directly into the USB TX buffer string
    '
    ' Transmit from the USB's internal TX buffer String. Null terminated.
    '
    Repeat
    USBOut 3, __USBOut_Buffer, Auto ' Poll the USB and Transmit the buffer from endpoint 3
    Until Carry_Flag = 0 ' Keep trying if the microcontroller does not have control over the buffer
    '
    ' Transmit from a Null terminated array
    '
    Repeat
    USBOut 3, Array1, Auto ' Poll the USB and Transmit the buffer from endpoint 3
    Until Carry_Flag = 0 ' Keep trying if the microcontroller does not have control over the buffer
    '
    ' Transmit from a Null terminated String
    '
    Repeat
    USBOut 3, Out_Buffer, Auto ' Poll the USB and Transmit the buffer from endpoint 3
    Until Carry_Flag = 0 ' Keep trying if the microcontroller does not have control over the buffer
    '
    ' Transmit from a Null terminated code memory String
    '
    Repeat
    USBOut 3, Code_String, Auto ' Poll the USB and Transmit the buffer from endpoint 3
    Until Carry_Flag = 0 ' Keep trying if the microcontroller does not have control over the buffer
    '
    ' Transmit a Null terminated quoted string of characters
    '
    Repeat
    USBOut 3, " Quoted String\n\r", Auto ' Poll the USB and Transmit the buffer from endpoint 3
    Until Carry_Flag = 0 ' Keep trying if the microcontroller does not have control over the buffer
    '
    ' Transmit 12 characters from a code memory String
    '
    Repeat
    USBOut 3, Code_String, 12 ' Poll the USB and Transmit only 12 characters of the buffer from endpoint 3
    Until Carry_Flag = 0 ' Keep trying if the microcontroller does not have control over the buffer

    __USBOut_Buffer = "\n\rVAR1 = " + Str$(Dec,MyWord) + "\n\r" ' Convert MyWord into a string
    '
    ' Transmit from the USB's internal TX buffer String. Null terminated.
    '
    Repeat
    USBOut 3, __USBOut_Buffer, Auto ' Poll the USB and Transmit the buffer from endpoint 3
    Until Carry_Flag = 0 ' Keep trying if the microcontroller does not have control over the buffer
    Inc MyWord
    Wend ' Go wait for the next buffer input

    '------------------------------------------------------------------------------------------------

    [/PHP]

    When connected to the PC it installs Crownhills "Proton CDC Virtual Com Port" driver. Your Terminal program should then see it as a com port.
    There is a handy usb utility on the web USBView available from
    http://code.msdn.microsoft.com/windowshardware/
    Dick
  • Recent Activity

    moonshadow-72867

    Boot loader woes.

    Thread Starter: moonshadow

    For a boot loader to work a number of conditions must be met, all at the same time. My attempt does not work so I have obviously got something...

    moonshadow Today, 14:26 Go to last post
    amod-29593

    Temperature Controller Problem

    Thread Starter: amod

    hi, i had made a digital temperature controller with "j" type thermocouple .Every thing is working fine except Thermocouple break option.I want when...

    amod Yesterday, 19:56 Go to last post