-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx15_disp.ino
83 lines (71 loc) · 2.53 KB
/
x15_disp.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
uint8_t dispFramebuffer[32];
void dispSetup() {
memset(dispFramebuffer, 0, sizeof(dispFramebuffer));
pinMode(PIN_DISP_DATA, OUTPUT);
pinMode(PIN_DISP_CLK, OUTPUT);
pinMode(PIN_DISP_LOAD, OUTPUT);
digitalWrite(PIN_DISP_LOAD, HIGH);
dispSendAll(15, 0); // disable display test mode
dispSendAll(11, 7); // set maximum scanlimit (8 rows)
dispSendAll(9, 0); // disable BCD decoding (only for 7-seg displays)
dispSetBrightness(8); // set initial brightness
dispSendAll(12, 1); // enable display
}
void dispSetBrightness(int8_t val) {
dispSendAll(10, constrain(val, 0, 15));
}
void dispSetImage(const uint8_t *data) {
memcpy_P(dispFramebuffer, data, sizeof(dispFramebuffer));
dispUpdate();
}
void dispSendAll(uint8_t command, uint8_t data) {
digitalWrite(PIN_DISP_LOAD, LOW);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, command);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, data);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, command);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, data);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, command);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, data);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, command);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, data);
digitalWrite(PIN_DISP_LOAD, HIGH);
}
void dispUpdate() {
uint8_t fbPos = 28;
for (uint8_t i = 0; i < 8; i++) {
digitalWrite(PIN_DISP_LOAD, LOW);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, i + 1);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, LSBFIRST, dispFramebuffer[fbPos + 3]);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, i + 1);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, LSBFIRST, dispFramebuffer[fbPos + 2]);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, i + 1);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, LSBFIRST, dispFramebuffer[fbPos + 1]);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, MSBFIRST, i + 1);
shiftOut(PIN_DISP_DATA, PIN_DISP_CLK, LSBFIRST, dispFramebuffer[fbPos]);
digitalWrite(PIN_DISP_LOAD, HIGH);
fbPos -= 4;
}
}
void dispShowDigit(const uint8_t num, const uint8_t pos) {
for (uint8_t i = 0; i < 8; i++) {
dispFramebuffer[pos + (i << 2)] = pgm_read_byte(numbers + (num << 3) + i);
}
}
void dispShowNumber(const uint16_t num) {
uint16_t n = num;
memset(dispFramebuffer, 0, sizeof(dispFramebuffer));
dispShowDigit(n % 10, 3);
n /= 10;
if (n) {
dispShowDigit(n % 10, 2);
n /= 10;
if (n) {
dispShowDigit(n % 10, 1);
n /= 10;
if (n) {
dispShowDigit(n % 10, 0);
}
}
}
dispUpdate();
}