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; }
No hay comentarios:
Publicar un comentario