|
@@ -63,54 +63,41 @@
|
63
|
63
|
|
64
|
64
|
static uint8_t LEDs[8] = { 0 };
|
65
|
65
|
|
|
66
|
+#ifdef CPU_32_BIT
|
|
67
|
+ #define MS_DELAY() delayMicroseconds(5) // 32-bit processors need a delay to stabilize the signal
|
|
68
|
+#else
|
|
69
|
+ #define MS_DELAY() NOOP
|
|
70
|
+#endif
|
|
71
|
+
|
66
|
72
|
void Max7219_PutByte(uint8_t data) {
|
67
|
73
|
CRITICAL_SECTION_START
|
68
|
74
|
for (uint8_t i = 8; i--;) {
|
69
|
|
- #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
70
|
|
- delayMicroseconds(5); // to let the signal wires stabilize.
|
71
|
|
- WRITE(MAX7219_CLK_PIN, LOW); // tick
|
72
|
|
- delayMicroseconds(5);
|
73
|
|
- WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
74
|
|
- delayMicroseconds(5);
|
75
|
|
- WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
76
|
|
- delayMicroseconds(5);
|
77
|
|
- #else
|
78
|
|
- WRITE(MAX7219_CLK_PIN, LOW); // tick
|
79
|
|
- WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
80
|
|
- WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
81
|
|
- #endif
|
82
|
|
-
|
|
75
|
+ MS_DELAY();
|
|
76
|
+ WRITE(MAX7219_CLK_PIN, LOW); // tick
|
|
77
|
+ MS_DELAY();
|
|
78
|
+ WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
|
|
79
|
+ MS_DELAY();
|
|
80
|
+ WRITE(MAX7219_CLK_PIN, HIGH); // tock
|
|
81
|
+ MS_DELAY();
|
83
|
82
|
data <<= 1;
|
84
|
83
|
}
|
85
|
84
|
CRITICAL_SECTION_END
|
86
|
85
|
}
|
87
|
86
|
|
88
|
87
|
void Max7219(const uint8_t reg, const uint8_t data) {
|
89
|
|
- #ifdef CPU_32_BIT
|
90
|
|
- delayMicroseconds(5);
|
91
|
|
- #endif
|
|
88
|
+ MS_DELAY();
|
92
|
89
|
CRITICAL_SECTION_START
|
93
|
90
|
WRITE(MAX7219_LOAD_PIN, LOW); // begin
|
94
|
|
- #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
|
95
|
|
- delayMicroseconds(5); // to let the signal wires stabilize.
|
96
|
|
- #endif
|
|
91
|
+ MS_DELAY();
|
97
|
92
|
Max7219_PutByte(reg); // specify register
|
98
|
|
- #ifdef CPU_32_BIT
|
99
|
|
- delayMicroseconds(5);
|
100
|
|
- #endif
|
|
93
|
+ MS_DELAY();
|
101
|
94
|
Max7219_PutByte(data); // put data
|
102
|
|
- #ifdef CPU_32_BIT
|
103
|
|
- delayMicroseconds(5);
|
104
|
|
- #endif
|
|
95
|
+ MS_DELAY();
|
105
|
96
|
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
|
106
|
|
- #ifdef CPU_32_BIT
|
107
|
|
- delayMicroseconds(5);
|
108
|
|
- #endif
|
|
97
|
+ MS_DELAY();
|
109
|
98
|
WRITE(MAX7219_LOAD_PIN, HIGH);
|
110
|
99
|
CRITICAL_SECTION_END
|
111
|
|
- #ifdef CPU_32_BIT
|
112
|
|
- delayMicroseconds(5);
|
113
|
|
- #endif
|
|
100
|
+ MS_DELAY();
|
114
|
101
|
}
|
115
|
102
|
|
116
|
103
|
void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
|