Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
9e46b92744 | |||
500c36b81b | |||
9d5fff9fa0 | |||
f72a7b33e0 | |||
1fad6de2e1 | |||
14a6e4ff91 | |||
281d4d72c5 | |||
89b7339775 | |||
adc3ad6a4a | |||
f4c572a2e6 | |||
de62693b6d | |||
25b1feb71d |
18
Makefile
18
Makefile
@ -8,6 +8,7 @@ CC = avr-gcc
|
||||
OBJCOPY = avr-objcopy
|
||||
AVRDUDE = avrdude
|
||||
CODE_FORMATTER = tooling/format-code.sh
|
||||
AVRSIZE = avr-size
|
||||
|
||||
BOARD = atmega2560
|
||||
|
||||
@ -42,13 +43,18 @@ CFLAGS = -Wall \
|
||||
-Werror \
|
||||
-Wfatal-errors \
|
||||
-Os \
|
||||
-flto \
|
||||
-fdata-sections \
|
||||
-ffunction-sections \
|
||||
-mmcu=$(BOARD) \
|
||||
-DF_CPU=16000000UL \
|
||||
-DGIT_DESCR=\"$(shell git describe --abbrev=6 --dirty --always --tags --long)\" \
|
||||
-std=c11
|
||||
|
||||
# Linker flags
|
||||
LDFLAGS = -mmcu=$(BOARD)
|
||||
LDFLAGS = -mmcu=$(BOARD) \
|
||||
-flto \
|
||||
-Wl,-gc-sections
|
||||
|
||||
OBJCOPYARGS = -O ihex \
|
||||
-R .eeprom
|
||||
@ -62,6 +68,9 @@ AVRDUDEARGS = -p $(BOARD) \
|
||||
-V \
|
||||
-D
|
||||
|
||||
AVRSIZEARGS = -C \
|
||||
--mcu=$(BOARD)
|
||||
|
||||
all: $(ELF) $(TARGET)
|
||||
|
||||
%.o : %.c
|
||||
@ -83,6 +92,9 @@ install:
|
||||
$(AVRDUDE) $(AVRDUDEARGS) -U flash:w:$(TARGET)
|
||||
|
||||
format:
|
||||
$(CODE_FORMATTER) $(SRC)
|
||||
$(CODE_FORMATTER) $(SRCDIR)/*.c
|
||||
|
||||
.PHONY: clean install format
|
||||
size:
|
||||
$(AVRSIZE) $(AVRSIZEARGS) $(ELF)
|
||||
|
||||
.PHONY: clean install format size
|
||||
|
@ -2,17 +2,17 @@
|
||||
#ifndef _HMI_MSG_H_
|
||||
#define _HMI_MSG_H_
|
||||
|
||||
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",
|
||||
};
|
||||
#define PROG_VERSION "Version: %S built on: %S %S\n"
|
||||
#define LIBC_VERSION "avr-libc version: %S\n"
|
||||
#define STUD_NAME "Arti Zirk"
|
||||
#define GET_MONTH_MSG "Enter Month name first letter >"
|
||||
|
||||
const char m1[] PROGMEM = "January";
|
||||
const char m2[] PROGMEM = "February";
|
||||
const char m3[] PROGMEM = "March";
|
||||
const char m4[] PROGMEM = "April";
|
||||
const char m5[] PROGMEM = "May";
|
||||
const char m6[] PROGMEM = "June";
|
||||
|
||||
PGM_P const months[] PROGMEM = {m1,m2,m3,m4,m5,m6};
|
||||
#endif /* _HMI_MSG_H_ */
|
||||
|
30
src/main.c
30
src/main.c
@ -23,18 +23,18 @@ int main (void)
|
||||
/* 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__);
|
||||
fprintf_P(stderr, PSTR(PROG_VERSION),
|
||||
PSTR(GIT_DESCR), PSTR(__DATE__), PSTR(__TIME__));
|
||||
fprintf_P(stderr, PSTR(LIBC_VERSION), PSTR(__AVR_LIBC_VERSION_STRING__));
|
||||
/* End version print */
|
||||
|
||||
fprintf_P(stdout, STUD_NAME);
|
||||
fprintf_P(stdout, PSTR(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 */
|
||||
lcd_puts_P(PSTR(STUD_NAME));
|
||||
|
||||
/* ASCII table print */
|
||||
print_ascii_tbl(stdout);
|
||||
unsigned char ascii[128] = {0};
|
||||
unsigned char ascii[128];
|
||||
for (unsigned char i = 0; i < sizeof(ascii); i++) {
|
||||
ascii[i] = i;
|
||||
}
|
||||
@ -46,21 +46,21 @@ int main (void)
|
||||
_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);
|
||||
char letter;
|
||||
fprintf_P(stdout, PSTR(GET_MONTH_MSG));
|
||||
fscanf(stdin, "%c", &letter);
|
||||
fprintf(stdout, "%c\n", letter);
|
||||
lcd_goto(0x40); /* Got to the beginning of the next line */
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (!strncmp_P(&month_first_leter, ENG_MONTH[i], 1)) {
|
||||
fprintf_P(stdout, ENG_MONTH[i]);
|
||||
if (!strncmp_P(&letter, (PGM_P)pgm_read_word(&months[i]), 1)) {
|
||||
fprintf_P(stdout, (PGM_P)pgm_read_word(&months[i]));
|
||||
fputc('\n', stdout);
|
||||
lcd_puts_P(ENG_MONTH[i]);
|
||||
lcd_puts_P((PGM_P)pgm_read_word(&months[i]));
|
||||
lcd_putc(' ');
|
||||
}
|
||||
}
|
||||
lcd_puts_P(PSTR(" ")); /* Clear the end of the line */
|
||||
lcd_goto(0x40); /* Got to the beginning of the next line */
|
||||
|
||||
lcd_puts_P(PSTR(" ")); /* Clear the end of the line */
|
||||
|
||||
/* set pin 3 low to turn led off */
|
||||
PORTA &= ~_BV(PORTA3);
|
||||
|
@ -1,27 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <avr/pgmspace.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)) {
|
||||
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])) {
|
||||
unsigned char c = array[i];
|
||||
if (c >= ' ' && c <= '~') {
|
||||
if (!fprintf(stream, "%c", c)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if(!fprintf(stream, "\"0x%02x\"", array[i])) {
|
||||
if (!fprintf(stream, "\"0x%02x\"", c)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fprintf(stream, "\n");;
|
||||
|
||||
return fprintf(stream, "\n");
|
||||
}
|
||||
|
@ -18,10 +18,8 @@ for FILE in "$@"
|
||||
do
|
||||
RESULT="$(astyle --style=1tbs \
|
||||
--indent-col1-comments \
|
||||
--break-blocks \
|
||||
--pad-oper \
|
||||
--pad-header \
|
||||
--delete-empty-lines \
|
||||
--add-brackets \
|
||||
--convert-tabs \
|
||||
--max-code-length=80 \
|
||||
|
Reference in New Issue
Block a user