interrupt stuff

This commit is contained in:
Lea 2023-08-29 10:58:36 +02:00
parent e393c10801
commit eb9ac17e13
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
3 changed files with 58616 additions and 1 deletions

File diff suppressed because one or more lines are too long

View file

@ -39,6 +39,13 @@ float update_display() {
}
void show_float(float value) {
if (value >= 10000 || value < 0) {
for (int i = 0; i < 4; i++) {
set_display_value(i, 0b01000000); // minus character
}
return;
}
int digits = num_digits((int)value);
int full_number = value * (int)roundf(powf(10, 4 - digits));

29
main.c
View file

@ -5,14 +5,41 @@
#include <avr/io.h>
#include <util/delay.h>
#include <stdbool.h>
#include <avr/interrupt.h>
#include "lib/util.h"
#include "lib/7segment.h"
#include "lib/7segment_4digits.h"
volatile int ticks = 0;
// https://gist.github.com/Wollw/2381139
void start_timer() {
// Sets the Clock Select. See table on page 157 the Atmel datasheet.
TCCR1B |= _BV(CS10) | _BV(CS12);
// Set the TOIE (Timer Overflow Interrupt Enable) bit
// on TIMSK1 (Timer 1 Interrupt Mask Register).
TIMSK1 |= _BV(TOIE1);
// Sets the current timer value
TCNT1 = 63974;
// Enable interrupts
sei();
}
void main() {
start_timer();
prog_7segment_4digit();
}
// ISR is used to handle interrupts. TIMER1_OVF_vect
// is triggered whenever timer 1 (16 bit) overflows.
ISR(TIMER1_OVF_vect) {
TCNT1 = 63974; // TODO figure out how to get the correct number
ticks++;
}
void prog_7segment() {
DDRF = 0b11111111;
DDRK = 0b00000000;
@ -49,7 +76,7 @@ void prog_7segment_4digit() {
bool pressed = false;
while(1) {
show_float(num);
show_float(ticks);
float sleep_time = update_display();
if (!pressed && bit_is_clear(PINK, PINK7)) {