aboutsummaryrefslogtreecommitdiff
path: root/examples/spiblink/master.c
blob: 1cc4289bc5c07434dc80fc78be562abc74fe9de8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <avr/io.h>
#include <util/delay.h>
#include <spi.h>

int main() {
    DDRB |= _BV(DDB1) | _BV(DDB2);
    PORTC |= _BV(PORTC1);
    spi_init(SPI_MODE_MASTER);
    SREG |= _BV(7);
    while (1) {
        if (PINC & _BV(PINC1)) {
            PORTB &= ~_BV(PORTB1);
        } else {
            PORTB |= _BV(PORTB1);
        }
        PORTB &= ~_BV(PORTB2);
        spi_send(!(PINC & _BV(PINC1)));
        PORTB |= _BV(PORTB2);
    }
}