Sunday, June 15, 2008

Test 74HC164 SHIFT OUT with LED


I used same pin numbers as bitbutter. If you have standard type 74HC164(ex) philiphs..), check his schematic and refer my pin-connection-table.

(Drawing table in blogger editor is real pain... i gave up)

74HC164 8-bit Serial-in/Parallel-out Shift Registor





















here is my code:

////////////////////////////////////////////////////////////////
////// /////////
////// 74HC164 Test Code by raynor ,June 2008 /////////
////// /////////
////////////////////////////////////////////////////////////////
//define where your pins are
int resetPin = 4;
int clockPin = 2;
int dataPin = 3;

//Define variables to hold the data
//for each shift register.

byte switch_var = 0x80; // 10000000(2)

void setup() {
//start serial
Serial.begin(9600);

//define pin modes
pinMode(resetPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(resetPin,0); //reset (clear) mode
digitalWrite(clockPin,0); //initialize clock
}

void loop() {
int j; //counter variable
byte data = 0;
int print_this; //for debug

digitalWrite(resetPin,1); //Shift mode

for (j=7; j>=0; j--) {
//0 = LOW
//1 = HIGH
data = 0x01 & (switch_var >> j); // this line generates 1(j=7),0,0,0,0.. until j=0

digitalWrite(dataPin,data); //prepare data to set
digitalWrite(clockPin,1); //LOW-to-HIGH clock transition :set data to Q0
digitalWrite(clockPin,0);

print_this = data; // just monitor what is set into shift-registor
Serial.print(print_this); //
delay (1500); // for test only /Here, you may insert 165's task and output to monomeserial via monome protocol

}
Serial.println(" ");
}



74HC165 Shift-in Test code

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
// 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;">




Test 74HC165 SHIFT REGISTOR WITH 16 button in daisychain

Arduino Monome's Keypad input : Multiplexer vs. Shift Register

http://post.monome.org/comments.php?DiscussionID=1623&page=1#Item_0

Bitwise operations in C

This document describes operations in C such as & << >>, which is useful in Arduino programming

http://www.space.unibe.ch/comp_doc/c_manual/C/CONCEPT/bitwise.html#one