Last active
August 29, 2015 14:25
-
-
Save jaseg/a451ca60f48b94df45ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef TEST | |
#include <stdint.h> | |
#include <stdio.h> | |
uint8_t LCDDR0=0, | |
LCDDR1=0, | |
LCDDR2=0, | |
LCDDR3=0, | |
LCDDR4=0, | |
LCDDR5=0, | |
LCDDR6=0, | |
LCDDR7=0; | |
#endif | |
struct { | |
uint8_t digits[3], /* 0-9, 10->disabled */ | |
warning:1, /* 022 */ | |
thermometer:1, /* 021 */ | |
window:1, /* 020 */ | |
percent:1, /* 019 */ | |
degrees:1, /* 016 */ | |
comma:1, /* 120 */ | |
rel:1, /* 116 */ | |
bat:2, /* 0-3 */ | |
bat_frame:1;/* 118 */ | |
} lcd_st; | |
#define SEG(x) (1<<(x)) | |
#define ALL 0x7F | |
uint8_t digit_patterns[11] = { | |
/* segments numbered left to right, top to bottom: | |
* /-0-\ | |
* 1 2 | |
* +-3-+ | |
* 4 5 | |
* \-6-/ | |
*/ | |
[0] = ALL - SEG(3), | |
[1] = SEG(2) + SEG(5), | |
[2] = ALL - SEG(1) - SEG(5), | |
[3] = ALL - SEG(1) - SEG(4), | |
[4] = SEG(1) + SEG(2) + SEG(3) + SEG(5), | |
[5] = ALL - SEG(2) - SEG(4), | |
[6] = ALL - SEG(2), | |
[7] = SEG(0) + SEG(2) + SEG(5), | |
[8] = ALL, | |
[9] = ALL - SEG(4), | |
[10]= 0 | |
}; | |
#undef SEG | |
#undef ALL | |
#define REG(v, s) ((!!(v))<<(s)) | |
void update_display(void) { | |
union { | |
struct { | |
uint8_t s6:1, | |
s5:1, | |
s4:1, | |
s3:1, | |
s2:1, | |
s1:1, | |
s0:1; | |
}; | |
uint8_t pat; | |
} d0 = {.pat=digit_patterns[lcd_st.digits[0]]}, | |
d1 = {.pat=digit_patterns[lcd_st.digits[0]]}, | |
d2 = {.pat=digit_patterns[lcd_st.digits[0]]}; | |
LCDDR0 = REG(d0.s1, 0) | REG(d0.s0, 1) | REG(d0.s2, 2) | |
| REG(d1.s1, 3) | REG(d1.s0, 4) | REG(d1.s2, 5) | |
| REG(d2.s1, 6) | REG(d2.s0, 7); | |
LCDDR2 = REG(lcd_st.degrees, 0) | |
| REG(lcd_st.bat>0, 1) | |
| REG(lcd_st.bat>1, 2) | |
| REG(lcd_st.percent, 3) | |
| REG(lcd_st.window, 4) | |
| REG(lcd_st.thermometer, 5) | |
| REG(lcd_st.warning, 6); | |
LCDDR5 = REG(d0.s4, 0) | REG(d0.s3, 1) | REG(d0.s5, 2) | |
| REG(d1.s4, 3) | REG(d1.s3, 4) | REG(d1.s5, 5) | |
| REG(d2.s4, 6) | REG(d2.s3, 7); | |
LCDDR7 = REG(d2.s6, 3) | REG(d1.s6, 5) | REG(d0.s6, 6) | |
| REG(lcd_st.rel, 0) | |
| REG(lcd_st.bat>2, 1) | |
| REG(lcd_st.window, 2) | |
| REG(lcd_st.comma, 4); | |
} | |
#undef REG | |
#ifdef TEST | |
static inline void print_regs(void) { | |
update_display(); | |
printf("digits: %d%d%d warning: %d thermometer: %d window: %d percent: %d degrees: %d comma: %d rel: %d bat: %d bat_frame: %d\n", | |
lcd_st.digits[0], | |
lcd_st.digits[1], | |
lcd_st.digits[2], | |
lcd_st.warning, | |
lcd_st.thermometer, | |
lcd_st.window, | |
lcd_st.percent, | |
lcd_st.degrees, | |
lcd_st.comma, | |
lcd_st.rel, | |
lcd_st.bat, | |
lcd_st.bat_frame); | |
printf("%.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", LCDDR0, LCDDR1, LCDDR2, LCDDR3, LCDDR4, LCDDR5, LCDDR6, LCDDR7); | |
printf("----\n\n"); | |
} | |
int main(void) { | |
lcd_st.bat_frame = 1; | |
printf("BAT test\n"); | |
for (uint8_t i=0; i<4; i++) { | |
lcd_st.bat = i; | |
print_regs(); | |
} | |
lcd_st.bat = 0; | |
printf("DIGIT test\n"); | |
lcd_st.digits[0] = 1; | |
print_regs(); | |
lcd_st.digits[0] = 0; | |
lcd_st.digits[1] = 1; | |
print_regs(); | |
lcd_st.digits[1] = 0; | |
lcd_st.digits[2] = 1; | |
print_regs(); | |
lcd_st.digits[2] = 0; | |
for (int j=0; j<3; j++) { | |
printf("DIGIT %d SEGMENT test\n", j); | |
for (int i=0; i<10; i++) { | |
lcd_st.digits[j] = i; | |
print_regs(); | |
} | |
lcd_st.digits[j] = 0; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment