This commit is contained in:
Arti Zirk 2016-11-02 15:14:51 +02:00
parent 5d4b4a1e6d
commit a61348e1c7
2 changed files with 38 additions and 14 deletions

View File

@ -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_ */

View File

@ -2,9 +2,11 @@
#include <string.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#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);