C:\Users\dntg\Documents\Arduino\spi_595\spi_595.
ino mercoledì 3 gennaio 2018 23:40
// [Link]
// code by Nick Gammon
// Connections for UNO and similar
// 595 Chip pin 14 Data (DS) goes to MOSI (pin 11)
// 595 Chip pin 11 Clock (SH) goes to SCK (pin 13)
// 595 Chip pin 12 Latch (ST) goes to SS (pin 10) (or any other pin by changing LATCH)
#include <SPI.h>
const int LATCH = 10; // Defines the LATCH on pin 10
void setup ()
{
//pinMode (LATCH, OUTPUT); // sets pin 10 as OUTPUT, since it plays the SS-Slave Select role
DDRB |= (1<<DDB2); // sets PB2, pin 10, as OUTPUT, since it plays the SS-Slave Select role
[Link] ();
// below settings reccomended for IDE 1.6.0 and above
[Link] (SPISettings (4000000, MSBFIRST, SPI_MODE0)); // 4 MHz clock, MSB
first, Mode 0
//[Link](115200);
/*
sei(); // Enables Global Interrupts
SPCR |= (1<<SPIE); // sets SPI Interrupt Enable bit
*/
//[Link]();
} // end of setup
byte c; // starts the counter at b00000000
// SPI interrupt routine
/*
ISR (SPI_STC_vect)
{
PORTB |= (1<<PB2); // puts SS pin 10 HIGH
}
*/
void loop ()
{
c++; // incremets the byte one bit at the time
//digitalWrite (LATCH, LOW);
PORTB &= ~(1<<PB2); // puts SS pin 10 LOW
[Link] (c);
PORTB |= (1<<PB2); // puts SS pin 10 HIGH
//digitalWrite (LATCH, HIGH);
//[Link](c);
delay (1000);
} // end of loop
-1-