55 lines
982 B
C
55 lines
982 B
C
#include <avr/io.h>
|
|
#include <stdint.h>
|
|
#include <util/delay.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#define D1 PB0
|
|
#define D2 PB1
|
|
#define D3 PB2
|
|
#define D4 PB4
|
|
|
|
#define SW1 PD2
|
|
#define SW2 PD4
|
|
|
|
int main(void) {
|
|
DDRB |= _BV(D4);
|
|
DDRB |= _BV(D3);
|
|
DDRB |= _BV(D2);
|
|
DDRB |= _BV(D1);
|
|
|
|
DDRD &= ~(_BV(SW1));
|
|
DDRD &= ~(_BV(SW2));
|
|
|
|
PORTB |= _BV(D4);
|
|
|
|
uint8_t prev = 0;
|
|
uint8_t value = 0;
|
|
while (true) {
|
|
uint8_t cur = (PIND & (_BV(SW1) | _BV(SW2)));
|
|
if (prev & (_BV(SW1)) && !(cur & (_BV(SW1)))) {
|
|
value++;
|
|
}
|
|
if (prev & (_BV(SW2)) && !(cur & (_BV(SW2)))) {
|
|
value--;
|
|
}
|
|
prev = cur;
|
|
if (value & 0b0001)
|
|
PORTB |= (_BV(D1));
|
|
else
|
|
PORTB &= ~(_BV(D1));
|
|
if (value & 0b0010)
|
|
PORTB |= (_BV(D2));
|
|
else
|
|
PORTB &= ~(_BV(D2));
|
|
if (value & 0b0100)
|
|
PORTB |= (_BV(D3));
|
|
else
|
|
PORTB &= ~(_BV(D3));
|
|
if (value & 0b1000)
|
|
PORTB |= (_BV(D4));
|
|
else
|
|
PORTB &= ~(_BV(D4));
|
|
_delay_ms(20);
|
|
}
|
|
}
|