note: I used same arduino pin numbers as bitbutter. so if you have standard type(ex:philips,..)IC, you refer bitbutter's
schematic and connect pins with my table as followed. Both my code and his will work correctly.
74HC165 8-bit Parallel-in/Serial-out Shift Registor
165 pin Number | Desc. | Connect to : |
1 | parallel/serial control (LATCH)PL | <- Arduino Ouput 13 |
2 | CLOCK | <-- Arduino Output 12 |
3 | D4 | |
4 | D5 | |
5 | D6 | |
6 | D7 | |
7 | complemantary Output | <- N.C. (ignore) |
8 | GND | <- GND |
9 | serial data Output (Q7) | àArduino Input 11 |
10 | serial data input (Ds) | -> 165_#2 serial data Output(use in daisy-chain) |
11 | D0 | |
12 | D1 | |
13 | D2 | |
14 | D3 | |
15 | CLOCK enable input (active”low”) | <- GND |
16 | Vcc | ß--- 5V |
* Fig1,2 from 74hc165 datasheet
Here is my(?) code:
//**************************************************************//
// Modified by Raynor for using 74HC165 test,2008 //
/// Previously written for CD4021B Shift Register by
// Modified by Raynor for using 74HC165 test,2008 //
/// Previously written for CD4021B Shift Register by
// Carlyn Maw,2007 //
//****************************************************************
//define where your pins are
int latchPin = 13;
int dataPin = 11;
int clockPin = 12;
//Define variables to hold the data
//for each shift register.
//starting with non-zero numbers can help
//troubleshoot
byte switchVar1 = 72; //01001000
byte switchVar2 = 1; //00000001
void setup() {
//start serial
Serial.begin(9600);
//define pin modes
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
}
void loop() {
//Pulse the latch pin:
//set it to 0 to collect parallel data
digitalWrite(latchPin,0);
//set it to 0 to collect parallel data, wait
delayMicroseconds(20);
//set it to 1 to transmit data serially
digitalWrite(latchPin,1);
//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);
delay (1);
switchVar2 = shiftIn(dataPin, clockPin);
//white space
Serial.println("-");
//delay so all these print satements can keep up.
delay(1000);
}
//------------------------------------------------end main loop
////// ----------------------------------------shiftIn function
byte shiftIn(int myDataPin, int myClockPin) {
int i;
int temp = 0;
int pinState;
byte myDataIn = 0x00;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);
//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
for (i=7; i>=0; i--)
{
digitalWrite(myClockPin, 0);
delayMicroseconds(2);
temp = digitalRead(myDataPin);
if (boolean(temp) == true) {
pinState = 1;
//set the bit to 0 no matter what
myDataIn = myDataIn (0x01 << pinstate =" 0;">
//****************************************************************
//define where your pins are
int latchPin = 13;
int dataPin = 11;
int clockPin = 12;
//Define variables to hold the data
//for each shift register.
//starting with non-zero numbers can help
//troubleshoot
byte switchVar1 = 72; //01001000
byte switchVar2 = 1; //00000001
void setup() {
//start serial
Serial.begin(9600);
//define pin modes
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
}
void loop() {
//Pulse the latch pin:
//set it to 0 to collect parallel data
digitalWrite(latchPin,0);
//set it to 0 to collect parallel data, wait
delayMicroseconds(20);
//set it to 1 to transmit data serially
digitalWrite(latchPin,1);
//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);
delay (1);
switchVar2 = shiftIn(dataPin, clockPin);
//white space
Serial.println("-");
//delay so all these print satements can keep up.
delay(1000);
}
//------------------------------------------------end main loop
////// ----------------------------------------shiftIn function
byte shiftIn(int myDataPin, int myClockPin) {
int i;
int temp = 0;
int pinState;
byte myDataIn = 0x00;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);
//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
for (i=7; i>=0; i--)
{
digitalWrite(myClockPin, 0);
delayMicroseconds(2);
temp = digitalRead(myDataPin);
if (boolean(temp) == true) {
pinState = 1;
//set the bit to 0 no matter what
myDataIn = myDataIn (0x01 << pinstate =" 0;">
Test 74HC165 SHIFT REGISTOR WITH 16 button in daisychain
2 comments:
that's cool
your code is not working...
Post a Comment