forked from saul-rodriguez/Qtraspberrylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay7seg.cpp
124 lines (100 loc) · 2.24 KB
/
display7seg.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "display7seg.h"
/*
* The DISP3 and DISP6 7-Segment displays are based on the ht16k33 chip.
* The leds are of the type common cathode (-).
* The electrical connection of the digits in the display is:
* [COM5][COM4][COM3][COM2][COM1][COM0]
* [#.] [#.] [#.] [#.] [#.] [#.]
* The segments of the digits are connected as:
* ROW 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8
* SEG . g f e d c b a x x x x x x x x
*
* The logical mapping of the COM registers is:
* ROWs Byte 0 ROWs Byte 1
* COMx 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8
*
*/
const quint8 Display7seg::numbertable[] = {
0x3F, /* 0 */
0x06, /* 1 */
0x5B, /* 2 */
0x4F, /* 3 */
0x66, /* 4 */
0x6D, /* 5 */
0x7D, /* 6 */
0x07, /* 7 */
0x7F, /* 8 */
0x6F, /* 9 */
0x77, /* a */
0x7C, /* b */
0x39, /* C */
0x5E, /* d */
0x79, /* E */
0x71, /* F */
};
Display7seg::Display7seg(QObject *parent) :
Ht16k33(parent)
{
}
void Display7seg::writeint(qint16 num)
{
quint16 res,absol;
qint16 aux[6];
quint8 sign;
int i;
for (i=0;i<6;i++)
aux[i] = 0;
if (num < 0) {
sign = 1;
absol = (-num);
} else {
sign = 0;
absol = num;
}
for (i=0;i<6;i++) {
res = absol%10;
absol /= 10;
aux[i] = numbertable[res];
if (!absol) break;
}
if (sign && i<5) {
i++;
aux[i] = 0x40;
}
for (i = 0; i < 6; i++) {
displaybuffer[i] = aux[i];
}
writeDisplay(6);
}
void Display7seg::writeint_zeropad(qint16 num,quint8 pad)
{
quint16 res,absol;
qint16 aux[6];
quint8 sign;
int i;
for (i=0;i<6;i++)
aux[i] = 0;
for (i=0;i<pad;i++)
aux[i] = numbertable[0];
if (num < 0) {
sign = 1;
absol = (-num);
} else {
sign = 0;
absol = num;
}
for (i=0;i<6;i++) {
res = absol%10;
absol /= 10;
aux[i] = numbertable[res];
if (!absol) break;
}
if (sign && i<5) {
i++;
aux[pad] = 0x40;
}
for (i = 0; i < 6; i++) {
displaybuffer[i] = aux[i];
}
writeDisplay(6);
}