diff options
-rw-r--r-- | .gitignore | 7 | ||||
-rw-r--r-- | Makefile | 45 | ||||
-rw-r--r-- | main.c | 31 |
3 files changed, 83 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..975c237 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.o +*.eep +*.elf +*.hex +*.lss +*.map +*.sym diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..aea031d --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +MCU ?= attiny88 +AVRDUDE_PROGRAMMER ?= usbasp + +AVRCC ?= avr-gcc +AVRFLASH ?= avrdude +AVRNM ?= avr-nm +AVROBJCOPY ?= avr-objcopy +AVROBJDUMP ?= avr-objdump + +CFLAGS += -mmcu=attiny88 -DF_CPU=1000000UL +# CFLAGS += -gdwarf-2 +CFLAGS += -I. -std=gnu99 -Os -Wall -Wextra -pedantic +CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +CFLAGS += -fwhole-program -flto -mstrict-X + +#AVRFLAGS += -U lfuse:w:0xe4:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m +AVRFLAGS += -U flash:w:main.hex +#AVRFLAGS += -U eeprom:w:main.eep + +%.hex: %.elf + ${AVROBJCOPY} -O ihex -R .eeprom $< $@ + +%.eep: %.elf + ${AVROBJCOPY} -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O ihex $< $@ + +main.elf: main.c + ${AVRCC} ${CFLAGS} -o $@ ${@:.elf=.c} -Wl,-Map=main.map,--cref + avr-size -d $@ + +program: main.hex #main.eep + ${AVRFLASH} -p ${MCU} -c ${AVRDUDE_PROGRAMMER} ${AVRFLAGS} + +secsize: main.elf + ${AVROBJDUMP} -hw -j.text -j.bss -j.data main.elf + +funsize: main.elf + ${AVRNM} --print-size --size-sort main.elf + +.PHONY: program secsize funsize + +# Listing of phony targets. +.PHONY : all begin finish end sizebefore sizeafter gccversion \ +build elf hex eep lss sym coff extcoff \ +clean clean_list program debug gdb-config @@ -0,0 +1,31 @@ +#include <avr/io.h> +#include <avr/wdt.h> +#include <util/delay.h> +#include <stdlib.h> + +int main (void) +{ + unsigned int i, j, h; + wdt_disable(); + + DDRB = 0xff; + DDRD = 0xff; + + PORTB = 0; + PORTD = 0; + + while (1) { + for (i = 1; i < 256; i *= 2) { + PORTB = i; + for (j = 1; j < 256; j *= 2) { + PORTD = ~j; + for (h = 1; h < 1; h++) { // use "h < 4096" for visible pixels (e.g. finding soldering errors) + asm("nop"); + } + } + PORTB = 0; + } + } + + return 0; +} |