> For the complete documentation index, see [llms.txt](https://docs.microside.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.microside.com/practicas/pic-c-compiler-ccs/pic18f4550-or-pic18f45k50/7-usb-cdc.md).

# 7 - USB CDC

> **PIC C Compiler CCS**
>
> [**PIC18F4550 / PIC18F45K50**](https://docs.microside.com/practicas/pic-c-compiler-ccs/pic18f4550-or-pic18f45k50)

<figure><img src="/files/lqw114I38RhkHCJw87w5" alt=""><figcaption></figcaption></figure>

## **Introducción**

En esta práctica se implementa una comunicación USB configurada como CDC (Comunications Devices Class) emulando un puerto serial UART, mediante comandos se controla un LED y se obtiene una lectura del estado lógico del push button integrado llamado BOOT.

## **Descripción**

En esta práctica se realiza la conexión con el puerto USB (Universal Serial Bus) configurado en clase CDC (Comunications Devices Class) emulando un puerto serial, el cual envía indicaciones para el encendido y apagado de un LED, también pregunta el estado de un push button usando el módulo **X-TRAINER** con el **PIC18F4550/PIC18F45K50**. Para encender el LED se envía el número 1, si se desea apagar se envía el número 0. Para recibir el estado del push button “BOOT”, se envía el signo “?”, si está presionado recibe el número 1, en caso contrario se recibe el número 0.

**Materiales:**

1 x Tarjeta **X-TRAINER**. [**Manuales**](https://docs.microside.com/tarjetas-de-desarrollo/x-trainer) | [**Comprar**](https://www.microside.com/shop/category/entrenadores-pic-1)

1 x Cable micro USB.

**Software:**

Windows 8.1 o posterior.

PIC C Compiler v5.069 o posterior. [**Descarga**](http://www.ccsinfo.com/ccsfreedemo.php)

X-TRAINER Suite v1.0 [**Descarga**](https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/microside_download_archive/main/Tools/X-TRAINER%20Suite/X-TRAINER%20Suite%20Setup.zip)

Software Hercules [**Descarga**](https://www.hw-group.com/software/hercules-setup-utility)

## **Procedimiento**

**1.** En el apartado de “[**Diagrama Esquemático**](#diagrama-esquematico)” selecciona el modelo de tu tarjeta, realiza las conexiones que se muestran en la imagen y conéctala a la computadora.

{% hint style="info" %}
Las conexiones mostradas en los diagramas esquemáticos son las mismas ya sea que la tarjeta **X-TRAINER** posea el **PIC18F4550** o el **PIC18F45K50**.
{% endhint %}

**2.** Ejecuta **PIC C Compiler**, crea un nuevo proyecto con el código fuente que se encuentra en el apartado "[**Código**](#codigo)" y compila el programa.

{% hint style="success" %}
Si tienes dudas de cómo realizar los pasos anteriores puedes encontrar un manual de **PIC C Compile**r a través del siguiente [**link**](https://docs.microside.com/practicas/ides/pic-c-compiler-ccs).
{% endhint %}

**3.** Abre el **Software X-TRAINER Suite v1.0** en el apartado **PIC18F4550/45K50**, selecciona el archivo .hex generado al compilar el proyecto y programa la tarjeta.

{% hint style="success" %}
Si tienes dudas de cómo realizar los pasos anteriores puedes encontrar un manual del **Software X-TRAINER Suite v1.0**. a través del siguiente[ **link**](https://docs.microside.com/tarjetas-de-desarrollo/software-x-trainer-suite).
{% endhint %}

**4.** Al terminar de programar, la tarjeta **X-TRAINER** se reiniciará automáticamente y se ejecutará el programa de esta práctica.

**5.** En el Software Hercules, abre el apartado “Serial” para lograr la comunicación con el módulo convertidor USB a Serial UART y envía los caracteres de esta práctica. En el siguiente [**link**](https://microside.com/wp-content/uploads/2021/12/Hercules-enviando-un-0.png) encontrarás una imagen de referencia del envío de comandos a través del software Hercules.

## **Diagrama esquemático**

Selecciona el modelo de tu tarjeta **X-TRAINER.**

{% tabs %}
{% tab title="LITE M R2" %}

<figure><img src="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/7-USB_CDC-CCS-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_Lite-M-r2_Practica-7_Microside_02.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="LITE M R3" %}

<figure><img src="/files/JP6ZeO6bXaCa9naSV73x" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="LITE F" %}

<figure><img src="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/7-USB_CDC-CCS-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_LITE-F_Practica-7_Microside_01.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="DIP" %}

<figure><img src="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/7-USB_CDC-CCS-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_DIP_Practica-7_Microside_01.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="DIP R3" %}

<figure><img src="/files/GQ3kNfHLINiAfXUCMANe" alt=""><figcaption></figcaption></figure>

{% endtab %}

{% tab title="PRO R2" %}

<figure><img src="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/7-USB_CDC-CCS-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_PRO-r2_Practica-7_Microside_01-1-e1635258751522.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="PRO R3" %}

<figure><img src="/files/B5R3yRv8H0sztsUnCptp" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="PRO R4" %}

<figure><img src="/files/7gcK1NCUbwVJoQcRPfxJ" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## **Código**

{% tabs %}
{% tab title="PIC18F4550" %}
{% embed url="<https://gist.github.com/microside-mx/d77847031a5c1a32699878e6019ffdd0>" %}
{% endtab %}

{% tab title="PIC18F45K50" %}
{% embed url="<https://gist.github.com/microside-mx/50c27748addf4a74a45b4afd53039288>" %}
{% endtab %}
{% endtabs %}

## **Descargas**

<table data-card-size="large" data-view="cards"><thead><tr><th align="center"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td align="center"><mark style="color:green;"><strong>Software X-TRAINER Suite v1.0</strong></mark></td><td><a href="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/microside_download_archive/main/Tools/X-TRAINER%20Suite/X-TRAINER%20Suite%20Setup.zip">https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/microside_download_archive/main/Tools/X-TRAINER%20Suite/X-TRAINER%20Suite%20Setup.zip</a></td></tr><tr><td align="center"><mark style="color:green;"><strong>Proyecto</strong></mark></td><td><a href="https://github.com/MICROSIDE-TECHNOLOGY/7-USB_CDC-CCS-PIC18F4550-45K50/archive/refs/heads/main.zip">https://github.com/MICROSIDE-TECHNOLOGY/7-USB_CDC-CCS-PIC18F4550-45K50/archive/refs/heads/main.zip</a></td></tr></tbody></table>
