-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
164 lines (139 loc) · 3.35 KB
/
main.c
File metadata and controls
164 lines (139 loc) · 3.35 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Implements a two digit seven segment common cathode display driver.
* The same approach will also drive a common anode with the same PCB
* layout by reversing the high/low logic of the pins below.
*/
#include "mcc_generated_files/mcc.h"
int readInput() {
// MK11 PCB layout accident
bool mk2 = false;
// MK1 DM9368 - not pic
// MK2 PIC WITH WINGS BUT WIRING WRONG
// MK3 SKINNY
// #define BAD_BCB_WIRING
#ifndef BAD_BCB_WIRING
return
(DIN_0_GetValue() << 0) +
(DIN_1_GetValue() << 1) +
(DIN_2_GetValue() << 2) +
(DIN_3_GetValue() << 3) +
(DIN_4_GetValue() << 4) +
(DIN_5_GetValue() << 5) +
(DIN_6_GetValue() << 6) +
(DIN_7_GetValue() << 7);
#else
return
(DIN_0_GetValue() << 3) +
(DIN_1_GetValue() << 2) +
(DIN_2_GetValue() << 1) +
(DIN_3_GetValue() << 0) +
(DIN_4_GetValue() << 4) +
(DIN_5_GetValue() << 5) +
(DIN_6_GetValue() << 6) +
(DIN_7_GetValue() << 7);
#endif
}
void display(int dig, int v) {
bool a;
bool b;
bool c;
bool d;
bool e;
bool f;
bool g;
a = b = c = d = e = f = g = false;
switch (v) {
case 0:
a = b = c = d = e = f = true;
break;
case 1:
b = c = true;
break;
case 2:
a = b = e = d = g = true;
break;
case 3:
a = b = c = d = g = true;
break;
case 4:
b = c = f = g = true;
break;
case 5:
a = c = d = f = g = true;
break;
case 6:
a = c = d = e = f = g = true;
break;
case 7:
a = b = c = true;
break;
case 8:
a = b = c = d = e = f = g = true;
break;
case 9:
a = b = c = d = f = g = true;
break;
case 10:
a = b = c = d = e = g = true;
break;
case 11:
c = d = e = f = g = true;
break;
case 12:
a = d = e = f = true;
break;
case 13:
b = c = d = e = g = true;
break;
case 14:
a = d = e = f = g = true;
break;
case 15:
a = e = f = g = true;
break;
}
// turn off display
DIGIT_L_LAT = 1; // inactive
DIGIT_H_LAT = 1; // inactive
SEG_A_LAT = a;
SEG_B_LAT = b;
SEG_C_LAT = c;
SEG_D_LAT = d;
SEG_E_LAT = e;
SEG_F_LAT = f;
SEG_G_LAT = g;
if (dig == 0) {
DIGIT_L_LAT = 0; // active
} else {
DIGIT_H_LAT = 0; // active
}
}
// make this long enough that the display is mostly on.
void sleep() {
int i = 2;
while (i-->0) {
// pass
}
}
/*
Main application
*/
#define LOWER 0
#define UPPER 1
void main(void) {
SYSTEM_Initialize();
while (1) {
unsigned int sample = readInput();
// Add your application code
display(LOWER, sample & 0x0f);
sleep();
__delay_us(500);
readInput();
display(UPPER, sample >> 4);
sleep();
__delay_us(500);
}
}
/**
End of File
*/