2023-08-26 17:08:09 +00:00
|
|
|
#include <avr/io.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display pins should be mapped like this:
|
|
|
|
* a b c d e f g DP
|
|
|
|
* 0 1 2 3 4 5 6 7
|
|
|
|
*
|
2023-08-27 19:01:23 +00:00
|
|
|
* d1 d2 d3 d4
|
2023-09-01 07:44:02 +00:00
|
|
|
* 0 1 2 3
|
2023-08-26 17:08:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void set_display_raw(volatile uint8_t * header, uint8_t data) {
|
|
|
|
*header = data;
|
|
|
|
}
|
|
|
|
|
2023-09-01 07:47:56 +00:00
|
|
|
uint8_t digit_to_binary(bool period, uint8_t digit) {
|
|
|
|
uint8_t val = period << 7;
|
|
|
|
|
2023-08-27 19:01:23 +00:00
|
|
|
switch(digit) {
|
2023-09-01 07:47:56 +00:00
|
|
|
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;
|
2023-08-26 17:08:09 +00:00
|
|
|
}
|
2023-08-27 19:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_display(volatile uint8_t * header, uint8_t value, bool period) {
|
2023-09-01 07:47:56 +00:00
|
|
|
uint8_t byte = digit_to_binary(period, value);
|
2023-08-26 17:08:09 +00:00
|
|
|
|
|
|
|
set_display_raw(header, byte);
|
|
|
|
}
|