Subversion Repositories Projects

Rev

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

Rev 783 Rev 800
Line 16... Line 16...
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
 ****************************************************************************/
Line -... Line 20...
-
 
20
 
20
 
21
#include "main.h"
21
#include <avr/io.h>
22
#include <avr/io.h>
22
#include <util/delay.h>
23
#include <util/delay.h>
23
#include <avr/pgmspace.h> 
24
#include <avr/pgmspace.h> 
24
#include <string.h>
25
#include <string.h>
25
#include <stdlib.h>
-
 
26
#include "main.h"
26
#include <stdlib.h>
Line 27... Line 27...
27
#include "max7456_software_spi.h"
27
#include "max7456_software_spi.h"
Line -... Line 28...
-
 
28
 
-
 
29
 
-
 
30
char conv_array[7]; // general array for number -> char conversation
-
 
31
 
-
 
32
int pow(int a, int b) {
-
 
33
    if (b <= 0) return 1;
-
 
34
    int res = 1;
28
 
35
    while (b-- > 0) res *= a;
29
 
36
    return res;
30
char conv_array[7]; // general array for number -> char conversation
37
}
Line 31... Line 38...
31
 
38
 
Line 226... Line 233...
226
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory
233
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory
227
 * <length> represents the length to rightbound the number
234
 * <length> represents the length to rightbound the number
228
 * <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
229
 */
236
 */
230
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
237
void write_ndigit_number_u(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
-
 
238
    if (number >= pow(10, length)) {
-
 
239
        number = pow(10, length) - 1;
-
 
240
    }
231
    itoa(number, conv_array, 10);
241
    itoa(number, conv_array, 10);
232
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
242
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
233
        if (pad) write_char((x++)+(y * 30), 10);
243
        if (pad) write_char((x++)+(y * 30), 10);
234
        else write_ascii_char((x++)+(y * 30), 0);
244
        else write_ascii_char((x++)+(y * 30), 0);
235
    }
245
    }
Line 240... Line 250...
240
 * Write a signed <number> at <x>/<y> to MAX7456 display memory
250
 * Write a signed <number> at <x>/<y> to MAX7456 display memory
241
 * <length> represents the length to rightbound the number
251
 * <length> represents the length to rightbound the number
242
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
252
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
243
 */
253
 */
244
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
254
void write_ndigit_number_s(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
-
 
255
    if (number <= -pow(10, length)) {
-
 
256
        number = -pow(10, length) + 1;
-
 
257
    } else if (number >= pow(10, length)) {
-
 
258
        number = pow(10, length) - 1;
-
 
259
    }
-
 
260
 
245
    itoa(number, conv_array, 10);
261
    itoa(number, conv_array, 10);
-
 
262
    if (strlen(conv_array) < length) {
246
    for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
263
        for (uint8_t i = 0; i < length - strlen(conv_array); i++) {
247
        if (pad) write_char((x++)+(y * 30), 10);
264
            if (pad) write_char((x++)+(y * 30), 10);
248
        else write_ascii_char((x++)+(y * 30), 0);
265
            else write_ascii_char((x++)+(y * 30), 0);
-
 
266
        }
249
    }
267
    }
250
    write_ascii_string(x, y, conv_array);
268
    write_ascii_string(x, y, conv_array);
251
}
269
}
Line 252... Line 270...
252
 
270
 
253
/**
271
/**
254
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value
272
 * Write a unsigned <number> at <x>/<y> to MAX7456 display memory as /10th of value
255
 * <length> represents the length to rightbound the number
273
 * <length> represents the length to rightbound the number
256
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
274
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
257
 */
275
 */
-
 
276
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
-
 
277
    if (number >= pow(10, length)) {
-
 
278
        number = pow(10, length) - 1;
258
void write_ndigit_number_u_10th(uint8_t x, uint8_t y, uint16_t number, int16_t length, uint8_t pad) {
279
    }
259
    itoa(number, conv_array, 10);
280
    itoa(number, conv_array, 10);
260
    uint8_t len = strlen(conv_array);
281
    uint8_t len = strlen(conv_array);
261
    for (uint8_t i = 0; i < length - len; i++) {
282
    for (uint8_t i = 0; i < length - len; i++) {
262
        if (pad) write_char((x++)+(y * 30), 10); //  zero
283
        if (pad) write_char((x++)+(y * 30), 10); //  zero
Line 281... Line 302...
281
 * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value
302
 * Write a signed <number> at <x>/<y> to MAX7456 display memory as /10th of value
282
 * <length> represents the length to rightbound the number
303
 * <length> represents the length to rightbound the number
283
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
304
 * <pad> = 1 will cause blank spaced to be filled up with zeros e.g. 007 instead of   7
284
 */
305
 */
285
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
306
void write_ndigit_number_s_10th(uint8_t x, uint8_t y, int16_t number, int16_t length, uint8_t pad) {
-
 
307
    if (number >= pow(10, length)) {
-
 
308
        number = pow(10, length) - 1;
-
 
309
    }
286
    itoa(number, conv_array, 10);
310
    itoa(number, conv_array, 10);
287
    uint8_t len = strlen(conv_array);
311
    uint8_t len = strlen(conv_array);
288
    for (uint8_t i = 0; i < length - len; i++) {
312
    for (uint8_t i = 0; i < length - len; i++) {
289
        if (pad) write_char((x++)+(y * 30), 10); //  zero
313
        if (pad) write_char((x++)+(y * 30), 10); //  zero
290
        else write_char((x++)+(y * 30), 0); // blank
314
        else write_char((x++)+(y * 30), 0); // blank