/*
This Project was started in my semester abroad
to do something useful in my freetime
and improve my skills in the field of embedded systems.
The goals of this project are the following:
1. Being able to type in any set of characters which are then displayed
in the LED-Matrix. The dots should move from left to right with a speed
which is easy to read.
2. Not to use any libraries or prewritten code
*/
#define DIN PB0 //define data input pin 12
#define CS PD7 //define chip select pin 11
#define CLK PB2 //define clock pin 14
void SPI_MasterInit(void)
{
/* Set MOSI and SCK output, all others input */
DDRB = (1 << DIN) | (1 << CLK);
/* Set CS output, all others input */
DDRD = (1 << CS);
/* Enable SPI, Master, set clock rate fck/16 */
SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0);
}
void SPI_MasterTransmit(uint8_t bData)
{
//PORTD &= ~(1<<CS);
/* Start transmission */
SPDR = bData;
/* Wait for transmission complete */
while (!(SPSR & (1 << SPIF)));
//PORTD |= (1<<CS);
}
void setup() {
Serial.begin(9600); // set up the serial connection
SPI_MasterInit();
}
void loop() {
//PORTD &= ~(1<<CS);
SPI_MasterTransmit(0b00001111);
//PORTD |= (1<<CS);
//PORTD &= ~(1<<CS);
SPI_MasterTransmit(0b11001111);
//PORTD |= (1<<CS);
delay(1000);
}