|
@@ -63,18 +63,38 @@ static uint8_t LEDs[8] = { 0 };
|
63
|
63
|
|
64
|
64
|
void Max7219_PutByte(uint8_t data) {
|
65
|
65
|
for (uint8_t i = 8; i--;) {
|
66
|
|
- WRITE(MAX7219_CLK_PIN, LOW); // tick
|
67
|
|
- WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
68
|
|
- WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
66
|
+ #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
|
67
|
+ // to let the signal wires stabilize.
|
|
68
|
+ WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
69
|
+ delayMicroseconds(5);
|
|
70
|
+ WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
|
71
|
+ delayMicroseconds(5);
|
|
72
|
+ WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
73
|
+ delayMicroseconds(5);
|
|
74
|
+ #else
|
|
75
|
+ WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
76
|
+ WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
|
77
|
+ WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
78
|
+ #endif
|
|
79
|
+
|
69
|
80
|
data <<= 1;
|
70
|
81
|
}
|
71
|
82
|
}
|
72
|
83
|
|
73
|
84
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
74
|
85
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
|
86
|
+ #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
|
87
|
+ delayMicroseconds(5); // to let the signal wires stabilize.
|
|
88
|
+ #endif
|
75
|
89
|
Max7219_PutByte(reg); // specify register
|
76
|
90
|
Max7219_PutByte(data); // put data
|
|
91
|
+ #ifdef CPU_32_BIT
|
|
92
|
+ delayMicroseconds(5);
|
|
93
|
+ #endif
|
77
|
94
|
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
|
95
|
+ #ifdef CPU_32_BIT
|
|
96
|
+ delayMicroseconds(5);
|
|
97
|
+ #endif
|
78
|
98
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
79
|
99
|
}
|
80
|
100
|
|
|
@@ -135,6 +155,7 @@ void Max7219_init() {
|
135
|
155
|
SET_OUTPUT(MAX7219_CLK_PIN);
|
136
|
156
|
|
137
|
157
|
OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
|
|
158
|
+ delay(1);
|
138
|
159
|
|
139
|
160
|
//initiation of the max 7219
|
140
|
161
|
Max7219(max7219_reg_scanLimit, 0x07);
|
|
@@ -187,9 +208,13 @@ void Max7219_init() {
|
187
|
208
|
void Max7219_idle_tasks() {
|
188
|
209
|
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
|
189
|
210
|
static int debug_cnt = 0;
|
190
|
|
- if (debug_cnt++ > 100) {
|
191
|
|
- Max7219_LED_Toggle(7, 7);
|
192
|
|
- debug_cnt = 0;
|
|
211
|
+ #ifdef CPU_32_BIT
|
|
212
|
+ if (debug_cnt++ > 400) {
|
|
213
|
+ #else
|
|
214
|
+ if (debug_cnt++ > 100) {
|
|
215
|
+ #endif
|
|
216
|
+ Max7219_LED_Toggle(7, 7);
|
|
217
|
+ debug_cnt = 0;
|
193
|
218
|
}
|
194
|
219
|
#endif
|
195
|
220
|
|