Compare commits
9 Commits
oldlab032
...
lab03.2-al
Author | SHA1 | Date | |
---|---|---|---|
22968ef6a4 | |||
09f82d5258 | |||
a61348e1c7 | |||
5d4b4a1e6d | |||
8b7377dff3 | |||
51e4a8bc9b | |||
2ea46d4402 | |||
e6888bd251 | |||
de62693b6d |
19
Makefile
19
Makefile
@ -8,6 +8,7 @@ CC = avr-gcc
|
|||||||
OBJCOPY = avr-objcopy
|
OBJCOPY = avr-objcopy
|
||||||
AVRDUDE = avrdude
|
AVRDUDE = avrdude
|
||||||
CODE_FORMATTER = tooling/format-code.sh
|
CODE_FORMATTER = tooling/format-code.sh
|
||||||
|
AVRSIZE = avr-size
|
||||||
|
|
||||||
BOARD = atmega2560
|
BOARD = atmega2560
|
||||||
|
|
||||||
@ -42,13 +43,19 @@ CFLAGS = -Wall \
|
|||||||
-Werror \
|
-Werror \
|
||||||
-Wfatal-errors \
|
-Wfatal-errors \
|
||||||
-Os \
|
-Os \
|
||||||
|
-flto \
|
||||||
|
-fdata-sections \
|
||||||
|
-ffunction-sections \
|
||||||
-mmcu=$(BOARD) \
|
-mmcu=$(BOARD) \
|
||||||
-DF_CPU=16000000UL \
|
-DF_CPU=16000000UL \
|
||||||
-DGIT_DESCR=\"$(shell git describe --abbrev=6 --dirty --always --tags --long)\" \
|
-DGIT_DESCR=\"$(shell git describe --abbrev=6 --dirty --always --tags --long)\" \
|
||||||
|
-ffreestanding \
|
||||||
-std=c11
|
-std=c11
|
||||||
|
|
||||||
# Linker flags
|
# Linker flags
|
||||||
LDFLAGS = -mmcu=$(BOARD)
|
LDFLAGS = -mmcu=$(BOARD) \
|
||||||
|
-flto \
|
||||||
|
-Wl,-gc-sections
|
||||||
|
|
||||||
OBJCOPYARGS = -O ihex \
|
OBJCOPYARGS = -O ihex \
|
||||||
-R .eeprom
|
-R .eeprom
|
||||||
@ -62,6 +69,9 @@ AVRDUDEARGS = -p $(BOARD) \
|
|||||||
-V \
|
-V \
|
||||||
-D
|
-D
|
||||||
|
|
||||||
|
AVRSIZEARGS = -C \
|
||||||
|
--mcu=$(BOARD)
|
||||||
|
|
||||||
all: $(ELF) $(TARGET)
|
all: $(ELF) $(TARGET)
|
||||||
|
|
||||||
%.o : %.c
|
%.o : %.c
|
||||||
@ -83,6 +93,9 @@ install:
|
|||||||
$(AVRDUDE) $(AVRDUDEARGS) -U flash:w:$(TARGET)
|
$(AVRDUDE) $(AVRDUDEARGS) -U flash:w:$(TARGET)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
$(CODE_FORMATTER) $(SRC)
|
$(CODE_FORMATTER) $(SRCDIR)/*.c
|
||||||
|
|
||||||
.PHONY: clean install format
|
size:
|
||||||
|
$(AVRSIZE) $(AVRSIZEARGS) $(ELF)
|
||||||
|
|
||||||
|
.PHONY: clean install format size
|
||||||
|
41
README.md
41
README.md
@ -1,41 +0,0 @@
|
|||||||
# I237 Hardware Programming
|
|
||||||
|
|
||||||
This here is my repository for hardware programming course at
|
|
||||||
Estonian IT College that is based around a
|
|
||||||
[Arduino Mega 2560](https://www.arduino.cc/en/Main/ArduinoBoardMega2560).
|
|
||||||
|
|
||||||
This code us usualy updated once every two weeks when a new excersice is put up
|
|
||||||
by Silver Kits.
|
|
||||||
|
|
||||||
# How to install
|
|
||||||
|
|
||||||
Currently to test this code you have to clone the repository
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://git.wut.ee/arti/i237.git hardware
|
|
||||||
cd hardware
|
|
||||||
```
|
|
||||||
|
|
||||||
And export a enviroment variable that points to a Arduino Mega board. The
|
|
||||||
real path will depend on the OS and Computer that you are using. For me it is
|
|
||||||
usualy `/dev/ttyACM0`.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
export ARDUINO=/dev/ttyACM0
|
|
||||||
```
|
|
||||||
|
|
||||||
After that you can `make` the project.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
make clean
|
|
||||||
make
|
|
||||||
make install
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also chekcout previous labs using `git checkout <lab name>`. For example
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git checkout lab02
|
|
||||||
```
|
|
||||||
|
|
||||||
Don't forget to `make clean` after each checkout!
|
|
0
lib/hd44780_111/hd44780.h
Normal file → Executable file
0
lib/hd44780_111/hd44780.h
Normal file → Executable file
0
lib/hd44780_111/hd44780.txt
Normal file → Executable file
0
lib/hd44780_111/hd44780.txt
Normal file → Executable file
0
lib/hd44780_111/hd44780_settings.h
Normal file → Executable file
0
lib/hd44780_111/hd44780_settings.h
Normal file → Executable file
0
lib/hd44780_111/hd44780_settings_example.h
Normal file → Executable file
0
lib/hd44780_111/hd44780_settings_example.h
Normal file → Executable file
@ -1,18 +1,26 @@
|
|||||||
#include <avr/pgmspace.h>
|
|
||||||
#ifndef _HMI_MSG_H_
|
#ifndef _HMI_MSG_H_
|
||||||
#define _HMI_MSG_H_
|
#define _HMI_MSG_H_
|
||||||
|
|
||||||
const char PROG_VERSION[] PROGMEM = "Version: %s built on: %s %s\n";
|
#define VER_FW "Version: %S built on: %S %S\n"
|
||||||
const char LIBC_VERSION[] PROGMEM = "avr-libc version: %s\n";
|
#define VER_LIBC "avr-libc version: %S\n"
|
||||||
const char STUD_NAME[] PROGMEM = "Arti Zirk";
|
#define UI_GET_MONTH_LETTER "Enter Month name first letter >"
|
||||||
const char GET_MONTH_MSG[] PROGMEM = "Enter Month name first letter >";
|
|
||||||
const char ENG_MONTH[6][9] PROGMEM = {
|
#define STUD_NAME "Arti Zirk"
|
||||||
"January",
|
const char string_1[] PROGMEM = "January";
|
||||||
"February",
|
const char string_2[] PROGMEM = "February";
|
||||||
"March",
|
const char string_3[] PROGMEM = "March";
|
||||||
"April",
|
const char string_4[] PROGMEM = "April";
|
||||||
"May",
|
const char string_5[] PROGMEM = "May";
|
||||||
"June",
|
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_ */
|
#endif /* _HMI_MSG_H_ */
|
||||||
|
53
src/main.c
53
src/main.c
@ -1,8 +1,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/pgmspace.h>
|
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
#include "hmi_msg.h"
|
#include "hmi_msg.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include "print_helper.h"
|
#include "print_helper.h"
|
||||||
@ -12,56 +12,53 @@
|
|||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
/* Init */
|
/* set pin 3 of PORTA for output*/
|
||||||
DDRA |= _BV(DDA3);
|
DDRA |= _BV(DDA3);
|
||||||
|
/* Init stdio on UART0 and UART3 and print user code info */
|
||||||
uart0_init();
|
uart0_init();
|
||||||
uart3_init();
|
uart3_init();
|
||||||
stdout = stdin = &uart0_io;
|
|
||||||
stderr = &uart3_out;
|
|
||||||
lcd_init();
|
lcd_init();
|
||||||
lcd_clrscr();
|
lcd_clrscr();
|
||||||
/* End init */
|
stdout = stdin = &uart0_io;
|
||||||
|
stderr = &uart3_out;
|
||||||
/* Print version info to stderr */
|
fprintf_P(stderr, PSTR(VER_FW),
|
||||||
fprintf_P(stderr, PROG_VERSION, GIT_DESCR, __DATE__, __TIME__);
|
PSTR(GIT_DESCR), PSTR(__DATE__), PSTR(__TIME__));
|
||||||
fprintf_P(stderr, LIBC_VERSION, __AVR_LIBC_VERSION_STRING__);
|
fprintf_P(stderr, PSTR(VER_LIBC), PSTR(__AVR_LIBC_VERSION_STRING__));
|
||||||
/* End version print */
|
/* End stdio init and info print */
|
||||||
|
fprintf_P(stdout, PSTR(STUD_NAME "\n"));
|
||||||
fprintf_P(stdout, STUD_NAME);
|
lcd_puts_P(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 */
|
|
||||||
|
|
||||||
/* ASCII table print */
|
/* ASCII table print */
|
||||||
print_ascii_tbl(stdout);
|
print_ascii_tbl(stdout);
|
||||||
unsigned char ascii[128] = {0};
|
unsigned char ascii[128] = {0};
|
||||||
|
|
||||||
for (unsigned char i = 0; i < sizeof(ascii); i++) {
|
for (unsigned char i = 0; i < sizeof(ascii); i++) {
|
||||||
ascii[i] = i;
|
ascii[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_for_human(stdout, ascii, sizeof(ascii));
|
print_for_human(stdout, ascii, sizeof(ascii));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* set pin 3 high to turn led on */
|
|
||||||
PORTA |= _BV(PORTA3);
|
|
||||||
_delay_ms(BLINK_DELAY_MS);
|
|
||||||
|
|
||||||
/* Month search and print */
|
|
||||||
char month_first_leter;
|
char month_first_leter;
|
||||||
fprintf_P(stdout, GET_MONTH_MSG);
|
fprintf_P(stdout, PSTR(UI_GET_MONTH_LETTER));
|
||||||
fscanf(stdin, "%c", &month_first_leter);
|
fscanf(stdin, "%c", &month_first_leter);
|
||||||
fprintf(stdout, "%c\n", month_first_leter);
|
fprintf(stdout, "%c\n", month_first_leter);
|
||||||
|
lcd_goto(0x40);
|
||||||
|
|
||||||
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(&months_table[i]), 1)) {
|
||||||
fprintf_P(stdout, ENG_MONTH[i]);
|
fprintf_P(stdout, PSTR("%S\n"), (PGM_P)pgm_read_word(&months_table[i]));
|
||||||
fputc('\n', stdout);
|
lcd_puts_P((PGM_P)pgm_read_word(&months_table[i]));
|
||||||
lcd_puts_P(ENG_MONTH[i]);
|
|
||||||
lcd_putc(' ');
|
lcd_putc(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lcd_puts_P(PSTR(" ")); /* Clear the end of the line */
|
|
||||||
lcd_goto(0x40); /* Got to the beginning of the next line */
|
|
||||||
|
|
||||||
|
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);
|
||||||
/* set pin 3 low to turn led off */
|
/* set pin 3 low to turn led off */
|
||||||
PORTA &= ~_BV(PORTA3);
|
PORTA &= ~_BV(PORTA3);
|
||||||
_delay_ms(BLINK_DELAY_MS);
|
_delay_ms(BLINK_DELAY_MS);
|
||||||
|
@ -1,27 +1,31 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "print_helper.h"
|
#include "print_helper.h"
|
||||||
|
|
||||||
int print_ascii_tbl (FILE *stream) {
|
int print_ascii_tbl (FILE *stream)
|
||||||
|
{
|
||||||
for (char c = ' '; c <= '~'; c++) {
|
for (char c = ' '; c <= '~'; c++) {
|
||||||
if(!fprintf(stream, "%c ", c)) {
|
if (!fprintf(stream, "%c ", c)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fprintf(stream, "\n");
|
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++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (array[i] >= ' ' && array[i] <= '~') {
|
if (array[i] >= ' ' && array[i] <= '~') {
|
||||||
if(!fprintf(stream, "%c", array[i])) {
|
if (!fprintf(stream, "%c", array[i])) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(!fprintf(stream, "\"0x%02x\"", array[i])) {
|
if (!fprintf(stream, "\"0x%02x\"", array[i])) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fprintf(stream, "\n");;
|
return fprintf(stream, "\n");;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user