Arduino > Exemple Mutliplexeur d'entrées numériques 74HC165
Contents (hide)
Le 74HC165 est multiplexeur d'entrées numériques.
BROCHE |
NOM |
FONCTION | |
3-6,11-14 |
A-H |
D0-D7 |
Entrées numériques |
9 |
QH |
Q7 |
DATA (sortie numérique) |
2 |
CLK |
CP |
CLOCK (horloge/impulsion) |
15 |
INH |
CE |
Brancher au GND |
1 |
SH/LD |
PL |
LATCH (active la sortie Q7 lorsque HIGH) |
10 |
SER |
DS |
Brancher au Q7 d'un autre 74HC165 si plusieurs sont enchaînés |
8 |
GND |
Brancher au GND | |
16 |
VCC |
Brancher au 5V |
// HARDWARE CONNECTIONS int LATCH = 11; int CLOCK = 10; int DATA = 9; byte a=0; void setup() { Serial.begin(57600); pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, INPUT); digitalWrite(CLOCK,LOW); digitalWrite(LATCH,LOW); } void loop() { digitalWrite(LATCH,HIGH); byte a_temp = shiftInFixed(DATA,CLOCK); digitalWrite(LATCH,LOW); // Envoie la valeur lue si elle change if ( a_temp != a ) { a = a_temp; Serial.print("A "); Serial.println(a,DEC); } } byte shiftInFixed(byte dataPin, byte clockPin) { byte value = 0; for (byte i = 0; i < 8; ++i) { value = value | (digitalRead(dataPin) << i); digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW); } return value; }
// HARDWARE CONNECTIONS int LATCH = 11; int CLOCK = 10; int DATA = 9; #define NUM_OF_74HC165 2 byte received[NUM_OF_74HC165]; byte previous[NUM_OF_74HC165]; void setup() { Serial.begin(57600); pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, INPUT); digitalWrite(CLOCK,LOW); digitalWrite(LATCH,LOW); } void loop() { digitalWrite(LATCH,HIGH); for ( byte i=0; i < NUM_OF_74HC165 ; i++ ) { received[i] = shiftInMSBFirst(DATA,CLOCK); } digitalWrite(LATCH,LOW); // Envoie la valeur si elle a changé for ( byte i=0; i < NUM_OF_74HC165 ; i++ ) { if ( previous[i] != received[i] ) { previous[i] = received[i]; Serial.print(i,DEC); Serial.print(' '); Serial.print(received[i],DEC); Serial.println(); } } } byte shiftInMSBFirst(byte dataPin, byte clockPin) { byte value = 0; for (byte i = 0; i < 8; ++i) { value = value | digitalRead(dataPin) << (7 - i); digitalWrite(clockPin, HIGH); digitalWrite(clockPin, LOW); } return value; }