This commit is contained in:
Arti Zirk 2016-11-02 15:18:43 +02:00
parent 09f82d5258
commit 22968ef6a4
2 changed files with 15 additions and 7 deletions

View File

@ -22,18 +22,19 @@ int main (void)
stdout = stdin = &uart0_io;
stderr = &uart3_out;
fprintf_P(stderr, PSTR(VER_FW),
PSTR(GIT_DESCR), PSTR(__DATE__), PSTR(__TIME__));
PSTR(GIT_DESCR), PSTR(__DATE__), PSTR(__TIME__));
fprintf_P(stderr, PSTR(VER_LIBC), PSTR(__AVR_LIBC_VERSION_STRING__));
/* End stdio init and info print */
fprintf_P(stdout, PSTR(STUD_NAME "\n"));
lcd_puts_P(PSTR(STUD_NAME));
/* ASCII table print */
print_ascii_tbl(stdout);
unsigned char ascii[128] = {0};
for (unsigned char i = 0; i < sizeof(ascii); i++) {
ascii[i] = i;
}
print_for_human(stdout, ascii, sizeof(ascii));
while (1) {
@ -42,6 +43,7 @@ int main (void)
fscanf(stdin, "%c", &month_first_leter);
fprintf(stdout, "%c\n", month_first_leter);
lcd_goto(0x40);
for (int i = 0; i < 6; i++) {
if (!strncmp_P(&month_first_leter, (PGM_P)pgm_read_word(&months_table[i]), 1)) {
fprintf_P(stdout, PSTR("%S\n"), (PGM_P)pgm_read_word(&months_table[i]));
@ -49,9 +51,11 @@ int main (void)
lcd_putc(' ');
}
}
for (int i = 0; i < 16; i++) {
lcd_putc(' ');
}
/* set pin 3 high to turn led on */
PORTA |= _BV(PORTA3);
_delay_ms(BLINK_DELAY_MS);

View File

@ -1,27 +1,31 @@
#include <stdio.h>
#include "print_helper.h"
int print_ascii_tbl (FILE *stream) {
int print_ascii_tbl (FILE *stream)
{
for (char c = ' '; c <= '~'; c++) {
if(!fprintf(stream, "%c ", c)) {
if (!fprintf(stream, "%c ", c)) {
return 0;
}
}
return fprintf(stream, "\n");
}
int print_for_human (FILE *stream, const unsigned char *array, const int len) {
int print_for_human (FILE *stream, const unsigned char *array, const int len)
{
for (int i = 0; i < len; i++) {
if (array[i] >= ' ' && array[i] <= '~') {
if(!fprintf(stream, "%c", array[i])) {
if (!fprintf(stream, "%c", array[i])) {
return 0;
}
} else {
if(!fprintf(stream, "\"0x%02x\"", array[i])) {
if (!fprintf(stream, "\"0x%02x\"", array[i])) {
return 0;
}
}
}
return fprintf(stream, "\n");;
}