-
Notifications
You must be signed in to change notification settings - Fork 19
/
ledmatrix88.c
216 lines (200 loc) · 5.8 KB
/
ledmatrix88.c
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
ledmatrix88 lib 0x01
copyright (c) Davide Gironi, 2013
Released under GPLv3.
Please refer to LICENSE file for licensing information.
*/
#include <stdio.h>
#include <avr/io.h>
#include "ledmatrix88.h"
volatile uint8_t ledmatrix88_col = 0; //contains column data
volatile uint8_t ledmatrix88_row = 0; //contains row data
/*
* get current col value
*/
uint8_t ledmatrix88_getcol(void) {
return ledmatrix88_col;
}
/*
* get current row value
*/
uint8_t ledmatrix88_gettrow(void) {
return ledmatrix88_row;
}
/*
* set col value
*/
void ledmatrix88_setcol(uint8_t col) {
ledmatrix88_col = col;
}
/*
* get row value
*/
void ledmatrix88_setrow(uint8_t row) {
ledmatrix88_row = row;
}
/*
* set ouput to zero
*/
void ledmatrix88_zero(void) {
ledmatrix88_setcol(0);
ledmatrix88_setrow(0);
}
/*
* init ledmatrix
*/
void ledmatrix88_init() {
//init col ports
#if LEDMATRIX88_COLS >= 1
LEDMATRIX88_COL1_DDR |= (1<<LEDMATRIX88_COL1_PINOUT); //output
#endif
#if LEDMATRIX88_COLS >= 2
LEDMATRIX88_COL2_DDR |= (1<<LEDMATRIX88_COL2_PINOUT); //output
#endif
#if LEDMATRIX88_COLS >= 3
LEDMATRIX88_COL3_DDR |= (1<<LEDMATRIX88_COL3_PINOUT); //output
#endif
#if LEDMATRIX88_COLS >= 4
LEDMATRIX88_COL4_DDR |= (1<<LEDMATRIX88_COL4_PINOUT); //output
#endif
#if LEDMATRIX88_COLS >= 5
LEDMATRIX88_COL5_DDR |= (1<<LEDMATRIX88_COL5_PINOUT); //output
#endif
#if LEDMATRIX88_COLS >= 6
LEDMATRIX88_COL6_DDR |= (1<<LEDMATRIX88_COL6_PINOUT); //output
#endif
#if LEDMATRIX88_COLS >= 7
LEDMATRIX88_COL7_DDR |= (1<<LEDMATRIX88_COL7_PINOUT); //output
#endif
#if LEDMATRIX88_COLS >= 8
LEDMATRIX88_COL8_DDR |= (1<<LEDMATRIX88_COL8_PINOUT); //output
#endif
//init row ports
#if LEDMATRIX88_ROWS >= 1
LEDMATRIX88_ROW1_DDR |= (1<<LEDMATRIX88_ROW1_PINOUT); //output
#endif
#if LEDMATRIX88_ROWS >= 2
LEDMATRIX88_ROW2_DDR |= (1<<LEDMATRIX88_ROW2_PINOUT); //output
#endif
#if LEDMATRIX88_ROWS >= 3
LEDMATRIX88_ROW3_DDR |= (1<<LEDMATRIX88_ROW3_PINOUT); //output
#endif
#if LEDMATRIX88_ROWS >= 4
LEDMATRIX88_ROW4_DDR |= (1<<LEDMATRIX88_ROW4_PINOUT); //output
#endif
#if LEDMATRIX88_ROWS >= 5
LEDMATRIX88_ROW5_DDR |= (1<<LEDMATRIX88_ROW5_PINOUT); //output
#endif
#if LEDMATRIX88_ROWS >= 6
LEDMATRIX88_ROW6_DDR |= (1<<LEDMATRIX88_ROW6_PINOUT); //output
#endif
#if LEDMATRIX88_ROWS >= 7
LEDMATRIX88_ROW7_DDR |= (1<<LEDMATRIX88_ROW7_PINOUT); //output
#endif
#if LEDMATRIX88_ROWS >= 8
LEDMATRIX88_ROW8_DDR |= (1<<LEDMATRIX88_ROW8_PINOUT); //output
#endif
}
/*
* output data
*/
void ledmatrix88_print() {
//emit column data
#if LEDMATRIX88_COLS >= 1
if(ledmatrix88_col & (1<<0))
LEDMATRIX88_COL1_PORT |= (1<<LEDMATRIX88_COL1_PINOUT); //on
else
LEDMATRIX88_COL1_PORT &= ~(1<<LEDMATRIX88_COL1_PINOUT); //off
#endif
#if LEDMATRIX88_COLS >= 2
if(ledmatrix88_col & (1<<1))
LEDMATRIX88_COL2_PORT |= (1<<LEDMATRIX88_COL2_PINOUT); //on
else
LEDMATRIX88_COL2_PORT &= ~(1<<LEDMATRIX88_COL2_PINOUT); //off
#endif
#if LEDMATRIX88_COLS >= 3
if(ledmatrix88_col & (1<<2))
LEDMATRIX88_COL3_PORT |= (1<<LEDMATRIX88_COL3_PINOUT); //on
else
LEDMATRIX88_COL3_PORT &= ~(1<<LEDMATRIX88_COL3_PINOUT); //off
#endif
#if LEDMATRIX88_COLS >= 4
if(ledmatrix88_col & (1<<3))
LEDMATRIX88_COL4_PORT |= (1<<LEDMATRIX88_COL4_PINOUT); //on
else
LEDMATRIX88_COL4_PORT &= ~(1<<LEDMATRIX88_COL4_PINOUT); //off
#endif
#if LEDMATRIX88_COLS >= 5
if(ledmatrix88_col & (1<<4))
LEDMATRIX88_COL5_PORT |= (1<<LEDMATRIX88_COL5_PINOUT); //on
else
LEDMATRIX88_COL5_PORT &= ~(1<<LEDMATRIX88_COL5_PINOUT); //off
#endif
#if LEDMATRIX88_COLS >= 6
if(ledmatrix88_col & (1<<5))
LEDMATRIX88_COL6_PORT |= (1<<LEDMATRIX88_COL6_PINOUT); //on
else
LEDMATRIX88_COL6_PORT &= ~(1<<LEDMATRIX88_COL6_PINOUT); //off
#endif
#if LEDMATRIX88_COLS >= 7
if(ledmatrix88_col & (1<<6))
LEDMATRIX88_COL7_PORT |= (1<<LEDMATRIX88_COL7_PINOUT); //on
else
LEDMATRIX88_COL7_PORT &= ~(1<<LEDMATRIX88_COL7_PINOUT); //off
#endif
#if LEDMATRIX88_COLS >= 8
if(ledmatrix88_col & (1<<7))
LEDMATRIX88_COL8_PORT |= (1<<LEDMATRIX88_COL8_PINOUT); //on
else
LEDMATRIX88_COL8_PORT &= ~(1<<LEDMATRIX88_COL8_PINOUT); //off
#endif
//emit row data
#if LEDMATRIX88_ROWS >= 1
if(ledmatrix88_row & (1<<0))
LEDMATRIX88_ROW1_PORT |= (1<<LEDMATRIX88_ROW1_PINOUT); //on
else
LEDMATRIX88_ROW1_PORT &= ~(1<<LEDMATRIX88_ROW1_PINOUT); //off
#endif
#if LEDMATRIX88_ROWS >= 2
if(ledmatrix88_row & (1<<1))
LEDMATRIX88_ROW2_PORT |= (1<<LEDMATRIX88_ROW2_PINOUT); //on
else
LEDMATRIX88_ROW2_PORT &= ~(1<<LEDMATRIX88_ROW2_PINOUT); //off
#endif
#if LEDMATRIX88_ROWS >= 3
if(ledmatrix88_row & (1<<2))
LEDMATRIX88_ROW3_PORT |= (1<<LEDMATRIX88_ROW3_PINOUT); //on
else
LEDMATRIX88_ROW3_PORT &= ~(1<<LEDMATRIX88_ROW3_PINOUT); //off
#endif
#if LEDMATRIX88_ROWS >= 4
if(ledmatrix88_row & (1<<3))
LEDMATRIX88_ROW4_PORT |= (1<<LEDMATRIX88_ROW4_PINOUT); //on
else
LEDMATRIX88_ROW4_PORT &= ~(1<<LEDMATRIX88_ROW4_PINOUT); //off
#endif
#if LEDMATRIX88_ROWS >= 5
if(ledmatrix88_row & (1<<4))
LEDMATRIX88_ROW5_PORT |= (1<<LEDMATRIX88_ROW5_PINOUT); //on
else
LEDMATRIX88_ROW5_PORT &= ~(1<<LEDMATRIX88_ROW5_PINOUT); //off
#endif
#if LEDMATRIX88_ROWS >= 6
if(ledmatrix88_row & (1<<5))
LEDMATRIX88_ROW6_PORT |= (1<<LEDMATRIX88_ROW6_PINOUT); //on
else
LEDMATRIX88_ROW6_PORT &= ~(1<<LEDMATRIX88_ROW6_PINOUT); //off
#endif
#if LEDMATRIX88_ROWS >= 7
if(ledmatrix88_row & (1<<6))
LEDMATRIX88_ROW7_PORT |= (1<<LEDMATRIX88_ROW7_PINOUT); //on
else
LEDMATRIX88_ROW7_PORT &= ~(1<<LEDMATRIX88_ROW7_PINOUT); //off
#endif
#if LEDMATRIX88_ROWS >= 8
if(ledmatrix88_row & (1<<7))
LEDMATRIX88_ROW8_PORT |= (1<<LEDMATRIX88_ROW8_PINOUT); //on
else
LEDMATRIX88_ROW8_PORT &= ~(1<<LEDMATRIX88_ROW8_PINOUT); //off
#endif
}