18 Commits

10 changed files with 88 additions and 53 deletions

View File

@ -49,7 +49,6 @@ CFLAGS = -Wall \
-mmcu=$(BOARD) \
-DF_CPU=16000000UL \
-DGIT_DESCR=\"$(shell git describe --abbrev=6 --dirty --always --tags --long)\" \
-ffreestanding \
-std=c11
# Linker flags

41
README.md Normal file
View File

@ -0,0 +1,41 @@
# 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 Executable file → Normal file
View File

0
lib/hd44780_111/hd44780.txt Executable file → Normal file
View File

0
lib/hd44780_111/hd44780_settings.h Executable file → Normal file
View File

0
lib/hd44780_111/hd44780_settings_example.h Executable file → Normal file
View File

View File

@ -1,26 +1,18 @@
#include <avr/pgmspace.h>
#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 PROG_VERSION "Version: %S built on: %S %S\n"
#define LIBC_VERSION "avr-libc version: %S\n"
#define STUD_NAME "Arti Zirk"
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";
#define GET_MONTH_MSG "Enter Month name first letter >"
PGM_P const months_table[] PROGMEM =
{
string_1,
string_2,
string_3,
string_4,
string_5,
string_6
};
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_ */

View File

@ -1,8 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "hmi_msg.h"
#include "uart.h"
#include "print_helper.h"
@ -12,53 +12,56 @@
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();
lcd_init();
lcd_clrscr();
stdout = stdin = &uart0_io;
stderr = &uart3_out;
fprintf_P(stderr, PSTR(VER_FW),
lcd_init();
lcd_clrscr();
/* End init */
/* Print version info to stderr */
fprintf_P(stderr, PSTR(PROG_VERSION),
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_P(stdout, PSTR(STUD_NAME "\n"));
fprintf_P(stderr, PSTR(LIBC_VERSION), PSTR(__AVR_LIBC_VERSION_STRING__));
/* End version print */
fprintf_P(stdout, PSTR(STUD_NAME));
fputc('\n', stdout); /* Add a new line to the uart printout */
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;
}
print_for_human(stdout, ascii, sizeof(ascii));
while (1) {
char month_first_leter;
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_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);
/* Month search and print */
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(&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((PGM_P)pgm_read_word(&months[i]));
lcd_putc(' ');
}
}
lcd_puts_P(PSTR(" ")); /* Clear the end of the line */
/* set pin 3 low to turn led off */
PORTA &= ~_BV(PORTA3);
_delay_ms(BLINK_DELAY_MS);

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <avr/pgmspace.h>
#include "print_helper.h"
int print_ascii_tbl (FILE *stream)
@ -16,16 +17,17 @@ int print_ascii_tbl (FILE *stream)
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");
}

View File

@ -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 \