Anda di halaman 1dari 3

usb_cdc.

Library for adding a virtual COM port on your PC over USB using the standard Communication Device Class (CDC) specification. Including this file in your code will add all USB code, interrupts, descriptors and handlers required. No other modifications need to be made. This library creates a virtual RS232 link between the PC and the PIC, therefore the library provided will be familiar to anyone with standard UART stream I/O: usb_cdc_kbhit() - Returns TRUE if there is one or more character received and waiting in the receive buffer. usb_cdc_getc() - Gets a character from the receive buffer. If there is no data in the receive buffer it will wait until there is data in the receive buffer. If you do not want to wait in an infinit loop, use usb_cdc_kbhit() first to check if there is data before calling usb_cdc_getc(). usb_cdc_putc(char c) - Puts a character into the transmit buffer. If the transmit buffer is full it will wait until the transmit buffer is not full before putting the char into the transmit buffer. The transmit buffer is read by the PC very quickly, and therefore the buffer should only be full for a few milli-seconds. If you are concerned and don't want to be stuck in a long or infinite loop, use usb_cdc_putready() to see if there is space in the transmit buffer before putting data into the buffer. usb_cdc_putready() - Returns TRUE if there is room left in the transmit buffer for another character. usb_cdc_connected() - Returns TRUE if we received a Set_Line_Coding. On most serial terminal programs (as Hyperterminal), they will send a Set_Line_Coding message when the program starts and it opens the COM port. This is a simple way to determine if the PC is ready to display data on a serial terminal program but is not garaunteed to work all the time or on other terminal programs. usb_cdc_putc_fast(char c) - Similar to usb_cdc_putc(), except if the transmit buffer is full it will skip the char. usb_cdc_line_coding - A structure used for Set_Line_Coding and Get_Line_Coding. Most of the time you can ignore this usb_cdc_break - If the PC has sent a break command, this will hold the break time (in milliseconds). If the PC sends a value of 0xFFFF the device is supposed to hold the break until it sends a value of usb_cdc_carrier - Where Set_Control_Line_State value is stored.Of most relevance is the field dte_present, which is the DTR setting. The following functions are also provided, and are ports of the I/O functions in input.c. See input.c and the CCS manual for documentation: get_float_usb() - Read a float number from the get_long_usb() - Read a long number from the user get_int_usb() - Read an integer number from the get_string_usb(char *s, int max) - Read a string from the user gethex_usb() - Read a byte, in HEX, from the gethex1_usb() - Read a HEX character This driver will load all the rest of the USB code, and a set of descriptors that will properly describe a CDC device for virtual COM port (usb_desc_cdc.h)

An .INF file is provided (cdc_NTXP.inf) that will load the standard CDC drivers for a virtual COM port in Windows NT/2000/XP and above.

usb_cdc. Biblioteca para agregar un puerto COM virtual en el PC a travs de USB utilizando la clase de dispositivo especificacin comunicacin estndar (CDC). La inclusin de este archivo en el cdigo agregar todo el cdigo de USB, interrupciones, descriptores y controladores necesarios. No hay otras modificaciones deben hacerse. Esta biblioteca crea un enlace RS232 virtual entre el PC y el PIC, por lo tanto, la biblioteca siempre ser familiar para cualquiera con el estndar UART corriente I / O: usb_cdc_kbhit () - Devuelve TRUE si hay uno o ms caracteres recibidos y esperando en el bfer de recepcin. usb_cdc_getc () - Obtiene un caracter del buffer de recepcin. Si no hay datos en el bfer de recepcin se va a esperar hasta que haya datos en el buffer de recepcin. Si no quieres esperar en un bucle infinit, utilice usb_cdc_kbhit () primero para comprobar si hay datos antes de llamar usb_cdc_getc (). usb_cdc_putc (char c) - Coloca un carcter en el bfer de transmisin. Si el bfer de transmisin est llena, esperar hasta que el bfer de transmisin no es completa antes de poner el carbn en el bfer de transmisin. La memoria intermedia de transmisin es ledo por el PC muy rpidamente, y por lo tanto el tampn slo debe estar lleno para unos pocos milisegundos. Si le preocupa y no quiere ser atrapado en un bucle de tiempo o infinito, utilice usb_cdc_putready () para ver si hay espacio en el buffer de transmisin antes de poner los datos en el bfer. usb_cdc_putready () - Devuelve TRUE si hay espacio en el bfer de transmisin para otros caracteres. usb_cdc_connected () - Devuelve TRUE si recibimos una Set_Line_Coding. En la mayora de los programas para terminales de serie (como HyperTerminal), se le enviar un mensaje Set_Line_Coding cuando el programa se inicia y abre el puerto COM. Esta es una manera simple de determinar si el PC est listo para mostrar los datos en un programa de terminal serie, pero no se garaunteed que trabajar todo el tiempo o en otro programas de terminal. usb_cdc_putc_fast (char c) - Al igual que usb_cdc_putc (), excepto si el buffer de transmisin est llena, se omitir el carbn. usb_cdc_line_coding - Una estructura utilizada para Set_Line_Coding y Get_Line_Coding. La mayora de las veces se puede pasar por alto este usb_cdc_break - Si el PC ha enviado un comando break, esto mantendr el tiempo de descanso (en milisegundos). Si el PC enva un valor de 0xFFFF el dispositivo se supone que mantenga la pausa hasta que se enva un valor de usb_cdc_carrier - Donde valor Set_Control_Line_State es stored.Of ms relevancia es la dte_present campo, que es la configuracin DTR.

Tambin se ofrecen las siguientes funciones, y son los puertos de las funciones de E / S en input.c. Ver input.c y el manual de CCS para la documentacin: get_float_usb ()-Leer un nmero flotante del usuario get_long_usb () - Leer un largo nmero del usuario get_int_usb () - Leer un nmero entero de la get_string_usb (char * s, int max) - Leer una cadena del usuario gethex_usb () - Lee un byte, en HEX, por parte del usuario gethex1_usb () - Lee un carcter HEX Este controlador se cargar el resto del cdigo de USB, y un conjunto de descriptores que describa adecuadamente un dispositivo CDC para el puerto COM virtual (usb_desc_cdc.h) Se proporciona un archivo. INF (cdc_NTXP.inf) que cargar los controladores CDC estndar para un puerto COM virtual en Windows NT/2000/XP y superiores. http://www.forosdeelectronica.com/f24/control-dispositivos-traves-modulo-usb-pic18f255017458/

https://www.youtube.com/watch?v=tzE8ZMNN858

Anda mungkin juga menyukai