USB Interface using PIC


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    OXIMBIT's Avatar
    OXIMBIT Guest


    Did you find this post helpful? Yes | No

    Default

    The PIC18F4550 has a USB2 interface, it's brilliant!! I can use it behave like a Mouse or use the USB interface as virtual serial port. There are other devices in the USB family as well.
    Last edited by OXIMBIT; - 13th March 2005 at 18:23.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Do you have any example of code, that this pic is show as a virtual com in windows?

  3. #3
    OXIMBIT's Avatar
    OXIMBIT Guest


    Did you find this post helpful? Yes | No

    Default

    Heres some code, It should all convert to Pbpro really easly

    Code:
     
    '
    ' 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.
    '
    	OPTIMISER_LEVEL = 2								' Enable the optimiser at level 2
    	Device = 18F4550								' Choose a device with on-board full speed USB
        XTAL = 48										' Set the oscillator speed to 48MHz (using a 20MHz crystal)
        
        REMINDERS = OFF									' Disable all reminders
        
        LCD_DTPIN = PORTD.4								' LCD data port attached to PORTD
    	LCD_RSPIN = PORTE.0								' LCD RS pin attached to PORTE.0
    	LCD_ENPIN = PORTE.1								' LCD EN pin attached to PORTE.1
    	LCD_INTERFACE = 4								' 4-bit Interface
    	LCD_LINES = 2									' 2 line LCD
    	LCD_TYPE = ALPHANUMERIC							' Use an Hitachi alphanumeric LCD								
            
        USB_DESCRIPTOR = "CDCDESC.INC"					' Point to the CDC DESCRIPTOR file (located in the INC\USB_18 folder)
        
        Dim PP0 As Byte SYSTEM							' USBPOLL status return
        Dim VAR1 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
        
        Symbol CARRY_FLAG = STATUS.0					' High if microcontroller does not have control over the DP buffer
        Symbol TRNIF = UIR.3							' Low if USB Busy
    '------------------------------------------------------------------------
    ' The main program loop starts here 
       
        DelayMS 200											' 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
        
        Repeat												' \
        	USBPoll											'   Wait for the USB interface to become attached
        Until PP0 = %00000110								' /
        
        StrN 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
        
    	VAR1 = 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
            Repeat : Until TRNIF = 1						' Wait for completion before transmitting anything else
    ' 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
            Repeat : Until TRNIF = 1						' Wait for completion before transmitting anything else
    ' 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
            Repeat : Until TRNIF = 1						' Wait for completion before transmitting anything else
    ' Transmit from a NULL terminated code memory String         
            Repeat  
    			USBOut 3, TEXT_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
            Repeat : Until TRNIF = 1						' Wait for completion before transmitting anything else
    ' 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
            Repeat : Until TRNIF = 1						' Wait for completion before transmitting anything else
    ' Transmit 12 characters from a code memory String         
            Repeat
            	USBOut 3, TEXT_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
            Repeat : Until TRNIF = 1						' Wait for completion before transmitting anything else
            
            __USBOUT_BUFFER = "\n\rVAR1 = " + Str$(Dec,VAR1) + "\n\r"  ' Convert VAR1 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
            Repeat : Until TRNIF = 1						' Wait for completion before transmitting anything else
            Inc VAR1 
        Wend												' Go wait for the next buffer input
    	
        
    TEXT_STRING: CData " CODE MEMORY BUFFER\n\r",0

  4. #4


    Did you find this post helpful? Yes | No

    Default

    oke thanx for the info i give it a try only i'm suppriced about how windows will detect this device

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. Reading a slave USB with a pic
    By pcaccia in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th October 2008, 12:00
  3. Replies: 15
    Last Post: - 30th October 2007, 19:25
  4. USB bluetooth interface to PIC
    By naidab in forum Bluetooth
    Replies: 15
    Last Post: - 17th March 2007, 22:37
  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 : 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