35 lines
682 B
C
35 lines
682 B
C
#define __AVR_ATmega2560__
|
|
#define F_CPU 16000000UL
|
|
#define DISPLAY PORTF
|
|
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
#include <stdbool.h>
|
|
#include "lib/7segment.h"
|
|
|
|
void main() {
|
|
DDRF = 0b11111111;
|
|
DDRK = 0b00000000;
|
|
PORTK = 0b00000001; // enable pull-up resistor
|
|
|
|
uint8_t val = 0;
|
|
|
|
set_display(&PORTF, val, false);
|
|
|
|
while(1) {
|
|
loop_until_bit_is_clear(PINK, PINK0);
|
|
|
|
if (val >= 9) {
|
|
val = 0xff; // will overflow to 0 when incremented
|
|
}
|
|
|
|
set_display(&PORTF, ++val, true);
|
|
|
|
// debounce
|
|
_delay_ms(200);
|
|
|
|
loop_until_bit_is_set(PINK, PINK0);
|
|
set_display(&PORTF, val, false);
|
|
}
|
|
}
|