# 3 - Corrimiento de Bits

> ####
>
> #### MPLAB X IDE - XC8 Compiler
>
> [**PIC18F4550 / PIC18F45K50**](https://docs.microside.com/practicas/mplab-x-ide/xc8-compiler/pic18f4550-or-pic18f45k50)

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2F5PzN6EyjW1rjGRdWEXc7%2F3%20-%20Corrimiento%20de%20bits.png?alt=media&#x26;token=3d7012f9-9458-4c9e-adbf-1d4fa0f6f3d7" alt=""><figcaption></figcaption></figure>

## **Introducción**

En esta práctica se implementa un corrimiento de bits, el cual se despliega a través de LEDs.

## **Descripción**

En esta práctica se implementa un corrimiento de bits usando la tarjeta **X-TRAINER** con el **PIC18F4550/PIC18F45K50**. Para visualizar el resultado se conectan 8 LEDs al puerto B de la tarjeta **X-TRAINER.**

**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 Módulo programador **XCU** o **XCU Lite.** [**Manuales**](https://docs.microside.com/programadores-pics-and-avrs/pic-and-avr) **|** [**Comprar**](https://www.microside.com/shop/category/programadores-pics-avrs-15)

8 x Resistencias 220 ohms.

8 x LEDs.

1 x Protoboard de 830 puntos.

1 x Juego de cables Dupont.

1 x Cable micro USB.

**Software:**

Windows 7 o posterior.

MPLAB X IDE. [**Descarga**](https://www.microchip.com/mplab/mplab-x-ide)

Compilador XC8. [**Descarga**](https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-xc-compilers)

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)

MPLAB Code Configurator. (**Solo para PIC18F45K50**)

## **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 **MPLAB X IDE** y crea un nuevo proyecto con el código fuente que se encuentra en el apartado "[**Código**](#codigo)".
3. Si cuentas con un **PIC18F45K50** ejecuta MCC (MPLAB Code Configurator) y configura los diferentes apartados como lo muestran las siguientes imágenes.

{% hint style="warning" %}
En caso de utilizar un **PIC18F4550** omite este paso.&#x20;
{% endhint %}

* [**Project Resources**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FuEZSVoGwHWRqfeqe6vQK%2FProject_Resources.webp?alt=media\&token=f85451f2-4649-43a6-ac00-5c9ccee992c6)
* [**System Module**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FC6ojge7ryPi2OcAKxsYD%2FComun%20System%20module.webp?alt=media\&token=b82ed185-a2da-44f8-89a7-fb5245769117)
* [**Device Resources**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2F7gO2hUCwNSkYpIzQoPu2%2FComun%20Device%20Resource.webp?alt=media\&token=0eef8588-1608-4550-8b5a-f7c3c24bdde3)
* [**Pin Manager**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FKWdQxeC0ZeJ1LTIYCz5l%2F3_PIN_MANAGER.webp?alt=media\&token=650bad66-2000-49a9-9272-4ec58de22d2f)
* [**Pin Module**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FjynR4llonCbtTXVeuDoV%2F3_PIN_MODULE.webp?alt=media\&token=7c131603-6d37-4236-8439-8d745263daa7)

{% hint style="success" %}
Si tienes dudas de cómo realizar los pasos anteriores puedes encontrar un manual de **MCC (MPLAB Code Configurator)** a través del siguiente [**link**](https://docs.microside.com/practicas/ides/mplab-code-configurator-mcc-mplab-x-ide).
{% endhint %}

4. Realiza los siguientes pasos para configurar el **bootloader** y poder programar la tarjeta **X-TRAINER**:

* Da clic en ***File*** y ***Project Properties***.

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FmWA48vgz0NiwtZUS2t0b%2FFILE%20MPLAB%20X%20IDE%20-%20PIC18F45K50%20PIC18F4550%20MICROSIDE.png?alt=media&#x26;token=1073ea96-9c9a-40bf-ad99-3c55b3c61d9f" alt=""><figcaption></figcaption></figure>

* Selecciona ***Building***, marca la casilla ***Insert unprotected checksum in user ID memory*** y da clic en ***Apply***.

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FEEnYQ91dO2MU0NQ1Kc7M%2FPROJECT%20PROPERTIES%20MPLAB%20X%20IDE%20-%20PIC18F45K50%20MICROSIDE.png?alt=media&#x26;token=b7360a4e-027d-41ff-a912-72edfc3db42a" alt=""><figcaption></figcaption></figure>

* Selecciona ***XC8 Linker***, despliega el apartado ***Option categories***: y selecciona ***Memory model**.* \
  En la sección de ***ROM ranges*** escribe **2000-7f00** y da clic en ***Apply***.

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FLlDc2LiPzzFpFtGgxZZY%2FPROJECT%20PROPERTIES%20MPLAB%20X%20IDE%20-%20%20XC8%20LINKER%20PIC18F45K50%20MICROSIDE.png?alt=media&#x26;token=6118558c-4826-4142-a064-8d103dfad597" alt=""><figcaption></figcaption></figure>

* Despliega nuevamente el apartado ***Option categories:*** y selecciona ***Additional options***. En la sección de ***Codeoffset*** escribe **2000**, da clic en ***Apply*** y por último da clic en ***OK***.

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FBBaB5FSH2wKhN03CPOZy%2FPROJECT%20PROPERTIES%20MPLAB%20X%20IDE%20-%20%20XC8%20LINKER%20ADDITIONAL%20OPTIONS%20PIC18F45K50%20MICROSIDE.png?alt=media&#x26;token=0b87aaa0-9361-42f1-8bf0-ed43cfc52447" alt=""><figcaption></figcaption></figure>

5. Una vez realizadas las configuraciones del bootloader compila el proyecto.

{% hint style="success" %}
Para compilar el proyecto dirígete a la barra de herramientas superior y da clic en el icono señalado.
{% endhint %}

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FaeLeCBrggmC8icPqUlU8%2FMPLAB%20X%20IDE%20COMPILACION%20MICROSIDE.png?alt=media&#x26;token=c473944c-57f1-436f-96c7-b5a9533ef719" alt=""><figcaption></figcaption></figure>

6. 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 %}

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

## **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/3-Bit-shift-MPLAB-X-IDE-XC8-COMPILER-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_Lite-M-r2_Practica-3_Microside_02.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

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

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FGww3UN0eLDgq7I8O1t7Q%2FCorrimiento%20de%20Bits%20PIC18F44550%20o%20PIC18F45K50%20%20LITE%20M%20MICROSIDE.webp?alt=media&#x26;token=3cacc11f-586b-4908-ba23-800da8aabc0a" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="LITE F" %}

<figure><img src="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/3-Bit-shift-MPLAB-X-IDE-XC8-COMPILER-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_LITE-F_Practica-3_Microside_01.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="DIP" %}

<figure><img src="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/3-Bit-shift-MPLAB-X-IDE-XC8-COMPILER-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_DIP_Practica-3_Microside_01.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="DIP R3" %}

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FdgLU9rz8SSw52OSp0rGZ%2Fhands-on-pic18f-p3-x-trainer-dip-r3.png?alt=media&#x26;token=8b72c25c-f35a-4a00-b4a5-3bd115a9bc08" alt=""><figcaption></figcaption></figure>

{% endtab %}

{% tab title="PRO R2" %}

<figure><img src="https://raw.githubusercontent.com/MICROSIDE-TECHNOLOGY/3-Bit-shift-MPLAB-X-IDE-XC8-COMPILER-PIC18F4550-45K50/main/Diagrama%20de%20conexi%C3%B3n/X-TRAINER_PRO-r2_Practica-3_Microside_01-1.png" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="PRO R3" %}

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2F72PXKfcL2ROQBDwFCBO6%2F3%20Corrimiento%20de%20Bits%20X%20Trainer%20Pro%2018.png?alt=media&#x26;token=3db6f2e3-6e48-40aa-b6c0-434d2b99e2da" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="PRO R4 " %}

<figure><img src="https://177299348-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2Fx3ihmQtCDJSAL1V0KdQp%2FCorrimiento%20de%20Bits%20%20PIC18F4550%20%20o%20PIC18F45K50%20X-TRAINER%20PRO%20R4%20MICROSIDE.webp?alt=media&#x26;token=bcf16d18-d7fa-4422-a86f-c3fd5a45cf19" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## **Código**

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

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

{% tab title="PIC18F45K50" %}
{% embed url="<https://gist.github.com/microside-mx/2acc8f213c80bbf6df30692865ce69f4>" %}
{% 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/3-Bit-shift-MPLAB-X-IDE-XC8-COMPILER-PIC18F4550-45K50/archive/refs/heads/main.zip">https://github.com/MICROSIDE-TECHNOLOGY/3-Bit-shift-MPLAB-X-IDE-XC8-COMPILER-PIC18F4550-45K50/archive/refs/heads/main.zip</a></td></tr></tbody></table>
