diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b523e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.hex +*.o +*.elf diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..85c916d --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +export CC = avr-gcc + +export MCU = atmega328p +export TARGET_ARCH = -mmcu=$(MCU) + +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os + +TARGET = usb +TERM = /dev/ttyACM0 +CPPFLAGS = -mmcu=$(MCU) +PGMER = -c stk500v1 -b 57600 -P $(TERM) +PGMERISP = -c stk500v1 -b 115200 -P $(TERM) +ARVDUDECONF= -C /usr/local/arduino/arduino-0022/hardware/tools/avrdude.conf +export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF) + +C_SRC = $(wildcard *.c) +OBJS = $(C_SRC:.c=.o) + +all: $(TARGET).hex + +clean: + rm -f *.o *.hex *.elf + +%.o:%.c + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ + +$(TARGET).elf: $(OBJS) + $(CC) $(LDFLAGS) -o $@ $(OBJS) + +$(TARGET).hex: $(TARGET).elf + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex + +upload: $(TARGET).hex + stty -F $(TERM) hupcl # reset + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex + diff --git a/main.c b/main.c new file mode 100755 index 0000000..dcbee71 --- /dev/null +++ b/main.c @@ -0,0 +1,63 @@ +#include +#include + +#define CPU_FREQ 16000000L + +unsigned int joystick_lr; +unsigned int joystick_ud; + +void init_serial(unsigned long int speed) +{ + //UBRR0 = CPU_FREQ/((speed)<<4)-1; + UBRR0 = 8; + UCSR0B = (1<