From t-o-f

Arduino: ExempleDémultiplexeurNumérique74HC595

Contents (hide)

  1. 1. 74HC595 (sortie par décalage)
    1. 1.1 Tutoriel Arduino
    2. 1.2 Fiche technique
    3. 1.3 Un seul 74HC595
    4. 1.4 Cascade de deux ou plus 74HC595
    5. 1.5 Code Msg

1.  74HC595 (sortie par décalage)

1.1  Tutoriel Arduino

1.2  Fiche technique

1.3  Un seul 74HC595

Circuit


595.fz

74HC595.sch

Code

Code Arduino:

/*
This code lights up each LED connected to
a 74HC595 as determined by the binary value
of a counter.
*/

// Pin connected to SRCLK of 74HC595
int CLOCK = 12;
// Pin connected to RCLK of 74HC595
int LATCH = 11;
// Pin connected to SER of 74HC595
int DATA = 10;

byte counter = 0;

void setup() {
        //set pins to output so you can control the shift register
        pinMode(LATCH, OUTPUT);
        pinMode(CLOCK, OUTPUT);
        pinMode(DATA, OUTPUT);
}

void loop() {
        // take the latchPin low
        digitalWrite(LATCH, LOW);
        // shift out the bits:
        shiftOut(DATA, CLOCK, MSBFIRST, counter);
        //take the latch pin high so the LEDs update:
        digitalWrite(LATCH, HIGH);
        // pause before next value:
        delay(100);

        counter = counter + 1;

}

1.4  Cascade de deux ou plus 74HC595


74HC595_cascade.sch
/*
This code lights up each LED connected to
a cascade of 74HC595 as determined by the binary value
of a counter.
*/

// Pin connected to SRCLK of BOTH 74HC595
int CLOCK = 12;
// Pin connected to RCLK of BOTH 74HC595
int LATCH = 11;
// Pin connected to SER of the first 74HC595
int DATA = 10;

byte counter = 0;

void setup() {
        //set pins to output so you can control the shift registers
        pinMode(LATCH, OUTPUT);
        pinMode(CLOCK, OUTPUT);
        pinMode(DATA, OUTPUT);
}

void loop() {
        // take the latchPin low
        digitalWrite(LATCH, LOW);
        // shift out the bits for the SECOND 74HC595:
        shiftOut(DATA, CLOCK, MSBFIRST, 255 - counter);
        // shift out the bits for the FIRST 74HC595:
        shiftOut(DATA, CLOCK, MSBFIRST, counter);
        //take the latch pin high so the LEDs update:
        digitalWrite(LATCH, HIGH);
        // pause before next value:
        delay(100);

        counter = counter + 1;

}

1.5  Code Msg


/*
Controls up to 16x 75HC595 through msg custom messages.
Each byte of the custom message is sent to one 75HC595.
If you want to control 3x 75HC595, then you send 3 bytes.
*/

#include <msg.h>

// Pin connected to SRCLK of 74HC595
int CLOCK = 12;
// Pin connected to RCLK of 74HC595
int LATCH = 11;
// Pin connected to SER of 74HC595
int DATA = 10;

// We will store the bytes sent from the computer
// into this array:
byte dataFromComputer[16];
byte dataLength;


void message() {

        // Read avaialbe bytes from computer:
        dataLength = msg.availableBytes() ;

        // If there is more bytes than the size
        // of the array, limit the number of bytes:
        if ( dataLength > 16 ) dataLength = 16;
        // Read each byte sent by the computer
        // and store it in the array:
        for ( int i =0; i < dataLength ; i++ ) {
                dataFromComputer[i] = msg.readByte();
        }

        msg.writeBytes(dataFromComputer,dataLength);


        // Update 595's
        // take the latchPin low
        digitalWrite(LATCH, LOW);
        // Shift out the bits for each byte we received
        // from the computer:
        for ( int i =0; i < dataLength ; i++ ) {
                // shift out the bits:
                shiftOut(DATA, CLOCK, MSBFIRST, dataFromComputer[i]);
        }
        //take the latch pin high:
        digitalWrite(LATCH, HIGH);

}


void setup() {
        // Setup msg whith the custom message function.
        // Also change its name to notify that this version
        // of msg is modified:
        msg.setup(message,"74*595");
        // Detach the pins used in our custom code from
        // msg's control:
        msg.detach(LATCH);
        msg.detach(CLOCK);
        msg.detach(DATA);

        // Set pins used in our custom code to output
        // so you can control the shift register:
        pinMode(LATCH, OUTPUT);
        pinMode(CLOCK, OUTPUT);
        pinMode(DATA, OUTPUT);

}


void loop() {

        msg.loop(); // Update msg

}
Récupéré sur http://wiki.t-o-f.info/Arduino/ExempleD%c3%a9multiplexeurNum%c3%a9rique74HC595
Page mise à jour le 18 November 2013 à 11h27