aboutsummaryrefslogtreecommitdiff
path: root/src/display.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/display.c')
-rw-r--r--src/display.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/display.c b/src/display.c
index 5fccd50..8de5043 100644
--- a/src/display.c
+++ b/src/display.c
@@ -4,6 +4,7 @@
#include <util/delay.h>
#include "display.h"
+#include "rtc.h"
// "_gfedcba"
// Reversed because a-g is mapped to pa0-6. (pa7 is decimal)
@@ -13,20 +14,18 @@ const uint32_t digit_masks[] = {
0b00010010, 0b00000010, 0b01111000, 0b00000000, 0b00010000,
};
-void setup_display() {
- TIMSK1 = 0;
-
- // Set prescaler (Timer clock = F_CPU / 64)
+void display_setup() {
+ // Set prescaler CS01 + CS00 (F_CPU / 64) + CTC
// For 32768Hz -> 32768/64 = 512Hz
- TCCR1B = (1 << CS11) | (1 << CS10) | (1 << WGM12) | (1 << WGM13);
- TCCR1A = (1 << WGM11) | (1 << WGM10);
+ TCCR0B = (1 << CS01) | (1 << CS00) | (1 << WGM02);
+ TCCR0A = (1 << WGM01) | (1 << WGM00);
- TCNT1 = 0; // Start counting from 0
- OCR1A = 1; // 0-1 = 2 counts before timer interrupt (512/2 = 256Hz)
- OCR1B = 0;
+ TCNT0 = 0; // Start counting from 0
+ OCR0A = 1; // 0-1 = 2 counts before timer interrupt (512/2 = 256Hz)
+ OCR0B = 0;
- TIFR1 = (1 << OCF1A) | (1 << OCF1B) | (1 << TOV1); // Clear interrupt flags
- TIMSK1 = (1 << OCIE1A); // Enable timer overflow interrupt
+ TIFR0 = (1 << OCF0A) | (1 << OCF0B) | (1 << TOV0); // Clear interrupt flags
+ TIMSK0 = (1 << OCIE0A); // Enable timer overflow interrupt
// Draw startup state
DDRA |= 0b11111111;
@@ -35,6 +34,19 @@ void setup_display() {
PORTB = (1 << PB2);
}
+volatile uint8_t current_digit = 0;
+
+// Render current digit
+void display_render(void) {
+ DDRA |= 0b11111111;
+ DDRB |= 0b11111111;
+
+ write_time(minutes, seconds, current_digit);
+
+ // Next digit
+ current_digit = (current_digit + 1) % 4;
+}
+
void write_digit(uint8_t digit) {
if (digit > 9 || digit < 0)
return;
@@ -47,25 +59,23 @@ void write_time(uint16_t hour, uint16_t minute, uint8_t mask) {
// unsigned short hour_digit1 = hour % 10;
// unsigned short hour_digit2 = (hour / 10) % 10;
- // _delay_ms(4);
// Reset digit control pins
PORTA &= ~(1 << PA7); // minute digit 1
PORTB &= ~(1 << PB2); // minute digit 2
- // _delay_ms(4);
// cli();
- if (mask & 0b0001 || mask & 0b0100) {
+ if (mask == 0 || mask == 2) {
#ifdef STUBBED
- printf(":: %d\n", minute_digit1);
+ printf(" %d\n", minute_digit1);
fflush(stdout);
#endif
write_digit(minute_digit1);
PORTA |= (1 << PA7);
}
- if (mask & 0b0010 || mask & 0b1000) {
+ if (mask == 1 || mask == 3) {
#ifdef STUBBED
- printf(":: %d\n", minute_digit2);
+ printf(":: %d", minute_digit2);
fflush(stdout);
#endif
write_digit(minute_digit2);