Hacer un ejemplo con PIC y USB directamente

Hola:

Cada vez más veo que a pesar de que los puertos series y paralelo se usan más sobre todas aquellas personas que están aprendiendo a controlar sea con Visual Basic, Visual C#, Visual C++, etc...

Me gustaría saber si alguien tiene experiencia en el tema de USB. Lo bueno que Microchip tiene los controladores par hacerlo más fácil.

Código:
;                            Software License Agreement
;
; The software supplied herewith by Microchip Technology Incorporated (the "Company")
; for its PICmicro(r) Microcontroller is intended and supplied to you, the Company's
; customer, for use solely and exclusively on Microchip PICmicro Microcontroller
; products.
;
; The software is owned by the Company and/or its supplier, and is protected under
; applicable copyright laws. All rights are reserved. Any use in violation of the
; foregoing restrictions may subject the user to criminal sanctions under applicable
; laws, as well as to civil liability for the breach of the terms and conditions of
; this license.
;
; THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, WHETHER EXPRESS,
; IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
; COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
;
; ###############################################################################
;	filename:	DESCRIPT.ASM
;
; This file contains a set of descriptors for a standard mouse.  
;
; ###############################################################################
;
;	Author:			Dan Butler and Reston Condit
;	Company:		Microchip Technology Inc
;
;	Revision:		1.25
;	Date:			23 April 2002
;	Assembled using:	MPASM 2.80
;################################################################################
;
;	include files:
;		P16C765.inc	Rev 1.00
;		usb_defs.inc	Rev 1.10
;
;################################################################################
#include <p16C765.inc>
#include "usb_defs.inc"

USBBANK	code
	global	Config_desc_index
	global	Report_desc_index
	global	Descriptions
	global	string_index
	global	DeviceDescriptor
	global	ReportDescriptor
	global	ReportDescriptorLen
	global	String0
	global	String0_end
	global	StringDescriptions
	global	HID_Descriptor

	extern	EP0_start
	extern	temp		; temp var used in get config index
	extern	temp2 		; another temp, in bank2 

; ******************************************************************
; Given a configuration descriptor index, returns the beginning address
; of the descriptor within the descriptions table
; ******************************************************************
Config_desc_index
	movwf	temp
	movlw	HIGH CDI_start
	movwf	PCLATH
	movlw	low CDI_start
	addwf	temp,w
	btfsc	STATUS,C
	incf	PCLATH,f
	movwf	PCL
CDI_start			; this table calculates the offsets for each 
	retlw	low  Config1	; configuration descriptor from the beginning
	retlw	high Config1	; of the table
	; more configurations can be added here
	; retlw   low Config2
	; retlw   high Config2
	; etc....

; ******************************************************************
; Given a report descriptor index, returns the beginning address
; of the descriptor within the descriptions table
; ******************************************************************
Report_desc_index
	movwf	temp
	movlw	HIGH RDI_start
	movwf	PCLATH
	movlw	low RDI_start
	addwf	temp,w
	btfsc	STATUS,C
	incf	PCLATH,f
	movwf	PCL
RDI_start		; this table calculates the offsets for each report
	retlw	low  ReportDescriptorLen  ; descriptor from the beginning
	retlw	high ReportDescriptorLen  ; of the table, effectively
	; more reports can be added here
	; retlw   low  ReportDescriptorLen2
	; retlw   high ReportDescriptorLen2
	; etc....

; ******************************************************************
; This table is polled by the host immediately after USB Reset has been released.
; This table defines the maximum packet size EP0 can take.
; See section 9.6.1 of the Rev 1.0 USB specification.
; These fields are application DEPENDENT. Modify these to meet
; your specifications.
; the offset is passed in P0 and P1 (P0 is low order byte).
; ******************************************************************
Descriptions
	banksel	EP0_start
	movf	EP0_start+1,w
	movwf	PCLATH
	movf	EP0_start,w
	movwf	PCL

DeviceDescriptor
StartDevDescr
	retlw	0x12		; bLengthLength of this descriptor
	retlw	0x01		; bDescType This is a DEVICE descriptor
	retlw	0x10		; bcdUSBUSB revision 1.10 (low byte)
	retlw	0x01		; high byte
	retlw	0x00		; bDeviceClasszero means each interface operates independently
	retlw	0x00		; bDeviceSubClass
	retlw	0x00		; bDeviceProtocol
	retlw	0x08		; bMaxPacketSize0 - inited in UsbInit()
	retlw	08		; idVendor - 0x04D8 is Microchip Vendor ID
	retlw	0x04		; high order byte
	retlw	0x00		; idProduct
	retlw	0x00
	retlw	0x41		; bcdDevice
	retlw	0x04
	retlw	0x01		; iManufacturer
	retlw	0x02		; iProduct
	retlw	0x00		; iSerialNumber - 3
	retlw	NUM_CONFIGURATIONS	; bNumConfigurations

; ******************************************************************
; This table is retrieved by the host after the address has been set.
; This table defines the configurations available for the device.
; See section 9.6.2 of the Rev 1.0 USB specification (page 184).
; These fields are application DEPENDENT. 
; Modify these to meet your specifications.
; ******************************************************************
Config1
	retlw	0x09		; bLengthLength of this descriptor
	retlw	0x02		; bDescType2 = CONFIGURATION
	retlw	EndConfig1 - Config1
	retlw	0x00
	retlw	0x01		; bNumInterfacesNumber of interfaces
	retlw	0x01		; bConfigValueConfiguration Value
	retlw	0x04		; iConfigString Index for this config = #01
	retlw	0xA0		; bmAttributesattributes - bus powered
	retlw	0x32		; MaxPowerself-powered draws 0 mA from the bus.
Interface1
	retlw	0x09		; length of descriptor
	retlw	INTERFACE
	retlw	0x00		; number of interface, 0 based array
	retlw	0x00		; alternate setting
	retlw	0x01		; number of endpoints used in this interface
	retlw	0x03		; interface class - assigned by the USB
	retlw	0x01		; boot device
	retlw	0x02		; interface protocol - mouse
	retlw	0x05		; index to string descriptor that describes this interface
HID_Descriptor
	retlw	0x09		; descriptor size (9 bytes)
	retlw	0x21		; descriptor type (HID)
	retlw	0x00
	retlw	0x01		; HID class release number (1.00)
	retlw	0x00		; Localized country code (none)
	retlw	0x01		; # of HID class descriptor to follow (1)
	retlw	0x22		; Report descriptor type (HID)
	retlw	(end_ReportDescriptor - ReportDescriptor)
	retlw	0x00
Endpoint1
	retlw	0x07		; length of descriptor
	retlw	ENDPOINT
	retlw	0x81		; EP1, In
	retlw	0x03		; Interrupt
	retlw	0x04		; max packet size (4 bytes) low order byte
	retlw	0x00		; max packet size (4 bytes) high order byte
	retlw	0x0A		; polling interval (10ms)
EndConfig1

ReportDescriptorLen
	retlw	low (end_ReportDescriptor-ReportDescriptor)

ReportDescriptor
	retlw	0x05
	retlw	0x01		; usage page (generic desktop)
	retlw	0x09
	retlw	0x02		; usage (mouse)
	retlw	0xA1
	retlw	0x01		; collection (application)
	retlw	0x09
	retlw	0x01		;usage (pointer)
	retlw	0xA1
	retlw	0x00		;collection (linked)
	retlw	0x05
	retlw	0x09		; usage page (buttons)
	retlw	0x19
	retlw	0x01		; usage minimum (1)
	retlw	0x29
	retlw	0x03		; usage maximum (3)
	retlw	0x15
	retlw	0x00		; logical minimum (0)
	retlw	0x25
	retlw	0x01		; logical maximum (1)
	retlw	0x95
	retlw	0x03		; report count (3)
	retlw	0x75
	retlw	0x01		; report size (1)
	retlw	0x81
	retlw	0x02		; input (3 button bits)
	retlw	0x95
	retlw	0x01		; report count (1)
	retlw	0x75
	retlw	0x05		; report size (5)
	retlw	0x81
	retlw	0x01		; input (constant 5 bit padding)
	retlw	0x05
	retlw	0x01		; usage page (generic desktop)
	retlw	0x09
	retlw	0x30		; usage (X)
	retlw	0x09
	retlw	0x31		; usage (Y)
	retlw	0x15
	retlw	0x81		; logical minimum (-127)
	retlw	0x25
	retlw	0x7F		; logical maximum (127)
	retlw	0x75
	retlw	0x08		; report size (8)
	retlw	0x95
	retlw	0x03		; report count (2)
	retlw	0x81
	retlw	0x06		; input (2 position bytes X & Y)
	retlw	0xC0		; end collection
	retlw	0xC0		; end collection
end_ReportDescriptor
	
StringDescriptions
	banksel	EP0_start
	movf	EP0_start+1,w
	movwf	PCLATH
	movf	EP0_start,w
	movwf	PCL

; ******************************************************************
; Given a configuration descriptor index, returns the beginning address
; of the descriptor within the descriptions table
; ******************************************************************
string_index	; langid in W reg, string offset in EP0_start
	movwf	temp
	bcf 	STATUS,C
	rlf 	temp, f
	pagesel	langid_index
	call	langid_index
	movwf	temp2
	incf	temp, f
	pagesel	langid_index
	call	langid_index
	movwf	temp

	movf	temp, w
	movwf	PCLATH
	movf	temp2,w
	addwf	EP0_start+1,w
	btfsc	STATUS,C
	incf	PCLATH, f
	movwf	PCL

langid_index
	movlw	high langids
	movwf	PCLATH
	movlw	low langids
	addwf	temp, w
	btfsc	STATUS,C
	incf	PCLATH,f
	movwf	PCL

langids
	retlw	low lang_1
	retlw	high lang_1
	retlw	low lang_2	; string indexes of different languages
	retlw	high lang_2

lang_1	; english
	retlw	low  String0	; LangIDs
	retlw	high String0
	retlw	low  String1_l1
	retlw	high String1_l1
	retlw	low  String2_l1
	retlw	high String2_l1
	retlw	low  String3_l1
	retlw	high String3_l1
	retlw	low  String4_l1
	retlw	high String4_l1
	retlw	low  String5_l1
	retlw	high String5_l1
	retlw	low  String6_l1
	retlw	high String6_l1

lang_2
	retlw	low  String0	; also point to LangID
	retlw	high String0
	retlw	low  String1_l2
	retlw	high String1_l2
	retlw	low  String2_l2
	retlw	high String2_l2
	retlw	low  String3_l2
	retlw	high String3_l2
	retlw	low  String4_l2
	retlw	high String4_l2
	retlw	low  String5_l2
	retlw	high String5_l2

String0
	retlw	low (String1_l1 - String0)	; length of string 
	retlw	0x03		; descriptor type 3?
	retlw	0x09		; language ID (as defined by MS 0x0409)
	retlw	0x04
	retlw	0x04		; some other language ID for testing
	retlw	0x08
String0_end
String1_l1
	retlw	String2_l1-String1_l1	; length of string
	retlw	0x03		; string descriptor type 3
	retlw	'M'
	retlw	0x00
	retlw	'i'
	retlw	0x00
	retlw	'c'
	retlw	0x00
	retlw	'r'
	retlw	0x00
	retlw	'o'
	retlw	0x00
	retlw	'c'
	retlw	0x00
	retlw	'h'
	retlw	0x00
	retlw	'i'
	retlw	0x00
	retlw	'p'
	retlw	0x00
String2_l1
	retlw	String3_l1-String2_l1
	retlw	0x03
	retlw	'P'
	retlw	0x00
	retlw	'i'
	retlw	0x00
	retlw	'c'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'6'
	retlw	0x00
	retlw	'C'
	retlw	0x00
	retlw	'7'
	retlw	0x00
	retlw	'4'
	retlw	0x00
	retlw	'5'
	retlw	0x00
	retlw	'/'
	retlw	0x00
	retlw	'7'
	retlw	0x00
	retlw	'6'
	retlw	0x00
	retlw	'5'
	retlw	0x00
	retlw	' '
	retlw	0x00
	retlw	'U'
	retlw	0x00
	retlw	'S'
	retlw	0x00
	retlw	'B'
	retlw	0x00
	retlw	' '
	retlw	0x00
	retlw	'M'
	retlw	0x00
	retlw	'o'
	retlw	0x00
	retlw	'u'
	retlw	0x00
	retlw	's'
	retlw	0x00
	retlw	'e'
	retlw	0x00
String3_l1
	retlw	String4_l1-String3_l1
	retlw	0x03
	retlw	'V'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'.'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'1'
	retlw	0x00
String4_l1
	retlw	String5_l1-String4_l1
	retlw	0x03
	retlw	'C'
	retlw	0x00
	retlw	'f'
	retlw	0x00
	retlw	'g'
	retlw	0x00
	retlw	'1'
	retlw	0x00
String5_l1
	retlw	String6_l1-String5_l1
	retlw	0x03
	retlw	'E'
	retlw	0x00
	retlw	'P'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'0'
	retlw	0x00
	retlw	'I'
	retlw	0x00
	retlw	'n'
	retlw	0x00
String6_l1
	
String1_l2	; lang 2, chinese. String can be totally different than english
	retlw	String2_l2-String1_l2	; length of string
	retlw	0x03		; string descriptor type 3
	retlw	'M'
	retlw	0x00
	retlw	'i'
	retlw	0x00
	retlw	'c'
	retlw	0x00
	retlw	'r'
	retlw	0x00
	retlw	'o'
	retlw	0x00
	retlw	'c'
	retlw	0x00
	retlw	'h'
	retlw	0x00
	retlw	'i'
	retlw	0x00
	retlw	'p'
	retlw	0x00
String2_l2
	retlw	String3_l2-String2_l2
	retlw	0x03
	retlw	'P'
	retlw	0x00
	retlw	'i'
	retlw	0x00
	retlw	'c'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'6'
	retlw	0x00
	retlw	'C'
	retlw	0x00
	retlw	'7'
	retlw	0x00
	retlw	'4'
	retlw	0x00
	retlw	'5'
	retlw	0x00
	retlw	'/'
	retlw	0x00
	retlw	'7'
	retlw	0x00
	retlw	'6'
	retlw	0x00
	retlw	'5'
	retlw	0x00
	retlw	' '
	retlw	0x00
	retlw	'U'
	retlw	0x00
	retlw	'S'
	retlw	0x00
	retlw	'B'
	retlw	0x00
	retlw	' '
	retlw	0x00
	retlw	'M'
	retlw	0x00
	retlw	'o'
	retlw	0x00
	retlw	'u'
	retlw	0x00
	retlw	's'
	retlw	0x00
	retlw	'e'
	retlw	0x00
String3_l2
	retlw	String4_l2-String3_l2
	retlw	0x03
	retlw	'V'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'.'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'1'
	retlw	0x00
String4_l2
	retlw	String5_l2-String4_l2
	retlw	0x03
	retlw	'C'
	retlw	0x00
	retlw	'f'
	retlw	0x00
	retlw	'g'
	retlw	0x00
	retlw	'1'
	retlw	0x00
String5_l2
	retlw	String6_l2-String5_l2
	retlw	0x03
	retlw	'E'
	retlw	0x00
	retlw	'P'
	retlw	0x00
	retlw	'1'
	retlw	0x00
	retlw	'0'
	retlw	0x00
	retlw	'I'
	retlw	0x00
	retlw	'n'
	retlw	0x00
String6_l2

	end

Lo puedes ver aquí en los primeros enlaces.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1410

Saludo.
 
¿Esto se supone que es la libreria que tiene que tener el pic para enviar datos através del puerto usb?.

¿Esta libreria sirve para enviar y recibir, o solo para enviar?.

¿Hasta que punto se pueden hacer cosas con ella?
 
Los pic 18F comparten el juego de instrucciones de los 16F, no? Si es asi sería cuestión de ver si los registros del 16C765 son compatibles para poder pasar ese código a un 18f2550
 
Trabajas rápido.
Encambio yo, MPLAB con ASM y Visual C# para aplicaciones de PC.
Lo del usb lo veo complicado sea en asm o C. Bueno, si hacen algún ejemplo de Visual Basic, C#, C++ relacionado con pic sea de usb, db9 o db25 nos avisas para ver el proyecto.
 
yo estoy preparando lo del usb para pic para postear, visual basic estoy aprendiendo de a poco

yo de asm mucho la verdad nose , me manejo muchisimo mejor con de c de ccs. Me conpre el libro del pic16f84a para aprender pero no he tenido mucho tiempo , ahora en las vacaciones de verano me pongo a full con los pics.
 
Buenas! Yo en mi trabajo de grado tambien tengo q utilizar el puerto USB con el 18F4550 y aun no tengo mucha información de como hacerlo. Tengo entendido q el USB tiene unas cuatans clases, una de ellas es un emulador del RS232 (q por desgracia mi tutor no creo q me vaya a dejar utilizar!), el HID y tambien el Bulk. Yo necesito hacer un especie de osciloscopio, que clase del USB me recomendarian utilizar? el HID o el BULK? se q eciste un programa llamado easyHID q genera el codigo tanto para la pc como para el pic, el problema es q lo genera en basic ... y yo estoy programando en ccs, asi q eso no me serviria de mucho. Sera q alguine podria suministrame información q pueda ayudarme con mis dudas, como tambien algo q me pueda guiar de alguna forma para realizar mi proyecto. Agradesco cualquier ayuda!

Saludos!
 
holaa a todos yo ya he realizados comunicaciones con usb con la familia 18FXX50

te aconsejos que programas con CCS C Compiler ya que traen incluidas la libreria usb.h y el pic18_usb.h
eso lo hace mas fal ademas tienes que configurar tu descriptores que tambien la inluclues en medio de esas dos librerias
pic18_usb.h
el nombre.h
usb.h
por el momento intala ese programa y te vas a la ayuda tiene ejemplos que te pueden servir


saludos
 
Hola adrianjpc! como hicistes la comunicacion, HID o BULK? yo todavia no entiendo cual es la diferencia entre los dos? Se que el HID hace que la PC trate al dispositivo como si fuera un teclado o un mouse, y que el BULK trata al dispositivo como uno de trasferencia masiva de información, pero noseq diferencia hay en la transferencia de información, por q yo voy a hacer un especia de osciloscopio por puerto USB asi q necesito la maxima velocidad de transferencia de información posible. Se q una de las formas mas faciles de trabajar con el puerto USB es a traves de la emulacion a RS232 y yo creo q no me dejarian usar eso, tal vez por la velocidades, alguien q me pueda aconsejar
 
asi es mephisto0000 la diferencia de las dos es
HID: lo reconoce la maquina sin necesidad de driver y su velocidad es muy baja no se recomienda.
Bulk: es las mas rapidas de todas alcanza una velocidad de (480Mb/s) y si necesita de controladores. regularmente se hace uso de las librerias de microchip ya bien con su respectivo drivers solo lo editas a tu manera.


saludos
 
adrianjpc dijo:
asi es mephisto0000 la diferencia de las dos es
HID: lo reconoce la maquina sin necesidad de driver y su velocidad es muy baja no se recomienda.
Bulk: es las mas rapidas de todas alcanza una velocidad de (480Mb/s) y si necesita de controladores. regularmente se hace uso de las librerias de microchip ya bien con su respectivo drivers solo lo editas a tu manera.


saludos

¿Sabes hacer por USB controlar 8 salidas independiente con el 18Fx550?

Para que te haga una idea, estoy haciendo lo mismo pero por puerto serie.

https://www.forosdeelectronica.com/posts/199347/

DESCARGA

Si puedes, entre todos hacemos eso en USB y haremos un tutorial paso a paso de cómo se hace, yo lo pasaré a PDF como hice con algunos manuales que puedes ver aquí.

http://www.abcdatos.com/tutoriales/tutorial/z9521.html

Saludo.

PD: Me imagino cuando saquen dentro de poco el USB 3.0, www.microchip.com está al tanto de ello, al final incluido yo me pasaré del 18Fx550 a los nuevos PIC.
 
por alli estoy escribiendo un tutorial de como prgramar el pic18f4550 para establecer la comunicacion usb

ademas agregare como utizarlo con sofware como matlab, labview , Visual C, C#, etc.
 
Muchas gracias.

Una pregunta tonta. ¿En qué se diferencia del MatLab con el LabView? Para mi son similares.

Esperando ese manual...

Saludo.
 
la diferencia es mucha que en labview programas en grafico y matlab en C

otro punto importante que en matlab solo puedes hacerlo emulando el puerto serial y en labview usb normal 2.0 de tipo bulk

por alli tengo unas ideas de como hacerlo en matlab de tipo bulk abri un tema en este mismo foro
y solo eh logrado saber la vercion y cuando mis dispositivo esta conectado y desconectado es lo mas a lo que eh llegado en matlab
 
Atrás
Arriba