From 1c08382936f77c0f56238d8373e3821804aa2d4a Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Sat, 21 Sep 2019 15:04:12 +0200 Subject: [PATCH] copy uart from atmega16 project wont compile right now! --- code/inc/uart.h | 16 ++++----- code/makefile | 4 +-- code/src/main.c | 8 ++--- code/src/uart.c | 104 +++++++++++++++++--------------------------------------- 4 files changed, 45 insertions(+), 87 deletions(-) diff --git a/code/inc/uart.h b/code/inc/uart.h index 4c7d451..19129cb 100644 --- a/code/inc/uart.h +++ b/code/inc/uart.h @@ -1,13 +1,13 @@ -#ifndef _UART_H -#define _UART_H +#ifndef _UART_H_ +#define _UART_H_ + +#include #define BAUD 9600 -#define MYUBRR F_CPU/16/BAUD-1 +#define BAUDRATE ((F_CPU)/(BAUD*16UL)-1) -void USART_Init(unsigned int ubrr); -void USART_Transmit(unsigned char data ); -void uart_puts( char* string); -int putchar(int c); -void search_i2c_devices(void); +void uart_init (void); +void read_sync(char buffer[], uint8_t buffersize, uint8_t * bufferindex); #endif + diff --git a/code/makefile b/code/makefile index 425ae78..d867dc6 100644 --- a/code/makefile +++ b/code/makefile @@ -1,6 +1,6 @@ MCU = atmega1284 TARGET = main -AVRDUDE_PROGRAMMER = usbasp-clone +AVRDUDE_PROGRAMMER = atmelice_isp FCPU=16000000L BUILDDIR=build @@ -45,7 +45,7 @@ CC = avr-gcc OBJCOPY = avr-objcopy OBJDUMP = avr-objdump SIZE = avr-size -AVRDUDE = ./avrdude +AVRDUDE = avrdude REMOVE = rm -f diff --git a/code/src/main.c b/code/src/main.c index 7f1ffc0..966f191 100644 --- a/code/src/main.c +++ b/code/src/main.c @@ -17,8 +17,8 @@ */ volatile int counter = 0; -char text[22] = {'F','R','o','h','e',' ',' ','W','e','i','h','n','a','c','h','t','e', 'n', ' ',' ', ' ', ' '}; -//char text[18] = {'1','2','3','4','5','6','7','8','9','t','s','c','a','f','e',' ', ' ', ' '}; +//char text[22] = {'F','R','o','h','e',' ',' ','W','e','i','h','n','a','c','h','t','e', 'n', ' ',' ', ' ', ' '}; +char text[18] = {'1','2','3','4','5','6','7','8','9','t','s','c','a','f','e',' ', ' ', ' '}; int offset = 0; int animationtimer = 0; int stringlength = 22; @@ -34,8 +34,8 @@ int main(void){ setup(); while(1){ - //putchar('c'); - //_delay_ms(50); + putchar('c'); + _delay_ms(50); check_dip_switches(); check_buttons(); diff --git a/code/src/uart.c b/code/src/uart.c index 3958208..f62699e 100644 --- a/code/src/uart.c +++ b/code/src/uart.c @@ -1,87 +1,45 @@ #include #include "uart.h" +static int uart_putchar(char c, FILE *stream); +FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); -void USART_Init(unsigned int ubrr) +void uart_init () { - /*Set baud rate */ - UBRR0H = ubrr>>8; - UBRR0L = ubrr; - /*Enable receiver and transmitter */ - UCSR0B = (1<>8); // shift the register right by 8 bits + UBRRL = BAUDRATE; // set baud rate + UCSRB|= (1<