0% found this document useful (0 votes)
326 views

74LS164 and Arduino

The document describes an Arduino program that uses a 74LS164 shift register to light up LEDs in a changing pattern. It initializes the latch, data, and clock pins of the 74LS164 and defines an array containing the binary values to output. The main loop sends each value in the array to the shift register, lighting up the LEDs in a changing pattern, with a delay between patterns. It uses bitwise operations to sequentially send each bit to the data pin on the clock pulse.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
326 views

74LS164 and Arduino

The document describes an Arduino program that uses a 74LS164 shift register to light up LEDs in a changing pattern. It initializes the latch, data, and clock pins of the 74LS164 and defines an array containing the binary values to output. The main loop sends each value in the array to the shift register, lighting up the LEDs in a changing pattern, with a delay between patterns. It uses bitwise operations to sequentially send each bit to the data pin on the clock pulse.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Instituto Federal de Educao, Cincia e Tecnologia da Paraba //Prof.

Ilton //Sistemas Embarcados // Efeitos com 74LS164 int latchPin int dataPin 164 int srclk #define led5 = = = 8 9; 11; A3; // LED4, Pino Reset ou pino 9 do 74LS164 // LED2 => Pino dado: pinos 1 ou 2 do do 74LS // DIG3 => Pino clock ou pino 8 do 74LS164

const unsigned long saidas[] = { 0x00800001,0x00C00003,0x00E00007,0x00F0000F,0x00F8001F,0x00FC003F,0x00FE 007F,0x00FF00FF, 0x00FF81FF,0x00FFC3FF, 0x00FFE7FF, 0x00FFFFFF, 0x00FFE7FF, 0x00FFC3FF, 0 x00FF81FF, 0x00FF00FF, 0x00FE007F, 0x00FC003F, 0x00F8001F, 0x00F0000F, 0x00E00007, 0x00C00003, 0x00800001 }; int j=0; int tempo1=500; void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(led5, OUTPUT); pinMode(srclk, OUTPUT); Serial.begin(9600); while(!Serial) {}; Serial.println("IFPB - Prof. Ilton"); Serial.println("Perifericos: Prova subturma A"); Serial.println("2012.4 - Bimestre 4"); Serial.println("Data: 25/02/2013"); Serial.println("Prof. Ilton L Barbacena"); Serial.println(" "); Serial.println("Elaborar o programa que produza neste hardware"); Serial.println("este efeito nos leds"); Serial.println(" "); Serial.println("Consultar apenas seus apontamentos"); delay(1000); digitalWrite(latchPin, HIGH); // saidas no zeradas } void loop() { for (int y=0; y<24; y++) // enviar 16 numeros pela serial, saidas[y] { Serial.print("Enviando "); Serial.println(saidas[y], BIN); //Serial.println(" em hexadecimal"); envia2(saidas[y]); digitalWrite( led5, digitalRead( led5 ) ^ 1 ); // inverte LED delay(tempo1);

} } void envia2 (unsigned long w) { boolean r; unsigned long e=0x00000001;

// inicia com LSB 1

digitalWrite(latchPin, LOW); // saidas zeradas digitalWrite(latchPin, HIGH); // saidas disponiveis for (int g=0; g<24; g++) { r = (e == (e & w)); // r = valor logico 1 ou zero envia(r); e = e << 1; // testa o proximo bit da esquerda se 1 } } void envia(boolean g) { digitalWrite(dataPin, g); digitalWrite(srclk, HIGH); digitalWrite(srclk, LOW); }

// bit a ser gravado na entrada, pino 2 do CI1 // pulso de gravacao, pino 8 do 74LS164

You might also like