A brief exercise using the 74HC595 Serial to Parallel Converter..
It's a shift register.
This chip has 8 outputs and 3 inputs.
The 74HC/HCT595 is a high-speed Si-gate CMOS device.
I remember building a Video synth module a few years ago that also used a shift register.
The Castle used a 4 bit module.... the CD4015
This 74HC595 is 8-bit.
It's a 16 pin chip.
It's all digital Designed to store 0's and 1's, not analog voltages.
So shouldn't be confused with synthesizer ASRs - analog shift registers (though the idea is the same).
Shift registers are basically memory modules.
It's useful if you run out of pins on your Arduino.
The 74HC595 will help you make use of the pins you have .
You can even link multiple shift registers together to extend your output even more.
Most of the outputs pins are on the left. Inputs on the right. (fig 1)
The Data sheet describes it as a 8-stage serial shift register with a storage register and 3-state outputs.
The shift register and storage register have separate clocks
What it does is take data from your Arduino ,& momentary store it, freeing up the pins for new data.
The inputs are:
MR (SRCLR) - pin 10
SHcp - Shift Register clock - pin 11
STcp - Clock (RCLK) - pin 12 - storage register clock (LATCH)
OE - pin 13 - output enable
Ds/SER - serial input (pin 14)
Both the shift register clock (SRCLK) and storage register clock (RCLK) are positive-edge triggered.
Pin 14 is your important DATA input pin
Pin 11 is the Clock
Pin 12 is the Latch
This is a good circuit diagram:
Q0 to Q7 & Q15, are the outputs
Connect ground & voltage (pins 8 & 16)
We are using digital pins 4, 5, 6.
The important connections are
- Digital 4 from the arduino goes to pin #14 of the shift register (DATA)
- Digital 5 from the arduino goes to pin #12 of the shift register (LATCH)
- Digital 6 from the arduino goes to pin #11 of the shift register (CLOCK)
The anodes of the LEDs connect via 270 ohm resistors to pins:15, 1, 2, 3, 4, 5, 6, 7.
On the LEDs, the cathode is connected to ground
Note:
Pin 13 is the output enable.
You could attach this to a PWM capable Arduino pin and use 'analogWrite' to control the brightness of the LEDs. At the moment, we need to attach it to ground.
MR must also be connected to 5V
--------------------------------
Code 1
--------------------------------------------
/*
Adafruit Arduino - Lesson 4. 8 LEDs and a Shift Register
*/
// declare your variables
// these are the pins attached to the clock,latch &
//data inputs
int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
int delayTime = 500;
/* used to hold the pattern of which LEDs are currently
turned on or off.
Data of type 'byte' represents numbers using eight bits.
*/
byte leds = 0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
leds = 0;
updateShiftRegister();
delay(delayTime);
for (int i = 0; i < 8; i++)
{
bitSet(leds, i);
updateShiftRegister();
delay(delayTime);
}
}
/*
the actual data to be shifted into the shift register,
which in this case is 'leds'.
*/
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
-------------------------------------------------------------------
---------------------------------
-------------------------------------
No comments:
Post a Comment