interrupt stuff
This commit is contained in:
parent
e393c10801
commit
eb9ac17e13
58581
atmega640-1280-1281-2560-2561_datasheet.pdf
Normal file
58581
atmega640-1280-1281-2560-2561_datasheet.pdf
Normal file
File diff suppressed because one or more lines are too long
|
@ -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
29
main.c
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue