33 Commits

Author SHA1 Message Date
9e46b92744 Constants shouldn't be uppercase 2016-10-24 16:08:34 +03:00
500c36b81b Last fixes for lab03.2 2016-10-24 00:01:26 +03:00
9d5fff9fa0 Better final version of lab03.2 2016-10-23 22:58:24 +03:00
f72a7b33e0 Final version of lab03.2 2016-10-23 22:49:49 +03:00
1fad6de2e1 Even lower memory usage 2016-10-23 22:11:20 +03:00
14a6e4ff91 Merge Silvers Makefile changes 2016-10-22 01:36:04 +02:00
281d4d72c5 Format only .c files in source directory with make format 2016-10-22 01:35:04 +02:00
89b7339775 Enable Link Time Optimization and function garbage collection 2016-10-19 22:27:25 +02:00
adc3ad6a4a Merge https://gitlab.com/I237-2016/skeleton 2016-10-19 21:53:05 +02:00
f4c572a2e6 Change formating script 2016-10-19 21:51:12 +02:00
25b1feb71d make format 2016-10-11 00:43:31 +03:00
39720c676e Looks like working lab03.2 code 2016-10-10 22:24:33 +03:00
a836b3a624 Remove executable bit from lcd library 2016-10-10 20:33:24 +03:00
51fc127b48 Merge https://gitlab.com/I237-2016/skeleton 2016-10-10 20:29:47 +03:00
be366ed50e Apparently ignoring letter case is a bug 2016-10-10 20:25:13 +03:00
8b64aca736 Fix 2016-10-02 21:28:15 +03:00
aa4e954f76 Add language to code snippets in readme 2016-10-02 21:27:32 +03:00
275cf9fa28 Add readme 2016-10-02 21:23:35 +03:00
bdd27a6bea Add 0 to 127 ascii print out and month lookup 2016-09-26 19:57:14 +03:00
a882534979 Fix bug in print_for_human 2016-09-26 19:56:46 +03:00
a7a915faf4 Remove assert code and add ascii table print 2016-09-26 17:33:47 +03:00
f1f06f056a Add humaninterface messages header 2016-09-26 17:33:21 +03:00
5b78b7da02 Add print helper functions 2016-09-26 17:33:02 +03:00
713cc80417 Add header guard to uart.h 2016-09-26 16:39:07 +03:00
7d422c5494 Merge gitlab.com:artizirk/skeleton into HEAD 2016-09-26 16:31:33 +03:00
8436ba76b0 Remove unnecessary build.sh script 2016-09-19 18:01:25 +03:00
d827bbe427 Fix uart3_init comment 2016-09-10 01:09:54 +03:00
85dca87ff3 Added assert test to main.c with stderr debug console output 2016-09-10 00:57:01 +03:00
ae55fbac04 Renamed uart functions and added support for stderr via uart3 2016-09-10 00:56:05 +03:00
8c5f723619 Add uart functions from https://github.com/tuupola/avr_demo 2016-09-10 00:23:43 +03:00
90a1b412df Formated the code with astyle 2016-09-10 00:23:14 +03:00
dca26ac547 Merge branch 'master' of https://gitlab.com/I237-2016/skeleton 2016-09-09 23:54:45 +03:00
cc4321ae40 Add a led blinking code and a build script 2016-09-05 19:00:01 +03:00
13 changed files with 265 additions and 5 deletions

View File

@ -43,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
@ -87,7 +92,7 @@ install:
$(AVRDUDE) $(AVRDUDEARGS) -U flash:w:$(TARGET)
format:
$(CODE_FORMATTER) $(SRC)
$(CODE_FORMATTER) $(SRCDIR)/*.c
size:
$(AVRSIZE) $(AVRSIZEARGS) $(ELF)

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

18
src/hmi_msg.h Normal file
View File

@ -0,0 +1,18 @@
#include <avr/pgmspace.h>
#ifndef _HMI_MSG_H_
#define _HMI_MSG_H_
#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_ */

View File

@ -0,0 +1,69 @@
#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)
{
/* Init */
DDRA |= _BV(DDA3);
uart0_init();
uart3_init();
stdout = stdin = &uart0_io;
stderr = &uart3_out;
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(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];
for (unsigned char i = 0; i < sizeof(ascii); i++) {
ascii[i] = i;
}
print_for_human(stdout, ascii, sizeof(ascii));
while (1) {
/* 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);
}
}

33
src/print_helper.c Normal file
View File

@ -0,0 +1,33 @@
#include <stdio.h>
#include <avr/pgmspace.h>
#include "print_helper.h"
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)
{
for (int i = 0; i < len; i++) {
unsigned char c = array[i];
if (c >= ' ' && c <= '~') {
if (!fprintf(stream, "%c", c)) {
return 0;
}
} else {
if (!fprintf(stream, "\"0x%02x\"", c)) {
return 0;
}
}
}
return fprintf(stream, "\n");
}

7
src/print_helper.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _PRINT_HELPER_H_
#define _PRINT_HELPER_H_
int print_ascii_tbl (FILE *stream);
int print_for_human (FILE *stream, const unsigned char *array, const int len);
#endif /* _PRINT_HELPER_H_ */

72
src/uart.c Normal file
View File

@ -0,0 +1,72 @@
#include <avr/io.h>
#include <stdio.h>
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#ifndef BAUD
#define BAUD 9600
#endif
#include <util/setbaud.h>
/* http://www.cs.mun.ca/~rod/Winter2007/4723/notes/serial/serial.html */
void uart0_init(void)
{
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= _BV(U2X0);
#else
UCSR0A &= ~(_BV(U2X0));
#endif
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); /* 8-bit data */
UCSR0B = _BV(RXEN0) | _BV(TXEN0); /* Enable RX and TX */
}
void uart3_init(void)
{
UBRR3H = UBRRH_VALUE;
UBRR3L = UBRRL_VALUE;
#if USE_2X
UCSR3A |= _BV(U2X3);
#else
UCSR3A &= ~(_BV(U2X3));
#endif
UCSR3C = _BV(UCSZ31) | _BV(UCSZ30); /* 8-bit data */
UCSR3B = _BV(TXEN3); /* Enable TX */
}
int uart0_putchar(char c, FILE *stream)
{
(void) stream;
if (c == '\n') {
uart0_putchar('\r', stream);
}
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
return 0;
}
int uart3_putchar(char c, FILE *stream)
{
(void) stream;
if (c == '\n') {
uart3_putchar('\r', stream);
}
loop_until_bit_is_set(UCSR3A, UDRE3);
UDR3 = c;
return 0;
}
int uart0_getchar(FILE *stream)
{
(void) stream;
loop_until_bit_is_set(UCSR0A, RXC0);
return UDR0;
}

17
src/uart.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef _UART_H_
#define _UART_H_
int uart0_putchar(char c, FILE *stream);
int uart0_getchar(FILE *stream);
int uart3_putchar(char c, FILE *stream);
void uart0_init(void);
void uart3_init(void);
/* http://www.ermicro.com/blog/?p=325 */
FILE uart0_io = FDEV_SETUP_STREAM(uart0_putchar, uart0_getchar, _FDEV_SETUP_RW);
FILE uart3_out = FDEV_SETUP_STREAM(uart3_putchar, NULL, _FDEV_SETUP_WRITE);
#endif /* _UART_H_ */

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 \