From 05322a603ab8f0947e719ad079a860baf1f33cda Mon Sep 17 00:00:00 2001 From: Torsten Meissner Date: Wed, 26 Sep 2012 23:32:55 +0200 Subject: [PATCH] new folder 'avr' with test project to test the AVR on USB-AVR-CPLD * makefile with compile, program & clean targets * src/avrtest.c file with test code (@ the moment a simple uart loop) --- avr/makefile | 24 +++++++++++++ avr/src/avrtest.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 avr/makefile create mode 100644 avr/src/avrtest.c diff --git a/avr/makefile b/avr/makefile new file mode 100644 index 0000000..74e8ac9 --- /dev/null +++ b/avr/makefile @@ -0,0 +1,24 @@ +#AVR-GCC Makefile +PROJECT = avrtest +SOURCES = src/avrtest.c +CC = avr-gcc +OBJCOPY = avr-objcopy +MMCU = atmega88 + +DUMMY_BINARY:=$(shell mkdir -p binary) + +CFLAGS = -mmcu=$(MMCU) -Wall -Os -std=gnu99 + +compile : binary/$(PROJECT).out + +binary/$(PROJECT).hex: binary/$(PROJECT).out + $(OBJCOPY) -j .text -O ihex binary/$(PROJECT).out binary/$(PROJECT).hex + +binary/$(PROJECT).out: $(SOURCES) + $(CC) $(CFLAGS) -I./ -o binary/$(PROJECT).out $(SOURCES) + +program: binary/$(PROJECT).hex + avrdude -p m88 -c buspirate -P /dev/cu.PL2303-003012FA -e -U flash:w:binary/$(PROJECT).hex + +clean: + rm -rf binary/ diff --git a/avr/src/avrtest.c b/avr/src/avrtest.c new file mode 100644 index 0000000..157a5d4 --- /dev/null +++ b/avr/src/avrtest.c @@ -0,0 +1,85 @@ +#include +#include +#include + +#ifndef F_CPU + #warning "F_CPU wasn't set in makefile, so we do it now with 8.0 MHz" + #define F_CPU 1000000UL +#endif + + +// setting baud rate +#define BAUD 4800UL + +// uart baud rate checks +#define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) +#define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) +#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD) + +#if ((BAUD_ERROR<990) || (BAUD_ERROR>1010)) + #error baudrate error higher than 1%! +#endif + + +static void uart_init (void); +static void uart_putc (unsigned char c); + +volatile uint8_t got_char; +volatile unsigned char rx_char; + +int main (void) +{ + + // uart rx initialisation + uart_init(); + + // activate global interrupts + sei(); + + while(1) + { + if(got_char) { + UCSR0B &= ~(1<> 8; + UBRR0L = UBRR_VAL & 0xFF; + // tx enable + UCSR0B |= (1<