Rev 728 | Rev 757 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 728 | Rev 736 | ||
---|---|---|---|
Line 25... | Line 25... | ||
25 | #include <string.h> |
25 | #include <string.h> |
26 | #include <stdlib.h> |
26 | #include <stdlib.h> |
27 | #include "main.h" |
27 | #include "main.h" |
28 | #include "max7456_software_spi.h" |
28 | #include "max7456_software_spi.h" |
Line -... | Line 29... | ||
- | 29 | ||
- | 30 | ||
- | 31 | char conv_array[7]; // general array for number -> char conversation |
|
29 | 32 | ||
30 | /* ########################################################################## |
33 | /* ########################################################################## |
31 | * MAX7456 SPI & Display stuff |
34 | * MAX7456 SPI & Display stuff |
Line 32... | Line 35... | ||
32 | * ##########################################################################*/ |
35 | * ##########################################################################*/ |
Line 89... | Line 92... | ||
89 | // clearing takes 12uS according to maxim so lets wait longer |
92 | // clearing takes 12uS according to maxim so lets wait longer |
90 | _delay_us(20); |
93 | _delay_us(20); |
91 | } |
94 | } |
Line -... | Line 95... | ||
- | 95 | ||
92 | 96 | ||
93 | 97 | #if (ALLCHARSDEBUG|(WRITECHARS != -1)) |
|
94 | /** |
98 | /** |
95 | * for testing write all chars to screen |
99 | * for testing write all chars to screen |
96 | */ |
100 | */ |
Line 103... | Line 107... | ||
103 | x = 3; |
107 | x = 3; |
104 | } |
108 | } |
105 | } |
109 | } |
106 | } |
110 | } |
Line -... | Line 111... | ||
- | 111 | ||
- | 112 | /** |
|
- | 113 | * let the MAX7456 learn a new character at <number> |
|
- | 114 | * with <data>. |
|
- | 115 | */ |
|
- | 116 | void learn_char(uint8_t number, unsigned char* data) { |
|
- | 117 | // select character to write (CMAH) |
|
- | 118 | spi_send_byte(0x09, number); |
|
- | 119 | ||
- | 120 | for (uint8_t i = 0; i < 54; i++) { |
|
- | 121 | // select 4pixel byte of char (CMAL) |
|
- | 122 | spi_send_byte(0x0A, i); |
|
- | 123 | ||
- | 124 | // write 4pixel byte of char (CMDI) |
|
- | 125 | spi_send_byte(0x0B, data[i]); |
|
- | 126 | } |
|
- | 127 | ||
- | 128 | // write to the NVM array from the shadow RAM (CMM) |
|
- | 129 | spi_send_byte(0x08, 0b10100000); |
|
- | 130 | ||
- | 131 | // according to maxim writing to nvram takes about 12ms, lets wait longer |
|
- | 132 | _delay_ms(120); |
|
- | 133 | } |
|
- | 134 | #endif |
|
107 | 135 | ||
Line 108... | Line 136... | ||
108 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
136 | #if !(ALLCHARSDEBUG|(WRITECHARS != -1)) |
109 | 137 | ||
110 | /** |
138 | /** |
Line 133... | Line 161... | ||
133 | uint16_t address = y * 30 + x; |
161 | uint16_t address = y * 30 + x; |
134 | write_char_att(address, attribute); |
162 | write_char_att(address, attribute); |
135 | } |
163 | } |
Line 136... | Line 164... | ||
136 | 164 | ||
137 | /** |
- | |
138 | * let the MAX7456 learn a new character at <number> |
- | |
139 | * with <data>. |
- | |
140 | */ |
- | |
141 | void learn_char(uint8_t number, unsigned char* data) { |
- | |
142 | // select character to write (CMAH) |
- | |
143 | spi_send_byte(0x09, number); |
- | |
144 | - | ||
145 | for (uint8_t i = 0; i < 54; i++) { |
- | |
146 | // select 4pixel byte of char (CMAL) |
- | |
147 | spi_send_byte(0x0A, i); |
- | |
148 | - | ||
149 | // write 4pixel byte of char (CMDI) |
- | |
150 | spi_send_byte(0x0B, data[i]); |
- | |
151 | } |
- | |
152 | - | ||
153 | // write to the NVM array from the shadow RAM (CMM) |
- | |
154 | spi_send_byte(0x08, 0b10100000); |
- | |
155 | - | ||
156 | // according to maxim writing to nvram takes about 12ms, lets wait longer |
- | |
157 | _delay_ms(120); |
- | |
158 | } |
- | |
159 | - | ||
160 | /** |
165 | /** |
161 | * write an ascii <character> to <address> of MAX7456 display memory |
166 | * write an ascii <character> to <address> of MAX7456 display memory |
162 | */ |
167 | */ |
163 | void write_ascii_char(uint16_t address, char c) { |
168 | void write_ascii_char(uint16_t address, char c) { |
164 | if (c == 32) c = 0; // remap space |
169 | if (c == 32) c = 0; // remap space |
Line 167... | Line 172... | ||
167 | else if (c >= 65 && c <= 90) c -= 54; // remap big letters |
172 | else if (c >= 65 && c <= 90) c -= 54; // remap big letters |
168 | else if (c >= 97 && c <= 122) c -= 60; // remap small letters |
173 | else if (c >= 97 && c <= 122) c -= 60; // remap small letters |
169 | else if (c == '(') c = 63; // remap |
174 | else if (c == '(') c = 63; // remap |
170 | else if (c == ')') c = 64; // remap |
175 | else if (c == ')') c = 64; // remap |
171 | else if (c == '.') c = 65; // remap |
176 | else if (c == '.') c = 65; // remap |
172 | else if (c == '?') c = 66; // remap |
177 | else if (c == '-') c = 73; // remap minus |
173 | else if (c == ';') c = 67; // remap |
178 | else if (c == ';') c = 67; // remap |
174 | else if (c == ':') c = 68; // remap |
179 | else if (c == ':') c = 68; // remap |
175 | else if (c == ',') c = 69; // remap |
180 | else if (c == ',') c = 69; // remap |
176 | else if (c == '\'') c = 70; // remap |
181 | // else if (c == '?') c = 66; // remap |
177 | else if (c == '/') c = 71; // remap |
182 | // else if (c == '\'') c = 70; // remap |
178 | else if (c == '"') c = 72; // remap |
183 | // else if (c == '/') c = 71; // remap |
179 | else if (c == '-') c = 73; // remap minus |
184 | // else if (c == '"') c = 72; // remap |
180 | else if (c == '<') c = 74; // remap |
185 | // else if (c == '<') c = 74; // remap |
181 | else if (c == '>') c = 75; // remap |
186 | // else if (c == '>') c = 75; // remap |
182 | else if (c == '@') c = 76; // remap |
187 | // else if (c == '@') c = 76; // remap |
183 | write_char(address, c); |
188 | write_char(address, c); |
184 | } |
189 | } |
Line 185... | Line 190... | ||
185 | 190 | ||
186 | /** |
191 | /** |
Line 213... | Line 218... | ||
213 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
218 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
214 | * <length> represents the length to rightbound the number |
219 | * <length> represents the length to rightbound the number |
215 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
220 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
216 | */ |
221 | */ |
217 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
222 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
218 | char s[7]; |
- | |
219 | itoa(number, s, 10 ); |
223 | itoa(number, conv_array, 10 ); |
220 | for (uint8_t i = 0; i < length - strlen(s); i++) { |
224 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
221 | if (pad) write_char((x++)+(y * 30), 10); |
225 | if (pad) write_char((x++)+(y * 30), 10); |
222 | else write_ascii_char((x++)+(y * 30), 0); |
226 | else write_ascii_char((x++)+(y * 30), 0); |
223 | } |
227 | } |
224 | write_ascii_string(x, y, s); |
228 | write_ascii_string(x, y, conv_array); |
225 | } |
229 | } |
Line 226... | Line 230... | ||
226 | 230 | ||
227 | /** |
231 | /** |
228 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
232 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
229 | * <length> represents the length to rightbound the number |
233 | * <length> represents the length to rightbound the number |
230 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
234 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
231 | */ |
235 | */ |
232 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
- | |
233 | char s[7]; |
236 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
234 | itoa(number, s, 10 ); |
237 | itoa(number, conv_array, 10 ); |
235 | for (uint8_t i = 0; i < length - strlen(s); i++) { |
238 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
236 | if (pad) write_char((x++)+(y * 30), 10); |
239 | if (pad) write_char((x++)+(y * 30), 10); |
237 | else write_ascii_char((x++)+(y * 30), 0); |
240 | else write_ascii_char((x++)+(y * 30), 0); |
238 | } |
241 | } |
239 | write_ascii_string(x, y, s); |
242 | write_ascii_string(x, y, conv_array); |
Line 240... | Line 243... | ||
240 | } |
243 | } |
241 | 244 | ||
242 | /** |
245 | /** |
243 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
246 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
244 | * <length> represents the length to rightbound the number |
247 | * <length> represents the length to rightbound the number |
245 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
248 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
246 | */ |
- | |
247 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
249 | */ |
248 | char s[7]; |
250 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
249 | itoa(number, s, 10 ); |
251 | itoa(number, conv_array, 10 ); |
250 | uint8_t len = strlen(s); |
252 | uint8_t len = strlen(conv_array); |
251 | for (uint8_t i = 0; i < length - len; i++) { |
253 | for (uint8_t i = 0; i < length - len; i++) { |
252 | if (pad) write_char((x++)+(y * 30), 10); // zero |
254 | if (pad) write_char((x++)+(y * 30), 10); // zero |
253 | else write_char((x++)+(y * 30), 0); // blank |
255 | else write_char((x++)+(y * 30), 0); // blank |
254 | } |
256 | } |
255 | char rest = s[len - 1]; |
257 | char rest = conv_array[len - 1]; |
256 | s[len - 1] = 0; |
258 | conv_array[len - 1] = 0; |
257 | if (len == 1) { |
259 | if (len == 1) { |
258 | write_char((x-1)+(y * 30), 10); // zero |
260 | write_char((x-1)+(y * 30), 10); // zero |
259 | } else if (len == 2 && s[0] == '-') { |
261 | } else if (len == 2 && conv_array[0] == '-') { |
260 | write_char((x-1)+(y * 30), 0x49); // minus |
262 | write_char((x-1)+(y * 30), 0x49); // minus |
261 | write_char((x)+(y * 30), 10); // zero |
263 | write_char((x)+(y * 30), 10); // zero |
262 | } else { |
264 | } else { |
263 | write_ascii_string(x, y, s); |
265 | write_ascii_string(x, y, conv_array); |
264 | } |
266 | } |
265 | x += len - 1; |
267 | x += len - 1; |
266 | write_char((x++)+(y * 30), 65); // decimal point |
268 | write_char((x++)+(y * 30), 65); // decimal point |
Line 271... | Line 273... | ||
271 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
273 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
272 | * <length> represents the length to rightbound the number |
274 | * <length> represents the length to rightbound the number |
273 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
275 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
274 | */ |
276 | */ |
275 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
277 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
276 | char s[7]; |
- | |
277 | itoa(number, s, 10 ); |
278 | itoa(number, conv_array, 10 ); |
278 | uint8_t len = strlen(s); |
279 | uint8_t len = strlen(conv_array); |
279 | for (uint8_t i = 0; i < length - len; i++) { |
280 | for (uint8_t i = 0; i < length - len; i++) { |
280 | if (pad) write_char((x++)+(y * 30), 10); // zero |
281 | if (pad) write_char((x++)+(y * 30), 10); // zero |
281 | else write_char((x++)+(y * 30), 0); // blank |
282 | else write_char((x++)+(y * 30), 0); // blank |
282 | } |
283 | } |
283 | char rest = s[len - 1]; |
284 | char rest = conv_array[len - 1]; |
284 | s[len - 1] = 0; |
285 | conv_array[len - 1] = 0; |
285 | if (len == 1) { |
286 | if (len == 1) { |
286 | write_char((x-1)+(y * 30), 10); // zero |
287 | write_char((x-1)+(y * 30), 10); // zero |
287 | } else if (len == 2 && s[0] == '-') { |
288 | } else if (len == 2 && conv_array[0] == '-') { |
288 | write_char((x-1)+(y * 30), 0x49); // minus |
289 | write_char((x-1)+(y * 30), 0x49); // minus |
289 | write_char((x)+(y * 30), 10); // zero |
290 | write_char((x)+(y * 30), 10); // zero |
290 | } else { |
291 | } else { |
291 | write_ascii_string(x, y, s); |
292 | write_ascii_string(x, y, conv_array); |
292 | } |
293 | } |
293 | x += len - 1; |
294 | x += len - 1; |
294 | write_char((x++)+(y * 30), 65); // decimal point |
295 | write_char((x++)+(y * 30), 65); // decimal point |
295 | write_ascii_char((x++)+(y * 30), rest); // after dot |
296 | write_ascii_char((x++)+(y * 30), rest); // after dot |
296 | } |
297 | } |