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(" ");
}



No comments: