Hide minor edits - Show changes to markup
// : 74HC595 para contar de 0 a 255 //
// : 74HC595 para contar de 0 a 255 //
//set pins to output because they are addressed in the main loop
// Configura como salida los pines que se direccionan en el bucle principal (loop)
//count up routine
//rutina de conteo
//ground latchPin and hold low for as long as you are transmitting
//pone a nivel bajo el latchPin y lo mantienen a nivel bajo todo el tiempo que estés transmitindo
//return the latch pin high to signal chip that it
//no longer needs to listen for information
//vuelve a poner el latchPin a nivel alto para señalizar que
//no sigue siendo necesario eschuchar más información
// Notes : Código para utilizar un registro de desplazamiento // // : 74HC595 para contar de 0 a 255 //
// Notes : Código para utilizar un registro de desplazamiento// // : 74HC595 para contar de 0 a 255 //
// Notes : Código para utilizar un registro de desplazamiento 74HC595 // // : to count from 0 to 255 //
// Notes : Código para utilizar un registro de desplazamiento // // : 74HC595 para contar de 0 a 255 //
Rota un byte de datos bit a bit. Empieza desde el bit más significante (el de más a la izquierda) o el menos significante (el más a la derecha). Cada bit se escribe siguiendo su turno en un pin de datos, después de conmutar un pin de reloj (señal de reloj) para indicar que el bit está disponible.
Desplaza un byte de datos bit a bit. Empieza desde el bit más significante (el de más a la izquierda) o el menos significante (el más a la derecha). Cada bit se escribe siguiendo su turno en un pin de datos, después de conmutar un pin de reloj (señal de reloj) para indicar que el bit está disponible.
ordenBits: en qué orden rotar los bits; si hacia el MSBFIRST (bit más significante primero) o hacia el LSBFIRST (bit menos significante primero).
ordenBits: en qué orden desplazar los bits; si hacia el MSBFIRST (bit más significante primero) o hacia el LSBFIRST (bit menos significante primero).
For accompanying circuit, see the tutorial on controlling a 74HC595 shift register.
Para ver el circuito asociado a este ejemplo, ver el tutorial para controlar un registro de desplazamiento 74HC595.
// Notes : Code for using a 74HC595 Shift Register //
// Notes : Código para utilizar un registro de desplazamiento 74HC595 //
//Pin connected to ST_CP of 74HC595
//Pin conectado al pin ST_CP del 74HC595
//Pin connected to SH_CP of 74HC595
//Pin connectado al pin SH_CP del 74HC595
////Pin connected to DS of 74HC595
////Pin conectado al pin DS del 74HC595
// Haz esto para una comunicación serie MSBFIRST (primero los bits más significativos) int data = 500; // shift out highbyte shiftOut(dataPin, clock, MSBFIRST, (data >> 8)); // shift out lowbyte shiftOut(data, clock, MSBFIRST, data);
// Or do this for LSBFIRST serial data = 500; // shift out lowbyte shiftOut(dataPin, clock, LSBFIRST, data); // shift out highbyte shiftOut(dataPin, clock, LSBFIRST, (data >> 8)); @]
// Haz esto para una comunicación serie MSBFIRST (primero el bit más significativo) int datos = 500; // rota el byte más alto shiftOut(pinDatos, pinReloj, MSBFIRST, (datos >> 8)); // rota el byte más bajo shiftOut(datos, pinReloj, MSBFIRST, datos);
// O haz esto para una comunicación serie LSBFIRST (primero el bit menos significativo) datos = 500; // rota el byte más bajo shiftOut(pinDatos, pinReloj, LSBFIRST, datos); // rota el bit más alto shiftOut(pinDatos, pinReloj, LSBFIRST, (datos >> 8)); @]
// Do this for MSBFIRST serial
// Haz esto para una comunicación serie MSBFIRST (primero los bits más significativos)
Rota cada vez un bit de un byte de datos. Empieza desde el bit más significante (el de más a la izquierda) o el menos significante (el más a la derecha). Cada bit se escribe siguiendo su turno en un pin de datos, después de conmutar un pin de reloj (señal de reloj) para indicar que el bit está disponible.
Rota un byte de datos bit a bit. Empieza desde el bit más significante (el de más a la izquierda) o el menos significante (el más a la derecha). Cada bit se escribe siguiendo su turno en un pin de datos, después de conmutar un pin de reloj (señal de reloj) para indicar que el bit está disponible.
The dataPin and clockPin must already be configured as outputs by a call to pinMode().
shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.
El pinDatos y pinReloj deben estar ya configurados como salida con una llamada previa a pinMode().
shiftOut se encuentra actualmente configurada para extraer un byte (8 bits) por lo que necesita realizar una operación de dos pasos para extraer valores más grandes de 255.
shiftOut(dataPin, clockPin, bitOrder, value)
dataPin: the pin on which to output each bit (int)
clockPin: the pin to toggle once the dataPin has been set to the correct value (int)
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.
(Most Significant Bit First, or, Least Significant Bit First)
value: the data to shift out. (byte)
None
shiftOut(pinDatos, pinReloj, ordenBits, valor)
pinDatos: el pin en el cual extraer cada bit (int)
pinReloj: el pin que hay que conmutar cada vez que a un pinDatos le ha sido enviado el valor correcto (int)
ordenBits: en qué orden rotar los bits; si hacia el MSBFIRST (bit más significante primero) o hacia el LSBFIRST (bit menos significante primero).
valor: los datos que rotar. (byte)
Ninguno
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in chip hardware documentation as Serial Peripheral Interface (SPI).
Esto es conocido como protocolo serie síncrono y es la forma común que utilizan los microcontroladores para comunicarse con sensores y con otros microcontroladores. Ambos dispositivos permanecen sincronizados, y se comunican a velocidades cercanas a las máximas, hasta que ambos compartan la misma linea de reloj. En la documentación del harware interno de los chips se hace referencia a menudo a esta característica como Serial Peripheral Interface (SPI).
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is toggled to indicate that the bit is available.
Rota cada vez un bit de un byte de datos. Empieza desde el bit más significante (el de más a la izquierda) o el menos significante (el más a la derecha). Cada bit se escribe siguiendo su turno en un pin de datos, después de conmutar un pin de reloj (señal de reloj) para indicar que el bit está disponible.
data = 500;
int data = 500;
shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.
shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.
[@
shiftOut(dataPin, clock, LSBFIRST, (data >> 8));
shiftOut(dataPin, clock, LSBFIRST, (data >> 8)); @]
shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255.
// Do this for MSBFIRST serial data = 500; // shift out highbyte shiftOut(dataPin, clock, MSBFIRST, (data >> 8)); // shift out lowbyte shiftOut(data, clock, MSBFIRST, data);
// Or do this for LSBFIRST serial data = 500; // shift out lowbyte shiftOut(dataPin, clock, LSBFIRST, data);
// shift out highbyte shiftOut(dataPin, clock, LSBFIRST, (data >> 8));
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to the dataPin, after which the clockPin is toggled to indicate that the bit is available.
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in chip hardware documentation as Serial Peripheral Interface (SPI)
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is toggled to indicate that the bit is available.
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in chip hardware documentation as Serial Peripheral Interface (SPI).
shiftOut(dataPin, clockPin, bitOrder, value)
The dataPin and clockPin must already be configured as outputs by a call to pinMode.
The dataPin and clockPin must already be configured as outputs by a call to pinMode().
Note that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so outputting an int with shiftout requires a two-step operation:
int data; int clock; int cs; ... digitalWrite(cs, LOW); data = 500; shiftOut(data, clock, MSBFIRST, data) digitalWrite(cs, HIGH); // this will actually only output 244 because // 500 % 256 = 244 // since only the low 8 bits are output // Instead do this for MSBFIRST serial data = 500; // shift out highbyte // " >> " is bitshift operator - moves top 8 bits (high byte) into low byte shiftOut(data, clock, MSBFIRST, (data >> 8)); // shift out lowbyte shiftOut(data, clock, MSBFIRST, data); // And do this for LSBFIRST serial data = 500; // shift out lowbyte shiftOut(data, clock, LSBFIRST, data); // shift out highbyte shiftOut(data, clock, LSBFIRST, (data >> 8));
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in chip hardware documentation as Synchronous Peripheral Interface (SPI)
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in chip hardware documentation as Serial Peripheral Interface (SPI)
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in hardware documentation as Synchronous Peripheral Interface (SPI)
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in chip hardware documentation as Synchronous Peripheral Interface (SPI)
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line.
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in hardware documentation as Synchronous Peripheral Interface (SPI)
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. Often referred to as SPI (synchronous protocol interface) in hardware documentation.
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line.
Note also that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so outputting an int with shiftout requires a two-step operation:
int data; int clock; int cs; ... digitalWrite(cs, LOW); data = 500; shiftOut(data, clock, MSBFIRST, data) digitalWrite(cs, HIGH); // this will actually only output 244 because // 500 % 256 = 244 // since only the low 8 bits are output // Instead do this for MSBFIRST serial data = 500; // shift out highbyte // " >> " is bitshift operator - moves top 8 bits (high byte) into low byte shiftOut(data, clock, MSBFIRST, (data >> 8)); // shift out lowbyte shiftOut(data, clock, MSBFIRST, data); // And do this for LSBFIRST serial data = 500; // shift out lowbyte shiftOut(data, clock, LSBFIRST, data); // shift out highbyte shiftOut(data, clock, LSBFIRST, (data >> 8));
Note that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so outputting an int with shiftout requires a two-step operation:
int data; int clock; int cs; ... digitalWrite(cs, LOW); data = 500; shiftOut(data, clock, MSBFIRST, data) digitalWrite(cs, HIGH); // this will actually only output 244 because // 500 % 256 = 244 // since only the low 8 bits are output // Instead do this for MSBFIRST serial data = 500; // shift out highbyte // " >> " is bitshift operator - moves top 8 bits (high byte) into low byte shiftOut(data, clock, MSBFIRST, (data >> 8)); // shift out lowbyte shiftOut(data, clock, MSBFIRST, data); // And do this for LSBFIRST serial data = 500; // shift out lowbyte shiftOut(data, clock, LSBFIRST, data); // shift out highbyte shiftOut(data, clock, LSBFIRST, (data >> 8));
shiftOut(data, clock, MSBFIRST, data);
shiftOut(data, clock, LSBFIRST, data);
shiftOut(data, clock, MSBFIRST, (data >> 8));
shiftOut(data, clock, LSBFIRST, (data >> 8));
// " >> " is bitshift operator - moves top 8 bit (high byte) into low byte
// " >> " is bitshift operator - moves top 8 bits (high byte) into low byte
Note also that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so if one tries to outputing an int with shiftout requires a two-step operation:
Note also that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so outputting an int with shiftout requires a two-step operation:
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.
(Most Significant Bit First, or, Least Significant Bit First)
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.\\
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.
(Most Significant Bit First, or, Least Significant Bit First)
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.\\
bitOrder: which order to shift out the bits (either MSBFIRST or LSBFIRST).
bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST. (Most Significant Bit First, or, Least Significant Bit First)
Note also that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so if one tries to do something like this:
Note also that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so if one tries to outputing an int with shiftout requires a two-step operation:
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a pin, after which another pin is toggled to indicate that the bit is available.
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to the dataPin, after which the clockPin is toggled to indicate that the bit is available.
// shift out lowbyte
// shift out lowbyte
// shift out highbyte
// shift out highbyte @]
@]
shiftOut(data, clock, MSBFIRST, (data >> 8)); // >> is bitshift operator - moves highbyte into lowbyte
// " >> " is bitshift operator - moves top 8 bit (high byte) into low byte shiftOut(data, clock, MSBFIRST, (data >> 8));
shiftOut(data, clock, MSBFIRST, (data >> 8));
shiftOut(data, clock, MSBFIRST, (data >> 8)); // >> is bitshift operator - moves highbyte into lowbyte // shift out lowbyte
// And do this for LSBFIRST serial data = 500; shiftOut(data, clock, MSBFIRST, data);
// And do this for LSBFIRST serial data = 500; shiftOut(data, clock, MSBFIRST, data); // shift out lowbyte
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. Often referred to in hardware documentation as SPI.
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. Often referred to as SPI (synchronous protocol interface) in hardware documentation.
Note also that this function, as it is currently written, only outputs 8 bits at a time. An int holds two bytes (16 bits), so if one tries to do something like this:
Note also that this function, as it is currently written, is hard-wired to output 8 bits at a time. An int holds two bytes (16 bits), so if one tries to do something like this:
Note also that this function, as it is currently written, only outputs 8 bits at a time. An int holds two bytes, so if one tries to do something like this:
Note also that this function, as it is currently written, only outputs 8 bits at a time. An int holds two bytes (16 bits), so if one tries to do something like this:
Note also that this function, as it is currently written, only outputs 8 bits at a time. An int holds two bytes so if one tries to do something like this:
Note also that this function, as it is currently written, only outputs 8 bits at a time. An int holds two bytes, so if one tries to do something like this:
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a pin, after which another pin is toggled to indicate that the bit is available.
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a pin, after which another pin is toggled to indicate that the bit is available.
This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices always stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. Often referred to in hardware documentation as SPI.
Note also that this function, as it is currently written, only outputs 8 bits at a time. An int holds two bytes so if one tries to do something like this:
int data; int clock; int cs; ... digitalWrite(cs, LOW); data = 500; shiftOut(data, clock, MSBFIRST, data) digitalWrite(cs, HIGH); // this will actually only output 244 because // 500 % 256 = 244 // since only the low 8 bits are output // Instead do this for MSBFIRST serial data = 500; shiftOut(data, clock, MSBFIRST, (data >> 8)); // shift out highbyte shiftOut(data, clock, MSBFIRST, data); // shift out lowbyte // And do this for LSBFIRST serial data = 500; shiftOut(data, clock, MSBFIRST, data); // shift out lowbyte shiftOut(data, clock, MSBFIRST, (data >> 8)); // shift out highbyte
[@//**************************************************************//
[@//**************************************************************//
[@ //**************************************************************//
[@//**************************************************************//
[@
//**************************************************************//
[@ //**************************************************************//
For accompanying circuit, see the tutorial on controlling a 74HC595 shift register.
For accompanying circuit, see the tutorial on controlling a 74HC595 shift register.
} @]
} @]
The dataPin and clockPin must already be configured as outputs by a call to pinMode.
The dataPin and clockPin must already be configured as outputs by a call to pinMode.
For accompanying circuit, see the tutorial on controlling a 74HC595 shift register.
// Name : shiftOutCode, Hello World // // Author : Carlyn Maw,Tom Igoe //
// Name : shiftOutCode, Hello World // // Author : Carlyn Maw,Tom Igoe //
Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a pin, after which another pin is toggled to indicate that the bit is available.
dataPin: the pin on which to output each bit (int)
clockPin: the pin to toggle once the dataPin has been set to the correct value (int)
bitOrder: which order to shift out the bits (either MSBFIRST or LSBFIRST).
value: the data to shift out. (byte)
None
//**************************************************************//
// Name : shiftOutCode, Hello World //
// Author : Carlyn Maw,Tom Igoe //
// Date : 25 Oct, 2006 //
// Version : 1.0 //
// Notes : Code for using a 74HC595 Shift Register //
// : to count from 0 to 255 //
//****************************************************************
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
//count up routine
for (int j = 0; j < 256; j++) {
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, j);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, HIGH);
delay(1000);
}
}
The dataPin and clockPin must already be configured as outputs by a call to pinMode.