Subversion Repositories Projects

Rev

Rev 489 | Rev 519 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 489 Rev 514
Line 19... Line 19...
19
 ****************************************************************************/
19
 ****************************************************************************/
Line 20... Line 20...
20
 
20
 
21
#include <avr/io.h>
21
#include <avr/io.h>
22
#include <util/delay.h>
22
#include <util/delay.h>
-
 
23
#include <avr/pgmspace.h> 
23
#include <avr/pgmspace.h> 
24
#include "main.h"
Line 24... Line 25...
24
#include "max7456_software_spi.h"
25
#include "max7456_software_spi.h"
25
 
26
 
26
/* ##########################################################################
27
/* ##########################################################################
Line 54... Line 55...
54
 
55
 
55
    // end sending
56
    // end sending
56
    MAX_CS_HIGH
57
    MAX_CS_HIGH
Line -... Line 58...
-
 
58
}
57
}
59
 
58
 
60
 
59
/**
61
/**
60
 *  write a <character> to <address> of MAX7456 display memory
62
 *  write a <character> to <address> of MAX7456 display memory
61
 */
63
 */
62
void write_char(uint16_t address, char character) {
64
void write_char(uint16_t address, char character) {
63
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
65
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
64
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
66
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
Line -... Line 67...
-
 
67
    spi_send_byte(0x07, character); // DMDI
-
 
68
}
-
 
69
 
-
 
70
 
-
 
71
/**
-
 
72
 *  clear display memory
-
 
73
 *  (also sets 8bit mode)
-
 
74
 */
-
 
75
void clear(void) {
-
 
76
    /*uint16_t memory_address = 0;
-
 
77
    for (unsigned int a = 0; a < 480; a++) {
-
 
78
        write_char(memory_address++, 0);
-
 
79
    }*/
-
 
80
        // clear all display-mem (DMM)
-
 
81
    spi_send_byte(0x04, 0b01000100);
-
 
82
 
-
 
83
    // clearing takes 12uS according to maxim so lets wait longer
-
 
84
    _delay_us(20);
-
 
85
}
-
 
86
 
-
 
87
 
-
 
88
/**
-
 
89
 * for testing write all chars to screen
-
 
90
 */
-
 
91
void write_all_chars() {
-
 
92
    uint16_t x = 3, y = 2, t = 0;
-
 
93
    while (t < 256) {
-
 
94
        write_char(x++ + y*30, t++);
-
 
95
        if (x > 25) {
-
 
96
            y++;
-
 
97
            x = 3;
-
 
98
        }
-
 
99
    }
-
 
100
}
65
    spi_send_byte(0x07, character); // DMDI
101
 
66
}
102
#if !(ALLCHARSDEBUG|(WRITECHARS != -1))
67
 
103
 
68
/**
104
/**
69
 *  write a character <attribute> to <address> of MAX7456 display memory
105
 *  write a character <attribute> to <address> of MAX7456 display memory
Line 91... Line 127...
91
    uint16_t address = y * 30 + x;
127
    uint16_t address = y * 30 + x;
92
    write_char_att(address, attribute);
128
    write_char_att(address, attribute);
93
}
129
}
Line 94... Line 130...
94
 
130
 
95
/**
131
/**
96
 *  clear display memory
132
 * let the MAX7456 learn a new character at <number>
97
 *  (also sets 8bit mode)
133
 * with <data>.
98
 */
-
 
99
void clear(void) {
-
 
100
    /*uint16_t memory_address = 0;
134
 */
101
    for (unsigned int a = 0; a < 480; a++) {
135
void learn_char(uint8_t number, unsigned char* data) {
102
        write_char(memory_address++, 0);
-
 
103
    }*/
-
 
104
        // clear all display-mem (DMM)
136
    // select character to write (CMAH)
Line -... Line 137...
-
 
137
    spi_send_byte(0x09, number);
-
 
138
 
-
 
139
    for (uint8_t i = 0; i < 54; i++) {
-
 
140
        // select 4pixel byte of char (CMAL)
-
 
141
        spi_send_byte(0x0A, i);
-
 
142
 
-
 
143
        // write 4pixel byte of char (CMDI)
-
 
144
        spi_send_byte(0x0B, data[i]);
-
 
145
    }
-
 
146
 
-
 
147
    // write to the NVM array from the shadow RAM (CMM)
105
    spi_send_byte(0x04, 0b01000100);
148
    spi_send_byte(0x08, 0b10100000);
106
 
149
 
107
    // clearing takes 12uS according to maxim so lets wait longer
150
    // according to maxim writing to nvram takes about 12ms, lets wait longer
Line 108... Line 151...
108
    _delay_us(20);
151
    _delay_ms(120);
109
}
152
}
110
 
153
 
Line 318... Line 361...
318
    write_char_xy(x + 3, y, 68);
361
    write_char_xy(x + 3, y, 68);
319
    write_ndigit_number_u(x + 4, y, seconds, 10, 1);
362
    write_ndigit_number_u(x + 4, y, seconds, 10, 1);
320
}
363
}
Line 321... Line 364...
321
 
364
 
322
/**
-
 
323
 * for testing write all chars to screen
-
 
324
 */
-
 
325
void write_all_chars() {
-
 
326
    uint16_t x = 3, y = 2, t = 0;
-
 
327
    while (t < 256) {
-
 
328
        write_char_xy(x++, y, t++);
-
 
329
        if (x > 25) {
-
 
330
            y++;
-
 
331
            x = 3;
-
 
332
        }
-
 
333
    }
-
 
334
}
-
 
335
 
-
 
336
/**
-
 
337
 * let the MAX7456 learn a new character at <number>
-
 
338
 * with <data>.
-
 
339
 */
-
 
340
void learn_char(uint8_t number, unsigned char* data) {
-
 
341
    // select character to write (CMAH)
-
 
342
    spi_send_byte(0x09, number);
-
 
343
 
-
 
344
    for (uint8_t i = 0; i < 54; i++) {
-
 
345
        // select 4pixel byte of char (CMAL)
-
 
346
        spi_send_byte(0x0A, i);
-
 
347
 
-
 
348
        // write 4pixel byte of char (CMDI)
-
 
349
        spi_send_byte(0x0B, data[i]);
-
 
350
    }
-
 
351
 
-
 
352
    // write to the NVM array from the shadow RAM (CMM)
-
 
353
    spi_send_byte(0x08, 0b10100000);
-
 
354
 
-
 
355
    // according to maxim writing to nvram takes about 12ms, lets wait longer
-
 
356
    _delay_ms(120);
-
 
357
}
-
 
358
 
-
 
359
/**
365
/**
360
 * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
366
 * wirte a <position> at <x>/<y> assuming it is a gps position for long-/latitude
361
 */
367
 */
362
void write_gps_pos(uint8_t x, uint8_t y, int32_t position) {
368
void write_gps_pos(uint8_t x, uint8_t y, int32_t position) {
363
        if (position < 0) {
369
        if (position < 0) {
Line 373... Line 379...
373
        write_ndigit_number_u(x + 4, y, (uint16_t) (position / (int32_t) 1000), 1000, 1);
379
        write_ndigit_number_u(x + 4, y, (uint16_t) (position / (int32_t) 1000), 1000, 1);
374
        position = position - ((uint16_t) (position / (int32_t) 1000) * (int32_t) 1000);
380
        position = position - ((uint16_t) (position / (int32_t) 1000) * (int32_t) 1000);
375
        write_ndigit_number_u(x + 8, y, (uint16_t) position, 100, 1);
381
        write_ndigit_number_u(x + 8, y, (uint16_t) position, 100, 1);
376
        write_char_xy(x + 11, y, 0xD0); // degree symbol
382
        write_char_xy(x + 11, y, 0xD0); // degree symbol
377
}
383
}
-
 
384
 
-
 
385
#endif