#ifndef F_CPU #define F_CPU 16000000UL #endif #include #include #include uint8_t spi_transfer(uint8_t data) { SPDR = data; while (!(SPSR & (1U << SPIF))) { } return SPDR; } int main(void) { PORTB &= (uint8_t)~(1U << PB2); DDRB |= (1U << PB2) | (1U << PB3) | (1U << PB5); SPCR = (1U << SPE) | (1U << MSTR); /* CPOL=0, CPHA=0, SPR=00 */ SPSR = (1U << SPI2X); /* f_SCK = 16 MHz / 2 */ while (1) { for (uint8_t bit = 0; bit < 8U; ++bit) { PORTB &= (uint8_t)~(1U << PB2); spi_transfer((uint8_t)(1U << bit)); PORTB |= (1U << PB2); /* Rising edge latches outputs. */ _delay_ms(150); } } }