diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-02-04 11:04:04 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-02-04 12:55:37 +0530 |
| commit | cc9d915435a61d71f11cffa264cf941de58fe444 (patch) | |
| tree | dc190a76b952e26942c298745f5321c5fb0d95ac /src/display.c | |
| parent | f0423ae9af947512f5200da1ffd3c5adf81d5d7f (diff) | |
| download | daft-watch-cc9d915435a61d71f11cffa264cf941de58fe444.tar.gz daft-watch-cc9d915435a61d71f11cffa264cf941de58fe444.zip | |
Switch from internal clock to crystal + button
Diffstat (limited to 'src/display.c')
| -rw-r--r-- | src/display.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/display.c b/src/display.c new file mode 100644 index 0000000..5f2d7f3 --- /dev/null +++ b/src/display.c @@ -0,0 +1,41 @@ +#include <avr/io.h> +#include <stdint.h> +#include <util/delay.h> + +#include "display.h" + +// "_gfedcba" +// Reversed because a-g is mapped to pa0-6. (pa7 is decimal) +// Complemented because display is common anode +const uint32_t digit_masks[] = { + 0b01000000, 0b01111001, 0b00100100, 0b00110000, 0b00011001, + 0b00010010, 0b00000010, 0b01111000, 0b00000000, 0b00010000, +}; + +void write_digit(uint8_t digit) { + if (digit > 9 || digit < 0) + return; + PORTA = digit_masks[digit]; +} + +void write_time(uint16_t hour, uint16_t minute) { + uint8_t minute_digit1 = minute % 10; + uint8_t minute_digit2 = minute / 10; + // unsigned short hour_digit1 = hour % 10; + // unsigned short hour_digit2 = hour / 10; + +#ifdef STUBBED + printf("\r:: %d %d", minute_digit2, minute_digit1); + fflush(stdout); +#endif + + write_digit(minute_digit1); + PORTA |= (1 << PA7); + _delay_ms(10); + PORTA &= ~(1 << PA7); + + write_digit(minute_digit2); + PORTB |= (1 << PB2); + _delay_ms(10); + PORTB &= ~(1 << PB2); +} |
