summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/display.cc13
-rw-r--r--src/display.h4
-rw-r--r--src/main.cc14
-rw-r--r--src/system.cc4
4 files changed, 17 insertions, 18 deletions
diff --git a/src/display.cc b/src/display.cc
index e06f271..b1b0af5 100644
--- a/src/display.cc
+++ b/src/display.cc
@@ -10,16 +10,23 @@ Display display;
extern volatile uint8_t disp[8];
-void Display::turn_off()
+void Display::disable()
{
TIMSK0 &= ~_BV(TOIE0);
PORTB = 0;
PORTD = 0;
}
-void Display::turn_on()
+void Display::enable()
{
- TIMSK0 |= _BV(TOIE0);
+ // Ports B and D drive the dot matrix display -> set all as output
+ DDRB = 0xff;
+ DDRD = 0xff;
+
+ // Enable 8bit counter with prescaler=8 (-> timer frequency = 1MHz)
+ TCCR0A = _BV(CS01);
+ // raise timer interrupt on counter overflow (-> interrupt frequency = ~4kHz)
+ TIMSK0 = _BV(TOIE0);
}
/*
diff --git a/src/display.h b/src/display.h
index 647e474..cb263d0 100644
--- a/src/display.h
+++ b/src/display.h
@@ -7,8 +7,8 @@
class Display {
public:
Display() {};
- void turn_on(void);
- void turn_off(void);
+ void enable(void);
+ void disable(void);
};
extern Display display;
diff --git a/src/main.cc b/src/main.cc
index ac8b68a..fbb40c9 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -19,20 +19,9 @@ int main (void)
// dito
wdt_disable();
- // Ports B and D drive the dot matrix display -> set all as output
- DDRB = 0xff;
- DDRD = 0xff;
- PORTB = 0;
- PORTD = 0;
-
// Enable pull-ups on PC3 and PC7 (button pins)
PORTC |= _BV(PC3) | _BV(PC7);
- // Enable 8bit counter with prescaler=8 (-> timer frequency = 1MHz)
- TCCR0A = _BV(CS01);
- // raise timer interrupt on counter overflow (-> interrupt frequency = ~4kHz)
- TIMSK0 = _BV(TOIE0);
-
disp[0] = 0x01;
disp[1] = 0x02;
disp[2] = 0x04;
@@ -78,6 +67,7 @@ int main (void)
disp[31] = 0x00;
#endif
+ display.enable();
modem.enable();
sei();
@@ -86,6 +76,8 @@ int main (void)
// nothing to do here, go to idle to save power
SMCR = _BV(SE);
asm("sleep");
+ // The display timer causes a wakeup after 256µs. Run the system
+ // loop after the timer's ISR is done.
rocket.loop();
}
diff --git a/src/system.cc b/src/system.cc
index b98e687..09c0f53 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -32,7 +32,7 @@ void System::loop()
else {
// turn off display to indicate we're about to shut down
- display.turn_off();
+ display.disable();
modem.disable();
@@ -57,7 +57,7 @@ void System::loop()
PCMSK1 &= ~(_BV(PCINT15) | _BV(PCINT11));
// turn on display
- display.turn_on();
+ display.enable();
// ... and modem
modem.enable();