diff --git a/lib/7segment.c b/lib/7segment.c index 6177dc2..2b37fd5 100644 --- a/lib/7segment.c +++ b/lib/7segment.c @@ -14,25 +14,27 @@ void set_display_raw(volatile uint8_t * header, uint8_t data) { *header = data; } -uint8_t digit_to_binary(uint8_t input, uint8_t digit) { +uint8_t digit_to_binary(bool period, uint8_t digit) { + uint8_t val = period << 7; + switch(digit) { - case 0: return input | 0x3f; - case 1: return input | 0x06; - case 2: return input | 0x5b; - case 3: return input | 0x4f; - case 4: return input | 0x66; - case 5: return input | 0x6d; - case 6: return input | 0x7d; - case 7: return input | 0x07; - case 8: return input | 0x7f; - case 9: return input | 0x6f; - // by default only draw the period if it was provided in the input - default: return input & (uint8_t) 0x10000000; + case 0: return val | 0x3f; + case 1: return val | 0x06; + case 2: return val | 0x5b; + case 3: return val | 0x4f; + case 4: return val | 0x66; + case 5: return val | 0x6d; + case 6: return val | 0x7d; + case 7: return val | 0x07; + case 8: return val | 0x7f; + case 9: return val | 0x6f; + // by default draw a dash + default: return 0x01000000; } } void set_display(volatile uint8_t * header, uint8_t value, bool period) { - uint8_t byte = digit_to_binary(period << 7, value); + uint8_t byte = digit_to_binary(period, value); set_display_raw(header, byte); } diff --git a/lib/7segment.h b/lib/7segment.h index 7a816ec..17a220a 100644 --- a/lib/7segment.h +++ b/lib/7segment.h @@ -4,4 +4,4 @@ void set_display_raw(volatile uint8_t * header, uint8_t data); void set_display(volatile uint8_t * header, uint8_t value, bool period); -uint8_t digit_to_binary(uint8_t in, uint8_t digit); +uint8_t digit_to_binary(bool period, uint8_t digit); diff --git a/lib/7segment_4digits.c b/lib/7segment_4digits.c index 68a75d3..f174ab1 100644 --- a/lib/7segment_4digits.c +++ b/lib/7segment_4digits.c @@ -54,6 +54,6 @@ void show_float(float value) { for (int i = 0; i < 4; i++) { bool show_period = digits == i + 1; int digit = get_digit_at_position(full_number, 3 - i); - set_display_value(i, digit_to_binary(show_period << 7, digit)); + set_display_value(i, digit_to_binary(show_period, digit)); } } diff --git a/main.c b/main.c index c2444d1..104406d 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,6 @@ #define __AVR_ATmega2560__ #define F_CPU 16000000UL -#define TICK_BEEP true +#define TICK_BEEP false #include #include