ciao
ho alcuni 74hc597 sono dei piso, ho seguito questa guida
http://y-aji.com/?p=242
funziona con un integrato, adesso vorrei aggiungerne uno,
ho già fatto esperienze con successo, seguendo il playground dove si usa un cd4021, per questo ho collegato pin9 di uno con pin 14 dell’altro ma leggo solo una variabile e la seconda è uguale
qualche suggerimento?
grazie
stefano
//**************************************************************//
// Name : shiftIn Example 2.1 //
// Author : Carlyn Maw //
// Date : 25 Jan, 2007 //
// Version : 1.0 //
// Notes : Code for using a CD74hc597 Shift Register //
// : //
//****************************************************************
//define where your pins are
int latchPin = 8; //597 pin 12
int dataPin = 9; //597 pin 9
int clockPin = 7; //597 pin 11
int loadPin = 6;//597 pin 13
int count;
//Define variables to hold the data
//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 72; //01001000
byte switchVar2 = 159; //10011111
void setup() {
//start serial
Serial.begin(9600);
//define pin modes
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
pinMode(loadPin, OUTPUT);
}
void loop() {
//Pulse the latch pin:
digitalWrite(latchPin,1);//set it to 1 to collect parallel data
delayMicroseconds(20); //set it to 1 to collect parallel data, wait
digitalWrite(latchPin,0);//set it to 0 to transmit data serially
//while the shift register is in serial mode
//collect each shift register into a byte
//the register attached to the chip comes in first
//switchVar1 = shiftIn(dataPin, clockPin);
switchVar1 = shiftIn(dataPin, clockPin, loadPin);
switchVar2 = shiftIn(dataPin, clockPin, loadPin);
//Print out the results.
//leading 0's at the top of the byte
//(7, 6, 5, etc) will be dropped before
//the first pin that has a high input
//reading
// Serial.println(switchVar1, BIN);
for (count=0;count<8;count++)
{
Serial.print(count);
Serial.print('\t');
Serial.print("switchVar1");
Serial.print('\t');
Serial.println(bitRead(switchVar2,count));
}
Serial.println("-------------------");
for (count=0;count<8;count++)
{
Serial.print(count);
Serial.print('\t');
Serial.print("switchVar2");
Serial.print('\t');
Serial.println(bitRead(switchVar1,count));
}
//white space
Serial.println("-------------------");
//delay so all these print satements can keep up.
delay(1000);
}//------------------end main loop
////// --------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0
//byte shiftIn(int myDataPin, int myClockPin) {
byte shiftIn(int myDataPin, int myClockPin, int myLoadPin)
{
int i;
int temp = 0;
int pinState;
byte myDataIn = 0;
pinMode(myDataPin, INPUT);
pinMode(myClockPin, OUTPUT);
pinMode(myLoadPin, OUTPUT);
//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop
//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
digitalWrite(myLoadPin, 0);
delayMicroseconds(0.2);
digitalWrite(myLoadPin, 1);
for (i=7; i>=0; i--)
{
digitalWrite(myClockPin, 0);
delayMicroseconds(0.2);
temp = digitalRead(myDataPin);
if (temp) {
pinState = 1;
//set the bit to 0 no matter what
myDataIn = myDataIn | (1 << i);
}
else {
//turn it off -- only necessary for debuging
//print statement since myDataIn starts as 0
pinState = 0;
}
//Debuging print statements
//Serial.print(pinState);
//Serial.print(" ");
//Serial.println (dataIn, BIN);
digitalWrite(myClockPin, 1);
}
//debuging print statements whitespace
//Serial.println();
//Serial.println(myDataIn, BIN);
return myDataIn;
}
cd74hc597 0900766b80cad189.pdf (627 KB)