Etiquetas

555 74HC04 74HC14 74HC165 74LS04 acentos ADC10 Amstrad archivo arduino aristóteles armbian array ass at backup base64 bash Basho bc beethoven Biblia blog bucle c c++ c++11 c++17 C005 cadena Carmina Burana casting CD4017 CD4040 Cine clases Colores connect Consolación a Helvia Consolación a Marcia Consolación a Polibio constante corsair CPC Cristal 32Khz css cursor mouse cut daemon date dead keys Debian directorio disco duro DS32kHz electricidad Electrónica ensamblador entryList epicureismo Estadística estoicismo felicidad ffmpeg filePath filosofia Filosofía firefox flac for fstab funcion Gargantúa gastronomía gilgamesh Ginott gmp gpt grep gtts Hobbes hotkeys html imagemagick inline Javascript kde kernel modulos latex ldr lib-notify Linux Literatura ludoteca macro mapa de bits Matroska mega Microsoft Word Milan Kundera mkvextract mkvinfo mount mp3 mplayer MSP430 msp430F5529 MSP432 Multimedia Musica oop orange_pi pato PIR PL9823 Platón poesía POO en C++ pulseaudio puntero PWM pygame pyqt python QAction qApp QApplication QByteArray QDialog Qdir QFile QFileDialog QImage qlabel QList QListWidget QMessagebox QMouseEvent qpainter QPalette QPixmap QProcess QRegularExpression QRegularExpressionMatchIterator QString QStringList Qt qt5 QToolbar quijote QVector qwidget R Rabelais ratón relé Resonador cerámico samba San Agustín screen Séneca signal slot smart smartctl sox srt static const stdarg.h subtítulos Symbian tar teléfonos móviles temperatura temperatura cpu Temporizador tesseract Timer timestamp Trigonometría tts tutorial uid unicode user USI va_arg va_end va_list va_start velocidad ventilador Voltaire wallpaper xboxdrv xinput xrandr Z80 zip

domingo, julio 14, 2013

Usar un 74HC165 con el MSP430 a través de USI

Conexión:
74HC165           MSP430
QH -------------> P1.7 (SDI)
CLK ------------> P1.5 (SCLK)
PL (o SH/LD) ---> P.1.2 (Cualquier pin vale).


InterruptVectors_init.c
/*
 *  ======== Timer0_A3 Interrupt Service Routine ======== 
 */
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR_HOOK(void)
{
    /* USER CODE START (section: TIMER0_A0_ISR_HOOK) */
    // Pedir al 74hc165 que lea las entradas
    P1OUT &= ~BIT2; // poner pin ld low
    P1OUT |= BIT2; // poner pin ld hight

    //Pedir al USI que lea 8 bits
    USICNT |= 8;

    /* USER CODE END (section: TIMER0_A0_ISR_HOOK) */
}


/*
 *  ======== USI Interrupt Service Routine ========
 */
#pragma vector=USI_VECTOR
__interrupt void USI_ISR_HOOK(void)
{
    /* USER CODE START (section: USI_ISR_HOOK) */
 USICTL1 &= ~USIIFG;
 clearDisplay();
 sendNumber(USISRL);
    /* USER CODE END (section: USI_ISR_HOOK) */
}

USI_init.c
/*
 *  This file is automatically generated and does not require a license
 */

#include <msp430.h>

/* USER CODE START (section: USI_init_c_prologue) */
/* User defined includes, defines, global variables and functions */
/* USER CODE END (section: USI_init_c_prologue) */

/*
 *  ======== USI_graceInit ========
 *  Initialize Universal Serial Interface
 */
void USI_graceInit(void)
{
    /* USER CODE START (section: USI_graceInit_prologue) */
    /* User initialization code */
    /* USER CODE END (section: USI_graceInit_prologue) */

    /* Disable USI */
    USICTL0 |= USISWRST;

    /* 
     * USI Control Register 0
     * 
     * USIPE7 -- USI function enabled
     * ~USIPE6 -- USI function disabled
     * USIPE5 -- USI function enabled
     * ~USILSB -- MSB first
     * USIMST -- Master mode
     * ~USIGE -- Output latch enable depends on shift clock
     * ~USIOE -- Output disabled
     * USISWRST -- USI logic held in reset state
     * 
     * Note: ~<BIT> indicates that <BIT> has value zero
     */
    USICTL0 = USIPE7 + USIPE5 + USIMST + USISWRST;

    /* 
     * USI Control Register 1
     * 
     * USICKPH -- Data is captured on the first SCLK edge and changed on the following edge
     * ~USII2C -- I2C mode disabled
     * ~USISTTIE -- Interrupt on START condition disabled
     * USIIE -- Interrupt enabled
     * ~USIAL -- No arbitration lost condition
     * ~USISTP -- No STOP condition received
     * ~USISTTIFG -- No START condition received. No interrupt pending
     * USIIFG -- Interrupt pending
     * 
     * Note: ~<BIT> indicates that <BIT> has value zero
     */
    USICTL1 = USICKPH + USIIE + USIIFG;

    /* 
     * USI Clock Control Register
     * 
     * USIDIV_0 -- Divide by 1
     * USISSEL_2 -- SMCLK
     * ~USICKPL -- Inactive state is low
     * ~USISWCLK -- Input clock is low
     * 
     * Note: ~<BIT> indicates that <BIT> has value zero
     */
    USICKCTL = USIDIV_0 + USISSEL_2;

    /* Enable USI */
    USICTL0 &= ~USISWRST;

    /* USER CODE START (section: USI_graceInit_epilogue) */
    /* User code */
    /* USER CODE END (section: USI_graceInit_epilogue) */
}

miércoles, julio 10, 2013

Usar un 74HC165 con el MSP430 y 8 interruptores

Nota:
LD --> PIN_PL
CLK--> PIN_CP
Q7 --> PIN_Q

74hc165.h

/*
 * 74hc165.h
 */

#ifndef FILE_74HC165_H_
#define FILE_74HC165_H_

#include "msp430.h"
#define PISO_IN_PORT P1IN
#define PISO_OUT_PORT P1OUT
#define PIN_PL BIT5
#define PIN_CP BIT4
#define PIN_Q BIT3

#define PIN_CP_HIGH PISO_OUT_PORT |= PIN_CP
#define PIN_CP_LOW PISO_OUT_PORT &= ~PIN_CP
#define PIN_PL_HIGH PISO_OUT_PORT |= PIN_PL
#define PIN_PL_LOW PISO_OUT_PORT &= ~PIN_PL

void init74hc165 (void);
unsigned char read74hc165(void);

#endif /* FILE_74HC165_H_ */

74hc165.c

/*
 * 74hc165.c
 */

#include "74hc165.h"

void pulseClock (void){
 PIN_CP_HIGH;
 PIN_CP_LOW;
}

void init74hc165 (void){
 PIN_PL_HIGH;
 PIN_CP_HIGH;
}

unsigned char read74hc165(void){

 unsigned char i;
 unsigned char ret = 0;
 volatile unsigned char readed;

 PIN_CP_HIGH;
 PIN_PL_LOW;
 PIN_CP_LOW;
 PIN_PL_HIGH;

 for (i=0; i < 8; i++){

  readed = PISO_IN_PORT;

  if ((readed & PIN_Q) == PIN_Q){
   ret = ret + (128 >> (i));
  }

  pulseClock();
 }

 return ret;
}