This commit is contained in:
Lea 2023-08-29 20:18:30 +02:00
parent bb17abaa90
commit 8b302d2ae6
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
2 changed files with 19 additions and 1 deletions

20
main.c
View file

@ -13,6 +13,7 @@
int timer_start = 0xffff - (F_CPU / 1024 / 1000); int timer_start = 0xffff - (F_CPU / 1024 / 1000);
volatile uint32_t ticks = 0; volatile uint32_t ticks = 0;
volatile bool counting = false; volatile bool counting = false;
volatile bool beeping = false;
void start_timer() { void start_timer() {
// Sets the Clock Select. See table on page 157 the Atmel datasheet. // Sets the Clock Select. See table on page 157 the Atmel datasheet.
@ -39,6 +40,12 @@ void main() {
ISR(TIMER1_OVF_vect) { ISR(TIMER1_OVF_vect) {
TCNT1 = timer_start; // TODO figure out how to get the correct number TCNT1 = timer_start; // TODO figure out how to get the correct number
if (counting) ticks += 1; if (counting) ticks += 1;
if (bit_is_set(PIND, PIND0)) {
PORTD &= 0b11111110;
} else if (beeping) {
PORTD |= 0b00000001;
}
} }
void prog_7segment() { void prog_7segment() {
@ -67,19 +74,28 @@ void prog_7segment() {
} }
} }
void beep() {
beeping = true;
_delay_ms(50);
beeping = false;
}
void prog_7segment_4digit() { void prog_7segment_4digit() {
DDRF = 0b11111111; DDRF = 0b11111111;
DDRK = 0b00001111; DDRK = 0b00001111;
DDRD = 0b00000001;
PORTK = 0b11000000; // set pull-up PORTK = 0b11000000; // set pull-up
float num = 0.0f; float num = 0.0f;
bool pressed_pause = false; bool pressed_pause = false;
bool pressed_clear = false;
while(1) { while(1) {
show_float(ticks / 1000.0f); show_float(ticks / 1000.0f);
float sleep_time = update_display(); float sleep_time = update_display();
if (!pressed_pause && bit_is_clear(PINK, PINK7)) { if (!pressed_pause && bit_is_clear(PINK, PINK7)) {
beep();
counting = !counting; counting = !counting;
pressed_pause = true; pressed_pause = true;
} else if (pressed_pause && bit_is_set(PINK, PINK7)) { } else if (pressed_pause && bit_is_set(PINK, PINK7)) {
@ -87,8 +103,10 @@ void prog_7segment_4digit() {
} }
if (bit_is_clear(PINK, PINK6)) { if (bit_is_clear(PINK, PINK6)) {
if (!pressed_clear) beep(50);
ticks = 0; ticks = 0;
counting = false; counting = false;
} pressed_clear = true;
} else pressed_clear = false;
} }
} }

BIN
pinout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 KiB