microcontrolling/lib/7segment.c

35 lines
858 B
C
Raw Normal View History

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
*
* TODO pass register as parameter
*/
void set_display_raw(volatile uint8_t * header, uint8_t data) {
*header = data;
}
void set_display(volatile uint8_t * header, uint8_t value, bool period) {
uint8_t byte = period << 7;
switch(value) {
case 0: byte |= 0x3f; break;
case 1: byte |= 0x06; break;
case 2: byte |= 0x5b; break;
case 3: byte |= 0x4f; break;
case 4: byte |= 0x66; break;
case 5: byte |= 0x6d; break;
case 6: byte |= 0x7d; break;
case 7: byte |= 0x07; break;
case 8: byte |= 0x7f; break;
case 9: byte |= 0x6f; break;
default: byte &= 0x10000000; break;
}
set_display_raw(header, byte);
}