So i am trying to read the serial output from a 74HC165N chip. The chip should take 8 binary parallel inputs and convert them to a single serial output.
It does not even seem to read my switches at all. I tried with a different 74HC165N chip and i got the same result, so i don't think my chips are faulty.
Any idea what's going on? have i done something incorrectly in my code? This is how i wired up the 74HC165N chip.
1 (Shift/Load) -> Arduino #13
2 (Clock) -> Arduino #12
3-6, 11-14 (Inputs) -> DIP Switches
8 (GND) - Ground
9 (DATA) -> Arduino 11
15 (Clock INHB) -> Ground
16 (Vcc) -> Power +5v
With the switches wired like this
VCC -> DIP - > 10k resistor-> 74165 A pin
//The terminology used here (PL, CP, Q7 and so on) are taken DIRECTLY from the 74HC165's datasheet.
#define PIN_PL (13) //pin 13 on arduino goes to pin 1 of 74HC165
#define PIN_CP (12) //pin 12 on arduino goes to pin 2 of 74HC165
#define PIN_Q7 (11) //pin 11 on arduino goes to pin 9 of 74HC165
//Hardwire pin 15 of both 74HC165 chips to ground to enable them all the time.
//For peace of mind I also hardwired pin 10 of the upstream chip to
//GND to force zeroes to be shifted in instead of allowing it to float.
//Given that the arduino is "downstream".
void setup()
{
Serial.begin(9600);
pinMode(PIN_PL, OUTPUT);
pinMode(PIN_CP, OUTPUT);
pinMode(PIN_Q7, INPUT);
digitalWrite(PIN_PL, HIGH);
digitalWrite(PIN_CP, LOW);
int i;
int j;
int value;
//read the switches 8 times to prove
//that the system is stable
for(i = 0 ; i < 7 ; i++)
{
//load logic bits from the DIP switches
digitalWrite(PIN_PL, LOW); //LOAD BITS
//reset "load" line, this freezes the internal buffer on both chips
digitalWrite(PIN_PL, HIGH);
for(j = 0 ; j < 8 ; j++)
{
value = digitalRead(PIN_Q7);
digitalWrite(PIN_CP, HIGH);
digitalWrite(PIN_CP, LOW);
//print switch's value
Serial.print(value);
}
Serial.println("");
Serial.println("----------------");
delay(1000);
}
}
void loop()
{
}
