USB Interface using PIC


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default USB Interface using PIC

    Has anyone used a PIC to develop a USB Interface. From what i have read the 16C745 which has a USB interface onboard is not flashable. Is there another alternative, preferably easily obtainable in the UK.

    I would, at this stage, like to use a Windows GUI (Via VB) to switch outputs on the PIC to HIGH and LOW as selected.

    Can anyone help in this quest.

    Many thanks,

    Steve

  2. #2
    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.

  3. #3


    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?

  4. #4
    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

  5. #5


    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

  6. #6
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Having now got my USB PICs for development (all of the 18F USB Series), are there any examples of how to switch the outputs of the PIC HIGH or LOW as driven by the PC.

    I'm looking at an application where by the front end is developed using VB, but then the control is by the PIC. So VB sends a command to the PIC to make a desired PORT HIGH or LOW.

    It seems fairly simple in its concept, but i can't find any examples of this on the WEB / Forums.

    Any help / pointers would be appriciated.

    Thanks.

    Steve.

  7. #7
    OXIMBIT's Avatar
    OXIMBIT Guest


    Did you find this post helpful? Yes | No

    Default

    Aren't there any examples included with the compiler?

  8. #8
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Not as far as im aware, but i may be wrong. They just seem to be about complex data transfer opposed to simple switching commands.

    Of course if you are aware of any, then please correct me if i'm wrong.

    I'm using PicBasic Pro.

    Many thanks,

    Steve

  9. #9
    OXIMBIT's Avatar
    OXIMBIT Guest


    Did you find this post helpful? Yes | No

    Default

    The Compiler I'm using has many demos including one to Implement the functionality of a Jan Axelson demo which flashes Leds at the Pic end in response to inputs made at the PC. And I just remembered one where as I move my mouse pointer of a picture of a Prototype board the Led's light up on the real board.

    I can only suggest you contact Melabs for more help.
    Last edited by OXIMBIT; - 25th April 2005 at 18:33.

  10. #10
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Sounds like what exactly after. Two questions then, what Compiler are you using and can you send these demos to me on email? I've sent you a PM with my email address.

    Many thanks,

    Steve

  11. #11
    Tgq's Avatar
    Tgq Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Tissy
    Having now got my USB PICs for development (all of the 18F USB Series), are there any examples of how to switch the outputs of the PIC HIGH or LOW as driven by the PC.
    look at this
    http://www.alecmcnamara.freeserve.co.uk/piccalc/
    you find HIDcomm component from Microchip for really easy VB development

  12. #12
    robbenaz's Avatar
    robbenaz Guest


    Did you find this post helpful? Yes | No

    Default facing problem with compiler in usb subject

    i face the error message

    "ERROR: Macro USBINIT? not found in macro file"

    how to solve this problem

    soni

  13. #13
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    if you are german, look at http://www.sprut.de there are the basic for USB & PIC18Fxx55 !
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  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 robbenaz
    i face the error message

    "ERROR: Macro USBINIT? not found in macro file"

    how to solve this problem

    soni
    Tell us wich PIC you're using and post your code here.
    Steve

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

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