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) */ }