Subversion Repositories Projects

Rev

Rev 403 | Rev 412 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 403 Rev 404
1
/****************************************************************************
1
/****************************************************************************
2
 *   Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje                    *
2
 *   Copyright (C) 2009 by Claas Anders "CaScAdE" Rathje                    *
3
 *   admiralcascade@gmail.com                                               *
3
 *   admiralcascade@gmail.com                                               *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
4
 *   Project-URL: http://www.mylifesucks.de/oss/c-osd/                      *
5
 *                                                                          *
5
 *                                                                          *
6
 *   This program is free software; you can redistribute it and/or modify   *
6
 *   This program is free software; you can redistribute it and/or modify   *
7
 *   it under the terms of the GNU General Public License as published by   *
7
 *   it under the terms of the GNU General Public License as published by   *
8
 *   the Free Software Foundation; either version 2 of the License.         *
8
 *   the Free Software Foundation; either version 2 of the License.         *
9
 *                                                                          *
9
 *                                                                          *
10
 *   This program is distributed in the hope that it will be useful,        *
10
 *   This program is distributed in the hope that it will be useful,        *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
13
 *   GNU General Public License for more details.                           *
13
 *   GNU General Public License for more details.                           *
14
 *                                                                          *
14
 *                                                                          *
15
 *   You should have received a copy of the GNU General Public License      *
15
 *   You should have received a copy of the GNU General Public License      *
16
 *   along with this program; if not, write to the                          *
16
 *   along with this program; if not, write to the                          *
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
 ****************************************************************************/
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 "max7456_software_spi.h"
24
#include "max7456_software_spi.h"
25
 
25
 
26
/* ##########################################################################
26
/* ##########################################################################
27
 * MAX7456 SPI & Display stuff
27
 * MAX7456 SPI & Display stuff
28
 * ##########################################################################*/
28
 * ##########################################################################*/
29
 
29
 
30
/**
30
/**
31
 * Send a byte through SPI
31
 * Send a byte through SPI
32
 */
32
 */
33
void spi_send(uint8_t byte) {
33
void spi_send(uint8_t byte) {
34
    for (int8_t i = 7; i >= 0; i--) {
34
    for (int8_t i = 7; i >= 0; i--) {
35
        if (((byte >> i) & 1)) {
35
        if (((byte >> i) & 1)) {
36
            MAX_SDIN_HIGH
36
            MAX_SDIN_HIGH
37
        } else {
37
        } else {
38
            MAX_SDIN_LOW
38
            MAX_SDIN_LOW
39
        }
39
        }
40
        MAX_SCLK_HIGH
40
        MAX_SCLK_HIGH
41
        MAX_SCLK_LOW
41
        MAX_SCLK_LOW
42
    }
42
    }
43
}
43
}
44
 
44
 
45
/**
45
/**
46
 *  Send <byte> to <address> of MAX7456
46
 *  Send <byte> to <address> of MAX7456
47
 */
47
 */
48
void spi_send_byte(uint8_t address, uint8_t byte) {
48
void spi_send_byte(uint8_t address, uint8_t byte) {
49
    // start sending
49
    // start sending
50
    MAX_CS_LOW
50
    MAX_CS_LOW
51
 
51
 
52
    spi_send(address);
52
    spi_send(address);
53
    spi_send(byte);
53
    spi_send(byte);
54
 
54
 
55
    // end sending
55
    // end sending
56
    MAX_CS_HIGH
56
    MAX_CS_HIGH
57
}
57
}
58
 
58
 
59
/**
59
/**
60
 *  write a <character> to <address> of MAX7456 display memory
60
 *  write a <character> to <address> of MAX7456 display memory
61
 */
61
 */
62
void write_char(uint16_t address, char character) {
62
void write_char(uint16_t address, char character) {
63
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
63
    spi_send_byte(0x05, (address & 0xFF00) >> 8); // DMAH
64
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
64
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
65
    spi_send_byte(0x07, character); // DMDI
65
    spi_send_byte(0x07, character); // DMDI
66
}
66
}
67
 
67
 
68
/**
68
/**
69
 *  write a character <attribute> to <address> of MAX7456 display memory
69
 *  write a character <attribute> to <address> of MAX7456 display memory
70
 */
70
 */
71
void write_char_att(uint16_t address, char attribute) {
71
void write_char_att(uint16_t address, char attribute) {
72
    // the only important part is that the DMAH[1] is set
72
    // the only important part is that the DMAH[1] is set
73
    // so we add 2 which binary is the 2nd lowest byte
73
    // so we add 2 which binary is the 2nd lowest byte
74
    spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
74
    spi_send_byte(0x05, ((address & 0xFF00) >> 8) | 2); // DMAH
75
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
75
    spi_send_byte(0x06, (address & 0x00FF)); // DMAL
76
    spi_send_byte(0x07, attribute); // DMDI
76
    spi_send_byte(0x07, attribute); // DMDI
77
}
77
}
78
 
78
 
79
/**
79
/**
80
 *  write a <character> at <x>/<y> to MAX7456 display memory
80
 *  write a <character> at <x>/<y> to MAX7456 display memory
81
 */
81
 */
82
void write_char_xy(uint8_t x, uint8_t y, char character) {
82
void write_char_xy(uint8_t x, uint8_t y, char character) {
83
    uint16_t address = y * 30 + x;
83
    uint16_t address = y * 30 + x;
84
    write_char(address, character);
84
    write_char(address, character);
85
}
85
}
86
 
86
 
87
/**
87
/**
88
 *  write a  character <attribute> at <x>/<y> to MAX7456 display memory
88
 *  write a  character <attribute> at <x>/<y> to MAX7456 display memory
89
 */
89
 */
90
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
90
void write_char_att_xy(uint8_t x, uint8_t y, char attribute) {
91
    uint16_t address = y * 30 + x;
91
    uint16_t address = y * 30 + x;
92
    write_char_att(address, attribute);
92
    write_char_att(address, attribute);
93
}
93
}
94
 
94
 
95
/**
95
/**
96
 *  clear display by writing blank characters all over it
96
 *  clear display memory
-
 
97
 *  (also sets 8bit mode)
97
 */
98
 */
98
void clear(void) {
99
void clear(void) {
99
    uint16_t memory_address = 0;
100
    /*uint16_t memory_address = 0;
100
    for (unsigned int a = 0; a < 480; a++) {
101
    for (unsigned int a = 0; a < 480; a++) {
101
        write_char(memory_address++, 0);
102
        write_char(memory_address++, 0);
102
    }
103
    }*/
-
 
104
        // clear all display-mem (DMM)
-
 
105
    spi_send_byte(0x04, 0b01000100);
-
 
106
 
-
 
107
    // clearing takes 12uS according to maxim so lets wait longer
-
 
108
    _delay_us(20);
103
}
109
}
104
 
110
 
105
/**
111
/**
106
 *  write an ascii <character> to <address> of MAX7456 display memory
112
 *  write an ascii <character> to <address> of MAX7456 display memory
107
 */
113
 */
108
void write_ascii_char(uint16_t address, char c) {
114
void write_ascii_char(uint16_t address, char c) {
109
    if (c == 32) c = 0; // remap space
115
    if (c == 32) c = 0; // remap space
110
    else if (c > 48 && c <= 57) c -= 48; // remap numbers
116
    else if (c > 48 && c <= 57) c -= 48; // remap numbers
111
    else if (c == '0') c = 10; // remap zero
117
    else if (c == '0') c = 10; // remap zero
112
    else if (c >= 65 && c <= 90) c -= 54; // remap big letters
118
    else if (c >= 65 && c <= 90) c -= 54; // remap big letters
113
    else if (c >= 97 && c <= 122) c -= 60; // remap small letters
119
    else if (c >= 97 && c <= 122) c -= 60; // remap small letters
114
    else if (c == '(') c = 63; // remap
120
    else if (c == '(') c = 63; // remap
115
    else if (c == ')') c = 64; // remap
121
    else if (c == ')') c = 64; // remap
116
    else if (c == '.') c = 65; // remap
122
    else if (c == '.') c = 65; // remap
117
    else if (c == '?') c = 66; // remap
123
    else if (c == '?') c = 66; // remap
118
    else if (c == ';') c = 67; // remap
124
    else if (c == ';') c = 67; // remap
119
    else if (c == ':') c = 68; // remap
125
    else if (c == ':') c = 68; // remap
120
    else if (c == ',') c = 69; // remap
126
    else if (c == ',') c = 69; // remap
121
    else if (c == '\'') c = 70; // remap
127
    else if (c == '\'') c = 70; // remap
122
    else if (c == '/') c = 71; // remap
128
    else if (c == '/') c = 71; // remap
123
    else if (c == '"') c = 72; // remap
129
    else if (c == '"') c = 72; // remap
124
    else if (c == '-') c = 73; // remap minus
130
    else if (c == '-') c = 73; // remap minus
125
    else if (c == '<') c = 74; // remap
131
    else if (c == '<') c = 74; // remap
126
    else if (c == '>') c = 75; // remap
132
    else if (c == '>') c = 75; // remap
127
    else if (c == '@') c = 76; // remap
133
    else if (c == '@') c = 76; // remap
128
    write_char(address, c);
134
    write_char(address, c);
129
}
135
}
130
 
136
 
131
/**
137
/**
132
 *  write an ascii <string> at <x>/<y> to MAX7456 display memory
138
 *  write an ascii <string> at <x>/<y> to MAX7456 display memory
133
 */
139
 */
134
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
140
void write_ascii_string(uint8_t x, uint8_t y, char *string) {
135
    while (*string) {
141
    while (*string) {
136
        write_ascii_char(((x++)+(y * 30)), *string);
142
        write_ascii_char(((x++)+(y * 30)), *string);
137
        string++;
143
        string++;
138
    }
144
    }
139
}
145
}
140
 
146
 
141
/**
147
/**
142
 *  write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory
148
 *  write an ascii <string> from progmen at <x>/<y> to MAX7456 display memory
143
 */
149
 */
144
void write_ascii_string_pgm(uint8_t x, uint8_t y, char *string) {
150
void write_ascii_string_pgm(uint8_t x, uint8_t y, char *string) {
145
        while (pgm_read_byte(string) != 0x00)
151
        while (pgm_read_byte(string) != 0x00)
146
                write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
152
                write_ascii_char(((x++)+(y * 30)), pgm_read_byte(string++));
147
}
153
}
148
 
154
 
149
/**
155
/**
150
 *  write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory
156
 *  write an <string> from progmen at <x>/<y> downwards to MAX7456 display memory
151
 */
157
 */
152
void write_string_pgm_down(uint8_t x, uint8_t y, char *string, uint8_t length) {
158
void write_string_pgm_down(uint8_t x, uint8_t y, char *string, uint8_t length) {
153
        while (length--)
159
        while (length--)
154
                write_char((x+(y++ * 30)), pgm_read_byte(string++));
160
                write_char((x+(y++ * 30)), pgm_read_byte(string++));
155
}
161
}
156
 
162
 
157
/**
163
/**
158
 * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
164
 * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
159
 * <num> represents the largest multiple of 10 that will still be displayable as
165
 * <num> represents the largest multiple of 10 that will still be displayable as
160
 * the first digit, so num = 10 will be 0-99 and so on
166
 * the first digit, so num = 10 will be 0-99 and so on
161
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
167
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
162
 */
168
 */
163
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) {
169
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) {
164
                // if number is largar than 99[..]9 we must decrease it
170
                // if number is largar than 99[..]9 we must decrease it
165
                while (number >= (num * 10)) {
171
                while (number >= (num * 10)) {
166
                        number -= num * 10;
172
                        number -= num * 10;
167
                }
173
                }
168
 
174
 
169
                uint8_t started = 0;
175
                uint8_t started = 0;
170
 
176
 
171
                while (num > 0) {
177
                while (num > 0) {
172
                        uint8_t b = number / num;
178
                        uint8_t b = number / num;
173
                        if (b > 0 || started || num == 1) {
179
                        if (b > 0 || started || num == 1) {
174
                            write_ascii_char((x++)+(y * 30), '0' + b);
180
                            write_ascii_char((x++)+(y * 30), '0' + b);
175
                            started = 1;
181
                            started = 1;
176
                        } else {
182
                        } else {
177
                                if (pad) write_ascii_char((x++)+(y * 30), '0');
183
                                if (pad) write_ascii_char((x++)+(y * 30), '0');
178
                                else write_ascii_char((x++)+(y * 30), 0);
184
                                else write_ascii_char((x++)+(y * 30), 0);
179
                        }
185
                        }
180
                        number -= b * num;
186
                        number -= b * num;
181
 
187
 
182
                        num /= 10;
188
                        num /= 10;
183
                }
189
                }
184
}
190
}
185
 
191
 
186
/**
192
/**
187
 * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
193
 * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
188
 * <num> represents the largest multiple of 10 that will still be displayable as
194
 * <num> represents the largest multiple of 10 that will still be displayable as
189
 * the first digit, so num = 10 will be 0-99 and so on
195
 * the first digit, so num = 10 will be 0-99 and so on
190
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
196
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
191
 */
197
 */
192
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) {
198
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) {
193
    if (((uint16_t) number) > 32767) {
199
    if (((uint16_t) number) > 32767) {
194
        number = number - 65536;
200
        number = number - 65536;
195
                num *= -1;
201
                num *= -1;
196
 
202
 
197
                // if number is smaller than -99[..]9 we must increase it
203
                // if number is smaller than -99[..]9 we must increase it
198
                while (number <= (num * 10)) {
204
                while (number <= (num * 10)) {
199
                        number -= num * 10;
205
                        number -= num * 10;
200
                }
206
                }
201
 
207
 
202
                uint8_t started = 0;
208
                uint8_t started = 0;
203
 
209
 
204
                while (num < 0) {
210
                while (num < 0) {
205
                        uint8_t b = number / num;
211
                        uint8_t b = number / num;
206
                        if (pad) write_ascii_char((x)+(y * 30), '0');
212
                        if (pad) write_ascii_char((x)+(y * 30), '0');
207
                        if (b > 0 || started || num == 1) {
213
                        if (b > 0 || started || num == 1) {
208
                                if (!started) write_char((x - 1)+(y * 30), 0x49);
214
                                if (!started) write_char((x - 1)+(y * 30), 0x49);
209
                            write_ascii_char((x++)+(y * 30), '0' + b);
215
                            write_ascii_char((x++)+(y * 30), '0' + b);
210
                            started = 1;
216
                            started = 1;
211
                        } else {
217
                        } else {
212
                                write_ascii_char((x++)+(y * 30), 0);
218
                                write_ascii_char((x++)+(y * 30), 0);
213
                        }
219
                        }
214
                        number -= b * num;
220
                        number -= b * num;
215
 
221
 
216
                        num /= 10;
222
                        num /= 10;
217
                }
223
                }
218
        } else {
224
        } else {
219
        write_char((x)+(y * 30), 0);
225
        write_char((x)+(y * 30), 0);
220
        write_ndigit_number_u(x, y, number, num, pad);
226
        write_ndigit_number_u(x, y, number, num, pad);
221
    }
227
    }
222
}
228
}
223
 
229
 
224
/**
230
/**
225
 * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
231
 * Write only some digits of a unsigned <number> at <x>/<y> to MAX7456 display memory
226
 * as /10th of the value
232
 * as /10th of the value
227
 * <num> represents the largest multiple of 10 that will still be displayable as
233
 * <num> represents the largest multiple of 10 that will still be displayable as
228
 * the first digit, so num = 10 will be 0-99 and so on
234
 * the first digit, so num = 10 will be 0-99 and so on
229
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
235
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
230
 */
236
 */
231
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) {
237
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t num, uint8_t pad) {
232
                // if number is largar than 99[..]9 we must decrease it
238
                // if number is largar than 99[..]9 we must decrease it
233
                while (number >= (num * 10)) {
239
                while (number >= (num * 10)) {
234
                        number -= num * 10;
240
                        number -= num * 10;
235
                }
241
                }
236
               
242
               
237
 
243
 
238
                uint8_t started = 0;
244
                uint8_t started = 0;
239
                while (num > 0) {
245
                while (num > 0) {
240
                        uint8_t b = number / num;
246
                        uint8_t b = number / num;
241
                        if (b > 0 || started || num == 1) {
247
                        if (b > 0 || started || num == 1) {
242
                                if ((num / 10) == 0) {
248
                                if ((num / 10) == 0) {
243
                                        if (!started) write_ascii_char((x - 1)+(y * 30), '0');
249
                                        if (!started) write_ascii_char((x - 1)+(y * 30), '0');
244
                                        write_char((x++)+(y * 30), 65); // decimal point
250
                                        write_char((x++)+(y * 30), 65); // decimal point
245
                                }
251
                                }
246
                                write_ascii_char((x++)+(y * 30), '0' + b);
252
                                write_ascii_char((x++)+(y * 30), '0' + b);
247
                            started = 1;
253
                            started = 1;
248
                        } else {
254
                        } else {
249
                                if (pad) write_ascii_char((x++)+(y * 30), '0');
255
                                if (pad) write_ascii_char((x++)+(y * 30), '0');
250
                                else write_ascii_char((x++)+(y * 30), ' ');
256
                                else write_ascii_char((x++)+(y * 30), ' ');
251
                        }
257
                        }
252
                        number -= b * num;
258
                        number -= b * num;
253
 
259
 
254
                        num /= 10;
260
                        num /= 10;
255
                }
261
                }
256
}
262
}
257
 
263
 
258
/**
264
/**
259
 * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
265
 * Write only some digits of a signed <number> at <x>/<y> to MAX7456 display memory
260
 * as /10th of the value
266
 * as /10th of the value
261
 * <num> represents the largest multiple of 10 that will still be displayable as
267
 * <num> represents the largest multiple of 10 that will still be displayable as
262
 * the first digit, so num = 10 will be 0-99 and so on
268
 * the first digit, so num = 10 will be 0-99 and so on
263
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
269
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
264
 */
270
 */
265
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) {
271
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t num, uint8_t pad) {
266
    if (((uint16_t) number) > 32767) {
272
    if (((uint16_t) number) > 32767) {
267
        number = number - 65536;
273
        number = number - 65536;
268
                num *= -1;
274
                num *= -1;
269
 
275
 
270
                // if number is smaller than -99[..]9 we must increase it
276
                // if number is smaller than -99[..]9 we must increase it
271
                while (number <= (num * 10)) {
277
                while (number <= (num * 10)) {
272
                        number -= num * 10;
278
                        number -= num * 10;
273
                }
279
                }
274
 
280
 
275
                uint8_t started = 0;
281
                uint8_t started = 0;
276
 
282
 
277
                while (num < 0) {
283
                while (num < 0) {
278
                        uint8_t b = number / num;
284
                        uint8_t b = number / num;
279
                        if (pad) write_ascii_char((x)+(y * 30), '0');
285
                        if (pad) write_ascii_char((x)+(y * 30), '0');
280
                        if (b > 0 || started || num == 1) {
286
                        if (b > 0 || started || num == 1) {
281
                                if ((num / 10) == 0) {
287
                                if ((num / 10) == 0) {
282
                                        if (!started) {
288
                                        if (!started) {
283
                                                write_ascii_char((x - 2)+(y * 30), '-');
289
                                                write_ascii_char((x - 2)+(y * 30), '-');
284
                                                write_ascii_char((x - 1)+(y * 30), '0');
290
                                                write_ascii_char((x - 1)+(y * 30), '0');
285
                                        }
291
                                        }
286
                                        write_char((x++)+(y * 30), 65); // decimal point
292
                                        write_char((x++)+(y * 30), 65); // decimal point
287
                                } else if (!started) {
293
                                } else if (!started) {
288
                                        write_char((x - 1)+(y * 30), 0x49); // minus
294
                                        write_char((x - 1)+(y * 30), 0x49); // minus
289
                                }
295
                                }
290
                            write_ascii_char((x++)+(y * 30), '0' + b);
296
                            write_ascii_char((x++)+(y * 30), '0' + b);
291
                            started = 1;
297
                            started = 1;
292
                        } else {
298
                        } else {
293
                                write_ascii_char((x++)+(y * 30), 0);
299
                                write_ascii_char((x++)+(y * 30), 0);
294
                        }
300
                        }
295
                        number -= b * num;
301
                        number -= b * num;
296
 
302
 
297
                        num /= 10;
303
                        num /= 10;
298
                }
304
                }
299
        } else {
305
        } else {
300
        write_char((x)+(y * 30), 0);
306
        write_char((x)+(y * 30), 0);
301
        write_ndigit_number_u_10th(x, y, number, num, pad);
307
        write_ndigit_number_u_10th(x, y, number, num, pad);
302
    }
308
    }
303
}
309
}
304
 
310
 
305
/**
311
/**
306
 *  write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
312
 *  write <seconds> as human readable time at <x>/<y> to MAX7456 display mem
307
 */
313
 */
308
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
314
void write_time(uint8_t x, uint8_t y, uint16_t seconds) {
309
    uint16_t min = seconds / 60;
315
    uint16_t min = seconds / 60;
310
    seconds -= min * 60;
316
    seconds -= min * 60;
311
    write_ndigit_number_u(x, y, min, 100, 0);
317
    write_ndigit_number_u(x, y, min, 100, 0);
312
    write_char_xy(x + 3, y, 68);
318
    write_char_xy(x + 3, y, 68);
313
    write_ndigit_number_u(x + 4, y, seconds, 10, 1);
319
    write_ndigit_number_u(x + 4, y, seconds, 10, 1);
314
}
320
}
315
 
321
 
316
/**
322
/**
317
 * for testing write all chars to screen
323
 * for testing write all chars to screen
318
 */
324
 */
319
void write_all_chars() {
325
void write_all_chars() {
320
    uint16_t x = 3, y = 2, t = 0;
326
    uint16_t x = 3, y = 2, t = 0;
321
    while (t < 256) {
327
    while (t < 256) {
322
        write_char_xy(x++, y, t++);
328
        write_char_xy(x++, y, t++);
323
        if (x > 25) {
329
        if (x > 25) {
324
            y++;
330
            y++;
325
            x = 3;
331
            x = 3;
326
        }
332
        }
327
    }
333
    }
328
}
334
}
329
 
335
 
330
/**
336
/**
331
 * let the MAX7456 learn a new character at <number>
337
 * let the MAX7456 learn a new character at <number>
332
 * with <data>.
338
 * with <data>.
333
 */
339
 */
334
void learn_char(uint8_t number, unsigned char* data) {
340
void learn_char(uint8_t number, unsigned char* data) {
335
    // select character to write (CMAH)
341
    // select character to write (CMAH)
336
    spi_send_byte(0x09, number);
342
    spi_send_byte(0x09, number);
337
 
343
 
338
    for (uint8_t i = 0; i < 54; i++) {
344
    for (uint8_t i = 0; i < 54; i++) {
339
        // select 4pixel byte of char (CMAL)
345
        // select 4pixel byte of char (CMAL)
340
        spi_send_byte(0x0A, i);
346
        spi_send_byte(0x0A, i);
341
 
347
 
342
        // write 4pixel byte of char (CMDI)
348
        // write 4pixel byte of char (CMDI)
343
        spi_send_byte(0x0B, data[i]);
349
        spi_send_byte(0x0B, data[i]);
344
    }
350
    }
345
 
351
 
346
    // write to the NVM array from the shadow RAM (CMM)
352
    // write to the NVM array from the shadow RAM (CMM)
347
    spi_send_byte(0x08, 0b10100000);
353
    spi_send_byte(0x08, 0b10100000);
348
 
354
 
349
    // according to maxim writing to nvram takes about 12ms, lets wait longer
355
    // according to maxim writing to nvram takes about 12ms, lets wait longer
350
    _delay_ms(120);
356
    _delay_ms(120);
351
}
357
}
352
 
358