Looks like working lab03.2 code
This commit is contained in:
parent
a836b3a624
commit
39720c676e
@ -1,12 +1,18 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#ifndef _HMI_MSG_H_
|
||||
#define _HMI_MSG_H_
|
||||
|
||||
#define STUD_NAME "Arti Zirk"
|
||||
const char *ENG_MONTH[6] = {"January",
|
||||
const char PROG_VERSION[] PROGMEM = "Version: %s built on: %s %s\n";
|
||||
const char LIBC_VERSION[] PROGMEM = "avr-libc version: %s\n";
|
||||
const char STUD_NAME[] PROGMEM = "Arti Zirk";
|
||||
const char GET_MONTH_MSG[] PROGMEM = "Enter Month name first letter >";
|
||||
const char ENG_MONTH[6][9] PROGMEM = {
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",};
|
||||
"June",
|
||||
};
|
||||
|
||||
#endif /* _HMI_MSG_H_ */
|
||||
|
51
src/main.c
51
src/main.c
@ -1,28 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <util/delay.h>
|
||||
#include "hmi_msg.h"
|
||||
#include "uart.h"
|
||||
#include "print_helper.h"
|
||||
#include "../lib/hd44780_111/hd44780.h"
|
||||
|
||||
#define BLINK_DELAY_MS 100
|
||||
|
||||
int main (void)
|
||||
{
|
||||
/* set pin 3 of PORTA for output*/
|
||||
/* Init */
|
||||
DDRA |= _BV(DDA3);
|
||||
/* Init stdio on UART0 and UART3 and print user code info */
|
||||
uart0_init();
|
||||
uart3_init();
|
||||
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__);
|
||||
/* End stdio init and info print */
|
||||
lcd_init();
|
||||
lcd_clrscr();
|
||||
/* End init */
|
||||
|
||||
/* Print version info to stderr */
|
||||
fprintf_P(stderr, PROG_VERSION, GIT_DESCR, __DATE__, __TIME__);
|
||||
fprintf_P(stderr, LIBC_VERSION, __AVR_LIBC_VERSION_STRING__);
|
||||
/* End version print */
|
||||
|
||||
fprintf_P(stdout, STUD_NAME);
|
||||
fputc('\n', stdout); /* Add a new line to the uart printout */
|
||||
lcd_puts_P(STUD_NAME);
|
||||
lcd_goto(0x40); /* Got to the beginning of the next line */
|
||||
|
||||
fprintf(stdout, STUD_NAME "\n");
|
||||
/* ASCII table print */
|
||||
print_ascii_tbl(stdout);
|
||||
unsigned char ascii[128] = {0};
|
||||
@ -32,19 +41,27 @@ int main (void)
|
||||
print_for_human(stdout, ascii, sizeof(ascii));
|
||||
|
||||
while (1) {
|
||||
char month_first_leter;
|
||||
fprintf(stdout, "Enter Month name first letter >");
|
||||
fscanf(stdin, "%c", &month_first_leter);
|
||||
fprintf(stdout, "%c\n", month_first_leter);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (!strncmp(&month_first_leter, ENG_MONTH[i], 1)) {
|
||||
fprintf(stdout, "%s\n", ENG_MONTH[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* set pin 3 high to turn led on */
|
||||
PORTA |= _BV(PORTA3);
|
||||
_delay_ms(BLINK_DELAY_MS);
|
||||
|
||||
/* Month search and print */
|
||||
char month_first_leter;
|
||||
fprintf_P(stdout, GET_MONTH_MSG);
|
||||
fscanf(stdin, "%c", &month_first_leter);
|
||||
fprintf(stdout, "%c\n", month_first_leter);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (!strncmp_P(&month_first_leter, ENG_MONTH[i], 1)) {
|
||||
fprintf_P(stdout, ENG_MONTH[i]);
|
||||
fputc('\n', stdout);
|
||||
lcd_puts_P(ENG_MONTH[i]);
|
||||
lcd_putc(' ');
|
||||
}
|
||||
}
|
||||
lcd_puts_P(PSTR(" ")); /* Clear the end of the line */
|
||||
lcd_goto(0x40); /* Got to the beginning of the next line */
|
||||
|
||||
|
||||
/* set pin 3 low to turn led off */
|
||||
PORTA &= ~_BV(PORTA3);
|
||||
_delay_ms(BLINK_DELAY_MS);
|
||||
|
Loading…
Reference in New Issue
Block a user