Rev 757 | Rev 783 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 757 | Rev 761 | ||
---|---|---|---|
Line 17... | Line 17... | ||
17 | * Free Software Foundation, Inc., * |
17 | * Free Software Foundation, Inc., * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 | ****************************************************************************/ |
19 | ****************************************************************************/ |
Line 20... | Line 20... | ||
20 | 20 | ||
21 | #include <avr/io.h> |
- | |
22 | 21 | #include <avr/io.h> |
|
23 | #include <util/delay.h> |
22 | #include <util/delay.h> |
24 | #include <avr/pgmspace.h> |
23 | #include <avr/pgmspace.h> |
25 | #include <string.h> |
24 | #include <string.h> |
26 | #include <stdlib.h> |
25 | #include <stdlib.h> |
Line 64... | Line 63... | ||
64 | 63 | ||
65 | // end sending |
64 | // end sending |
66 | MAX_CS_HIGH |
65 | MAX_CS_HIGH |
Line 67... | Line -... | ||
67 | } |
- | |
68 | 66 | } |
|
69 | 67 | ||
70 | /** |
68 | /** |
71 | * write a <character> to <address> of MAX7456 display memory |
69 | * write a <character> to <address> of MAX7456 display memory |
72 | */ |
70 | */ |
73 | void write_char(uint16_t address, char character) { |
71 | void write_char(uint16_t address, char character) { |
74 | spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH |
72 | spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH |
75 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
73 | spi_send_byte(0x06, (address & 0x00FF)); // DMAL |
Line 76... | Line -... | ||
76 | spi_send_byte(0x07, character); // DMDI |
- | |
77 | } |
74 | spi_send_byte(0x07, character); // DMDI |
78 | 75 | } |
|
79 | 76 | ||
80 | /** |
77 | /** |
81 | * clear display memory |
78 | * clear display memory |
82 | * (also sets 8bit mode) |
79 | * (also sets 8bit mode) |
83 | */ |
80 | */ |
84 | void clear(void) { |
81 | void clear(void) { |
85 | /*uint16_t memory_address = 0; |
82 | /*uint16_t memory_address = 0; |
86 | for (unsigned int a = 0; a < 480; a++) { |
83 | for (unsigned int a = 0; a < 480; a++) { |
87 | write_char(memory_address++, 0); |
84 | write_char(memory_address++, 0); |
Line 88... | Line 85... | ||
88 | }*/ |
85 | }*/ |
89 | // clear all display-mem (DMM) |
86 | // clear all display-mem (DMM) |
90 | spi_send_byte(0x04, 0b01000100); |
87 | spi_send_byte(0x04, 0b01000100); |
Line 91... | Line 88... | ||
91 | 88 | ||
- | 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 | } |
92 | |
95 | 93 | ||
96 | 94 | #if (ALLCHARSDEBUG|(WRITECHARS != -1)) |
|
97 | #if (ALLCHARSDEBUG|(WRITECHARS != -1)) |
95 | |
98 | /** |
96 | /** |
99 | * for testing write all chars to screen |
97 | * for testing write all chars to screen |
100 | */ |
98 | */ |
101 | void write_all_chars() { |
99 | void write_all_chars() { |
102 | uint16_t x = 3, y = 2, t = 0; |
100 | uint16_t x = 3, y = 2, t = 0; |
103 | while (t < 256) { |
101 | while (t < 256) { |
Line 176... | Line 174... | ||
176 | else if (c == '.') c = 65; // remap |
174 | else if (c == '.') c = 65; // remap |
177 | else if (c == '-') c = 73; // remap minus |
175 | else if (c == '-') c = 73; // remap minus |
178 | else if (c == ';') c = 67; // remap |
176 | else if (c == ';') c = 67; // remap |
179 | else if (c == ':') c = 68; // remap |
177 | else if (c == ':') c = 68; // remap |
180 | else if (c == ',') c = 69; // remap |
178 | else if (c == ',') c = 69; // remap |
181 | // else if (c == '?') c = 66; // remap |
179 | // else if (c == '?') c = 66; // remap |
182 | // else if (c == '\'') c = 70; // remap |
180 | // else if (c == '\'') c = 70; // remap |
183 | else if (c == '/') c = 71; // remap |
181 | else if (c == '/') c = 71; // remap |
184 | // else if (c == '"') c = 72; // remap |
182 | // else if (c == '"') c = 72; // remap |
185 | // else if (c == '<') c = 74; // remap |
183 | // else if (c == '<') c = 74; // remap |
186 | // else if (c == '>') c = 75; // remap |
184 | // else if (c == '>') c = 75; // remap |
187 | // else if (c == '@') c = 76; // remap |
185 | // else if (c == '@') c = 76; // remap |
188 | write_char(address, c); |
186 | write_char(address, c); |
189 | } |
187 | } |
Line 190... | Line 188... | ||
190 | 188 | ||
191 | /** |
189 | /** |
Line 200... | Line 198... | ||
200 | 198 | ||
201 | /** |
199 | /** |
202 | * write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory |
200 | * write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory |
203 | */ |
201 | */ |
204 | void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) { |
202 | void write_ascii_string_pgm(uint8_t x, uint8_t y, const char *string) { |
205 | while (pgm_read_byte(string) != 0x00) |
203 | while (pgm_read_byte(string) != 0x00) |
206 | write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++)); |
204 | write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++)); |
Line 207... | Line 205... | ||
207 | } |
205 | } |
208 | 206 | ||
209 | /** |
207 | /** |
210 | * write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory |
208 | * write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory |
211 | */ |
209 | */ |
212 | void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) { |
210 | void write_string_pgm_down(uint8_t x, uint8_t y, const char *string, uint8_t length) { |
213 | while (length--) |
211 | while (length--) |
Line 214... | Line 212... | ||
214 | write_char((x+(y++ * 30)), pgm_read_byte(string++)); |
212 | write_char((x + (y++ * 30)), pgm_read_byte(string++)); |
215 | } |
213 | } |
216 | 214 | ||
217 | /** |
215 | /** |
218 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
216 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory |
219 | * <length> represents the length to rightbound the number |
217 | * <length> represents the length to rightbound the number |
220 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
218 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
221 | */ |
219 | */ |
222 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
220 | void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
223 | itoa(number, conv_array, 10 ); |
221 | itoa(number, conv_array, 10); |
224 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
222 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
225 | if (pad) write_char((x++)+(y * 30), 10); |
223 | if (pad) write_char((x++)+(y * 30), 10); |
226 | else write_ascii_char((x++)+(y * 30), 0); |
224 | else write_ascii_char((x++)+(y * 30), 0); |
Line 227... | Line 225... | ||
227 | } |
225 | } |
228 | write_ascii_string(x, y, conv_array); |
226 | write_ascii_string(x, y, conv_array); |
229 | } |
227 | } |
230 | 228 | ||
231 | /** |
229 | /** |
232 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
230 | * Write a signed <number> at <x>/<y> to MAX7456 display memory |
233 | * <length> represents the length to rightbound the number |
231 | * <length> represents the length to rightbound the number |
234 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
232 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
235 | */ |
233 | */ |
236 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
234 | void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
237 | itoa(number, conv_array, 10 ); |
235 | itoa(number, conv_array, 10); |
238 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
236 | for (uint8_t i = 0; i < length - strlen(conv_array); i++) { |
239 | if (pad) write_char((x++)+(y * 30), 10); |
237 | if (pad) write_char((x++)+(y * 30), 10); |
Line 240... | Line 238... | ||
240 | else write_ascii_char((x++)+(y * 30), 0); |
238 | else write_ascii_char((x++)+(y * 30), 0); |
241 | } |
239 | } |
242 | write_ascii_string(x, y, conv_array); |
240 | write_ascii_string(x, y, conv_array); |
243 | } |
241 | } |
244 | 242 | ||
245 | /** |
243 | /** |
246 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
244 | * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value |
247 | * <length> represents the length to rightbound the number |
245 | * <length> represents the length to rightbound the number |
248 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
246 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
249 | */ |
247 | */ |
250 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
248 | void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) { |
251 | itoa(number, conv_array, 10 ); |
249 | itoa(number, conv_array, 10); |
252 | uint8_t len = strlen(conv_array); |
250 | uint8_t len = strlen(conv_array); |
253 | for (uint8_t i = 0; i < length - len; i++) { |
251 | for (uint8_t i = 0; i < length - len; i++) { |
254 | if (pad) write_char((x++)+(y * 30), 10); // zero |
252 | if (pad) write_char((x++)+(y * 30), 10); // zero |
255 | else write_char((x++)+(y * 30), 0); // blank |
253 | else write_char((x++)+(y * 30), 0); // blank |
256 | } |
254 | } |
257 | char rest = conv_array[len - 1]; |
255 | char rest = conv_array[len - 1]; |
258 | conv_array[len - 1] = 0; |
256 | conv_array[len - 1] = 0; |
259 | if (len == 1) { |
257 | if (len == 1) { |
260 | write_char((x-1)+(y * 30), 10); // zero |
258 | write_char((x - 1)+(y * 30), 10); // zero |
261 | } else if (len == 2 && conv_array[0] == '-') { |
259 | } else if (len == 2 && conv_array[0] == '-') { |
262 | write_char((x-1)+(y * 30), 0x49); // minus |
260 | write_char((x - 1)+(y * 30), 0x49); // minus |
263 | write_char((x)+(y * 30), 10); // zero |
261 | write_char((x)+(y * 30), 10); // zero |
264 | } else { |
262 | } else { |
265 | write_ascii_string(x, y, conv_array); |
263 | write_ascii_string(x, y, conv_array); |
Line 266... | Line 264... | ||
266 | } |
264 | } |
267 | x += len - 1; |
265 | x += len - 1; |
268 | write_char((x++)+(y * 30), 65); // decimal point |
266 | write_char((x++)+(y * 30), 65); // decimal point |
269 | write_ascii_char((x++)+(y * 30), rest); // after dot |
267 | write_ascii_char((x++)+(y * 30), rest); // after dot |
270 | } |
268 | } |
271 | 269 | ||
272 | /** |
270 | /** |
273 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
271 | * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value |
274 | * <length> represents the length to rightbound the number |
272 | * <length> represents the length to rightbound the number |
275 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
273 | * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of 7 |
276 | */ |
274 | */ |
277 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
275 | void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) { |
278 | itoa(number, conv_array, 10 ); |
276 | itoa(number, conv_array, 10); |
279 | uint8_t len = strlen(conv_array); |
277 | uint8_t len = strlen(conv_array); |
280 | for (uint8_t i = 0; i < length - len; i++) { |
278 | for (uint8_t i = 0; i < length - len; i++) { |
281 | if (pad) write_char((x++)+(y * 30), 10); // zero |
279 | if (pad) write_char((x++)+(y * 30), 10); // zero |
282 | else write_char((x++)+(y * 30), 0); // blank |
280 | else write_char((x++)+(y * 30), 0); // blank |
283 | } |
281 | } |
284 | char rest = conv_array[len - 1]; |
282 | char rest = conv_array[len - 1]; |
285 | conv_array[len - 1] = 0; |
283 | conv_array[len - 1] = 0; |
286 | if (len == 1) { |
284 | if (len == 1) { |
287 | write_char((x-1)+(y * 30), 10); // zero |
285 | write_char((x - 1)+(y * 30), 10); // zero |
288 | } else if (len == 2 && conv_array[0] == '-') { |
286 | } else if (len == 2 && conv_array[0] == '-') { |
289 | write_char((x-1)+(y * 30), 0x49); // minus |
287 | write_char((x - 1)+(y * 30), 0x49); // minus |
290 | write_char((x)+(y * 30), 10); // zero |
288 | write_char((x)+(y * 30), 10); // zero |
291 | } else { |
289 | } else { |
Line 292... | Line 290... | ||
292 | write_ascii_string(x, y, conv_array); |
290 | write_ascii_string(x, y, conv_array); |
293 | } |
291 | } |
294 | x += len - 1; |
292 | x += len - 1; |
Line 309... | Line 307... | ||
309 | 307 | ||
310 | /** |
308 | /** |
311 | * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude |
309 | * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude |
312 | */ |
310 | */ |
313 | void write_gps_pos(uint8_t x, uint8_t y, int32_t position) { |
311 | void write_gps_pos(uint8_t x, uint8_t y, int32_t position) { |
314 | if (position < 0) { |
312 | if (position < 0) { |
315 | position ^= ~0; |
313 | position ^= ~0; |
316 | position++; |
314 | position++; |
317 | write_char_xy(x++, y, 0x49); // minus |
315 | write_char_xy(x++, y, 0x49); // minus |
318 | } else { |
316 | } else { |
319 | write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later) |
317 | write_char_xy(x++, y, 0); // clear ('+' would be nice, maybe later) |
320 | } |
318 | } |
321 | write_ndigit_number_u(x, y, (uint16_t) (position / (int32_t) 10000000), 3, 1); |
319 | write_ndigit_number_u(x, y, (uint16_t)(position / (int32_t)10000000), 3, 1); |
322 | write_char_xy(x + 3, y, 65); // decimal point |
320 | write_char_xy(x + 3, y, 65); // decimal point |
323 | position = position - ((position / (int32_t) 10000000) * (int32_t) 10000000); |
321 | position = position - ((position / (int32_t)10000000) * (int32_t)10000000); |
324 | write_ndigit_number_u(x + 4, y, (uint16_t) (position / (int32_t) 1000), 4, 1); |
322 | write_ndigit_number_u(x + 4, y, (uint16_t)(position / (int32_t)1000), 4, 1); |
325 | position = position - ((uint16_t) (position / (int32_t) 1000) * (int32_t) 1000); |
323 | position = position - ((uint16_t)(position / (int32_t)1000) * (int32_t)1000); |
326 | write_ndigit_number_u(x + 8, y, (uint16_t) position, 3, 1); |
324 | write_ndigit_number_u(x + 8, y, (uint16_t)position, 3, 1); |
327 | write_char_xy(x + 11, y, 0xD0); // degree symbol |
325 | write_char_xy(x + 11, y, 0xD0); // degree symbol |
Line 328... | Line 326... | ||
328 | } |
326 | } |