Saturday, June 26, 2010

INTREFACING SHIFT REGISTER WITH ARDUINO

This document gives some detail about how to interface shift register with Arduino, and connecting 7 segment display with it.

SCHEMATIC:


The schematic above shows shift register IC74HC595.It has 16pins. Vcc=5V.1 Micro Farad Capacitor is used. In this one shift register is used, we have to use at least two shift register and two 7 segment display.

                            
 


PINS 1-7, 15

Q0 " Q7

Output Pins

PIN 8

GND

Ground, Vss

PIN 9

Q7"

Serial Out

PIN 10

MR

Master Reclear, active low

PIN 11

SH_CP

Shift register clock pin

PIN 12

ST_CP

Storage register clock pin (latch pin)

PIN 13

OE

Output enable, active low

PIN 14

DS

Serial data input

PIN 16

Vcc

Positive supply voltage


 


 


 


 


 


 


 


 


 


 


The schematic above shows 7 segment display either common Anode or common Cathode (here it is common Anode).

Program:


 

//Pin connected to ST_CP of 74HC595


 

int latchPin = 8;


 

//Pin connected to SH_CP of 74HC595


 

int clockPin = 12;


 

////Pin connected to DS of 74HC595


 

int dataPin = 11;


 

//Initializing the output pins


 

int k=B11111111;


 

int a;


 


 

void setup()

{


 

//set pins to output so you can control the shift register


 

pinMode(latchPin, OUTPUT);


 


 

pinMode(clockPin, OUTPUT);


 


 

pinMode(dataPin, OUTPUT);


 


 

Serial.begin(9600);


 


 

}


 


 

void loop()


 

{


 

// setting the output pins to show 1


 

k=B11111010;

\

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 

Serial.print(k);


 

// setting the output pins to show 2


 

k=B10100100;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits: 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 

delay(1000);


 

// print the value


 

Serial.print(k);


 

// setting the output pins to show 3


 


 

k=B10110000;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 

digitalWrite(latchPin, HIGH);


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 4


 


 


 

k=B10011010;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 


 


 

// setting the output pins to show 5


 


 

k=B10010001;


 


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 6


 

k=B10000001;


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 7


 

k=B11111000;


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 8


 

k=B10000000;


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 

// print the value


 


 

Serial.print(k);


 

// setting the output pins to show 9


 

k=B10010000;


 

// making latch pin low to shift


 

digitalWrite(latchPin, LOW);


 


 

// shift out the bits:


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 


 

// setting the output pins to show 0


 


 

k=B11000000;


 


 

// making latch pin low to shift


 


 

digitalWrite(latchPin, LOW);


 


 

// shift out the bits:


 


 


 

shiftOut(dataPin, clockPin, MSBFIRST, k);


 


 

// making latch pin high to store


 


 

digitalWrite(latchPin, HIGH);


 


 

delay(1000);


 


 

// print the value


 


 

Serial.print(k);


 


 


 


 


 

}


 


 


 


 


 

CONNECTING SHIFT REGISTER WITH ARDUINO:




 


 


 


 


 

If we want to use more than one shift register, we have to connect the Q7" (PIN 9) of the first shift register to the serial input pin (PIN 14) of the next shift register. If we want to connect more shift register the same (i.e. connecting the PIN 14 of the shift register with the PIN 9 of the previous shift register) procedure must be followed. connecting two shift register is shown below

No comments:

Post a Comment