Final version of lab03.2

This commit is contained in:
Arti Zirk 2016-10-23 22:49:49 +03:00
parent 1fad6de2e1
commit f72a7b33e0
3 changed files with 25 additions and 17 deletions

View File

@ -6,14 +6,20 @@
#define LIBC_VERSION "avr-libc version: "__AVR_LIBC_VERSION_STRING__"\n" #define LIBC_VERSION "avr-libc version: "__AVR_LIBC_VERSION_STRING__"\n"
#define STUD_NAME "Arti Zirk" #define STUD_NAME "Arti Zirk"
#define GET_MONTH_MSG "Enter Month name first letter >" #define GET_MONTH_MSG "Enter Month name first letter >"
const char ENG_MONTH[6][9] PROGMEM = {
"January",
"February",
"March",
"April",
"May",
"June",
};
};*/ const char JANUARY[] PROGMEM = "January";
const char FEBRUARY[] PROGMEM = "February";
const char MARCH[] PROGMEM = "March";
const char APRIL[] PROGMEM = "April";
const char MAY[] PROGMEM = "May";
const char JUNE[] PROGMEM = "June";
PGM_P const ENG_MONTH[] PROGMEM = {
JANUARY,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
};
#endif /* _HMI_MSG_H_ */ #endif /* _HMI_MSG_H_ */

View File

@ -33,7 +33,7 @@ int main (void)
/* ASCII table print */ /* ASCII table print */
print_ascii_tbl(stdout); print_ascii_tbl(stdout);
unsigned char ascii[128] = {0}; unsigned char ascii[128];
for (unsigned char i = 0; i < sizeof(ascii); i++) { for (unsigned char i = 0; i < sizeof(ascii); i++) {
ascii[i] = i; ascii[i] = i;
} }
@ -51,10 +51,10 @@ int main (void)
fprintf(stdout, "%c\n", month_first_leter); fprintf(stdout, "%c\n", month_first_leter);
lcd_goto(0x40); /* Got to the beginning of the next line */ lcd_goto(0x40); /* Got to the beginning of the next line */
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
if (!strncmp_P(&month_first_leter, ENG_MONTH[i], 1)) { if (!strncmp_P(&month_first_leter, (PGM_P)pgm_read_word(&ENG_MONTH[i]), 1)) {
fprintf_P(stdout, ENG_MONTH[i]); fprintf_P(stdout, (PGM_P)pgm_read_word(&ENG_MONTH[i]));
fputc('\n', stdout); fputc('\n', stdout);
lcd_puts_P(ENG_MONTH[i]); lcd_puts_P((PGM_P)pgm_read_word(&ENG_MONTH[i]));
lcd_putc(' '); lcd_putc(' ');
} }
} }

View File

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <avr/pgmspace.h>
#include "print_helper.h" #include "print_helper.h"
int print_ascii_tbl (FILE *stream) int print_ascii_tbl (FILE *stream)
@ -16,16 +17,17 @@ int print_ascii_tbl (FILE *stream)
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++) { for (int i = 0; i < len; i++) {
if (array[i] >= ' ' && array[i] <= '~') { unsigned char c = array[i];
if (!fprintf(stream, "%c", array[i])) { if (c >= ' ' && c <= '~') {
if (!fprintf(stream, "%c", c)) {
return 0; return 0;
} }
} else { } else {
if (!fprintf(stream, "\"0x%02x\"", array[i])) { if (!fprintf(stream, "\"0x%02x\"", c)) {
return 0; return 0;
} }
} }
} }
return fprintf(stream, "\n");; return fprintf(stream, "\n");
} }