From a61348e1c78c870b1fc02af02fa64e024a2d3ef9 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Wed, 2 Nov 2016 15:14:51 +0200 Subject: [PATCH] lab03.2 --- src/hmi_msg.h | 26 ++++++++++++++++++++------ src/main.c | 26 ++++++++++++++++++-------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/hmi_msg.h b/src/hmi_msg.h index 890169a..34d6dde 100644 --- a/src/hmi_msg.h +++ b/src/hmi_msg.h @@ -1,12 +1,26 @@ #ifndef _HMI_MSG_H_ #define _HMI_MSG_H_ +#define VER_FW "Version: %S built on: %S %S\n" +#define VER_LIBC "avr-libc version: %S\n" +#define UI_GET_MONTH_LETTER "Enter Month name first letter >" + #define STUD_NAME "Arti Zirk" -const char *ENG_MONTH[6] = {"January", - "February", - "March", - "April", - "May", - "June",}; +const char string_1[] PROGMEM = "January"; +const char string_2[] PROGMEM = "February"; +const char string_3[] PROGMEM = "March"; +const char string_4[] PROGMEM = "April"; +const char string_5[] PROGMEM = "May"; +const char string_6[] PROGMEM = "June"; + +PGM_P const months_table[] PROGMEM = +{ + string_1, + string_2, + string_3, + string_4, + string_5, + string_6 +}; #endif /* _HMI_MSG_H_ */ diff --git a/src/main.c b/src/main.c index fce8a0e..3d42587 100644 --- a/src/main.c +++ b/src/main.c @@ -2,9 +2,11 @@ #include #include #include +#include #include "hmi_msg.h" #include "uart.h" #include "print_helper.h" +#include "../lib/hd44780_111/hd44780.h" #define BLINK_DELAY_MS 100 @@ -15,14 +17,17 @@ int main (void) /* Init stdio on UART0 and UART3 and print user code info */ uart0_init(); uart3_init(); + lcd_init(); + lcd_clrscr(); stdout = stdin = &uart0_io; stderr = &uart3_out; - fprintf(stderr, "Version: %s built on: %s %s\n", - GIT_DESCR, __DATE__, __TIME__); - fprintf(stderr, "avr-libc version: %s\n", __AVR_LIBC_VERSION_STRING__); + fprintf_P(stderr, PSTR(VER_FW), + 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(stdout, STUD_NAME "\n"); + 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}; @@ -33,15 +38,20 @@ int main (void) while (1) { char month_first_leter; - fprintf(stdout, "Enter Month name first letter >"); + fprintf_P(stdout, PSTR(UI_GET_MONTH_LETTER)); 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(strupr(&month_first_leter), ENG_MONTH[i], 1)) { - fprintf(stdout, "%s\n", ENG_MONTH[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])); + lcd_puts_P((PGM_P)pgm_read_word(&months_table[i])); + 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);