interrupts but real
This commit is contained in:
parent
eb9ac17e13
commit
517d589650
13
main.c
13
main.c
|
@ -10,19 +10,20 @@
|
|||
#include "lib/7segment.h"
|
||||
#include "lib/7segment_4digits.h"
|
||||
|
||||
volatile int ticks = 0;
|
||||
int timer_start = 0xffff - (F_CPU / 1024 / 1000);
|
||||
volatile uint32_t 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);
|
||||
TCCR1B |= _BV(CS10) | _BV(CS12); // clk/1024
|
||||
|
||||
// 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;
|
||||
TCNT1 = timer_start;
|
||||
|
||||
// Enable interrupts
|
||||
sei();
|
||||
|
@ -36,8 +37,8 @@ void main() {
|
|||
// 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++;
|
||||
TCNT1 = timer_start; // TODO figure out how to get the correct number
|
||||
ticks += 1;
|
||||
}
|
||||
|
||||
void prog_7segment() {
|
||||
|
@ -76,7 +77,7 @@ void prog_7segment_4digit() {
|
|||
bool pressed = false;
|
||||
|
||||
while(1) {
|
||||
show_float(ticks);
|
||||
show_float(ticks / 1000.0f);
|
||||
float sleep_time = update_display();
|
||||
|
||||
if (!pressed && bit_is_clear(PINK, PINK7)) {
|
||||
|
|
Loading…
Reference in a new issue