PIC18F14K50: Registro de Desplazamiento (Shift Register) – 74HC595

Page 1

Por: Omar Gurrola

3/02/13

http://www.proprojects.wordpress.com

PIC18F14K50: Registro de Desplazamiento (Shift Register) – 74HC595 Los registros de desplazamiento son integrados que reciben los datos en serie y los refleja en un puerto de forma paralela. La ventaja de utilizar estos integrados es la reducción de pines, ya que con tan solo tres pines se puede administrar 8 pines del IC. Otra ventaja es la conexión en cascada donde se puede administrar más de un IC con los mismos tres pines. Para esta sección trabajaremos con el registro de desplazamiento 74HC595 de TI, es un integrado barato y fácil de conseguir. Los pines del integrado y las funciones de sus pines son:

Dónde:  SER: Donde entran los bits de forma serie  SRCLK: Recibe el reloj para el shift register.  /SRCLR: Es para borrar el shift register.  RCLK: Recibe el reloj para el storage register.  /OE: Sirve para activar o desactivar las salidas QA-QH. La forma más sencilla para controlar este integrado es utilizando tres pines únicamente, por lo tanto:  

/SRCLR: Conectarlo a alto o voltaje para no borrar el shift register. /OE: Conectarlo a bajo o tierra para que siempre estén las salidas activadas.


Por: Omar Gurrola

3/02/13

http://www.proprojects.wordpress.com

La l贸gica para mandar los datos es muy sencilla: 1. Al iniciar se debe poner los datos en su valor default que son: a. SRCLK = 0 b. RCLK = 0 2. Extraer el bit a enviar, SER = bit 3. Esperar un tiempo. 4. SRCLK = 1 para escribir el bit en el shift register. 5. Esperar un tiempo. 6. SRCLK = 0 para dejar el reloj en default. 7. Esperar un tiempo. 8. Repetir del paso 2 hasta 7 por cada uno de los ocho bits a enviar. 9. RCLK = 1 para que los datos guardados en el shift register sean mostrados en el puerto. 10. Esperar un tiempo. 11. RCLK = 0 para dejar el reloj en default. 12. Esperar un tiempo. Para este ejemplo controlaremos dos registros de desplazamiento (16 bits) y realizaremos el corrimiento de derecha a izquierda de un bit y viceversa, utilizando LEDs. main.c /* * * * * * * * * * * * * * * * * * * * * * */

Copyright (c) 2011-2013, http://www.proprojects.wordpress.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1.- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2.- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/********************************************************************************** * Author: Omar Gurrola * Site: http://www.proprojects.wordpress.com * Processor: PIC18 * Compiler: C18 v3.45 * File Name: main.c * Description: Main program * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Rev. Date Comment * 1.0 04/01/12 Initial version * 1.1 01/29/13 Remove ISR prototipes, they are declared in hid_bl.h *********************************************************************************/ /** INCLUDES *******************************************************/ #include <p18f14k50.h> #include "pic18f14k50_cbits.h" #include "pic18f14k50_io.h" #include "stdvars.h" #include "wait.h" #include "stp.h" /** PROTOTYPES *****************************************************/ /** VARIABLES ******************************************************/ /** DECLARATIONS ***************************************************/


Por: Omar Gurrola #pragma code

3/02/13

http://www.proprojects.wordpress.com

// Forces the code below this line to be put into the code section (Memory Adress >= 0x'REMDIR'02A)

/** Interrupt Service Routines (ISR)********************************/ #pragma interrupt HighPriorityISR void HighPriorityISR (void){ //Check which interrupt flag caused the interrupt. //Service the interrupt //Clear the interrupt flag //Etc. } //This return will be a "retfie fast", since this is in a #pragma interrupt section #pragma interruptlow LowPriorityISR void LowPriorityISR (void){ //Check which interrupt flag caused the interrupt. //Service the interrupt //Clear the interrupt flag //Etc. }

//This return will be a "retfie", since this is in a #pragma interruptlow section

void main(void){ u8 c; u16 data; OSCCONbits.IRCF = 0b110; OSCTUNEbits.SPLLEN = 1;

// Poscaler selected to 8 MHz // PLLx4 Enable System FQ = 32 MHz

STPInit(); while(true){ data = 0x0001; for(c=0; c < 15; c++){ STPSend(data); STPSend(data >> 8); data <<= 1; Waitmsx(50); } data = 0x8000; for(c=0; c < 15; c++){ STPSend(data); STPSend(data >> 8); data >>= 1; Waitmsx(50); } } // end while } // end main()

// Send LSB // Send MSB

// Send LSB // Send MSB


Por: Omar Gurrola Diagrama esquemático:

3/02/13

http://www.proprojects.wordpress.com

Circuito armado:

Referencias 

Microchip, “PIC18F/LF1XK50 Data Sheet”, 2010, http://ww1.microchip.com/downloads/en/DeviceDoc/41350E.pdf

Texas Instrument, “8-BIT SHIFT REGISTERS WITH 3-STATE OUTPUT REGISTERS - Datasheet”, 2009 http://www.ti.com/lit/ds/symlink/sn74hc595.pdf

DrLuke, “Can you move over? The 74HC595 8 bit shift register”, 2012 http://bildr.org/2011/02/74hc595/


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.