From d41e70ce3463f6b239da415c5d69773fce55f9e9 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sat, 2 Nov 2024 15:18:22 +0800 Subject: Initial commit. --- .gitignore | 9 +++++++++ Makefile | 41 +++++++++++++++++++++++++++++++++++++++++ main.c | 25 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..596a14b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# C +**/*.o +**/*.elf +**/*.hex +**/*.out + +# Vim +*.swp +*.core diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..27092b1 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +CC = avr-gcc +MCU = atmega328p +TARGET = blink + +SRC = main.c +OBJ = $(SRC:.c=.o) + +CFLAGS = -std=gnu99 +CFLAGS += -Os +CFLAGS+= -Wall +CFLAGS+= -mmcu=$(MCU) +CFLAGS+= -DF_CPU=16000000UL +CFLAGS+= -ffunction-sections -fdata-sections + +LDFLAGS = -mmcu=$(MCU) +LDFLAGS += -Wl,--gc-sections + +HEX_FLAGS = -O ihex +HEX_FLAGS += -j .text -j .data + +AVRDUDE_FLAGS = -p $(MCU) +AVRDUDE_FLAGS += -c arduino +AVRDUDE_FLAGS += -P /dev/cuaU0 +AVRDUDE_FLAGS += -D -U + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +elf: $(OBJ) + $(CC) $(LDFLAGS) $(OBJ) -o $(TARGET).elf + +hex: elf + avr-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex + +upload: hex + avrdude $(AVRDUDE_FLAGS) flash:w:$(TARGET).hex:i + +.PHONY: clean + +clean: + rm *.o *.elf *.hex diff --git a/main.c b/main.c new file mode 100644 index 0000000..aed9465 --- /dev/null +++ b/main.c @@ -0,0 +1,25 @@ +#include +#include + +int main(void) +{ + DDRB |= (1 << DDB5); + + TCCR1A = 0; + TCNT1 = 65535 - (F_CPU / 1024); + TCCR1B = (1 << CS10) | (1 << CS12); + TIMSK1 = (1 << TOIE1); + + sei(); + + for (;;) + ; + + return 0; +} + +ISR(TIMER1_OVF_vect) +{ + PORTB ^= (1 << 5); + TCNT1 = 65535 - (F_CPU / 1024); +} -- cgit v1.2.3