# required packages: avrdude gcc-avr avr-libc # the atmega firmware binary to output TARGET=scale # to compile CC=avr-gcc OBJDUMP=avr-objdump OBJCOPY=avr-objcopy CFLAGS=-g -Wall -Werror -O3 -std=c99 # the target DEVICE=atmega328p F_CPU=16000000UL # the flasher PROGRAMMER=arduino PORT=/dev/ttyUSB0 # to flash (specially for the arduino, with DTR pulse ot reset) FLASHER=avrdude -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b 57600 -D # source files to compile SRC = $(wildcard *.c) # header files. HEADER = $(SRC:.c=.h) # object files. OBJ = $(SRC:.c=.o) # listing files. LST = $(SRC:.c=.lst) all: compile $(TARGET).lst flash reset: stty 57600 raw ignbrk hup < $(PORT) flash: compile reset $(FLASHER) -U flash:w:$(TARGET).hex:i compile: $(TARGET).hex # compile %.o: %.c %.h $(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -c -o $@ $< # link %.elf: $(OBJ) $(CC) $(CFLAGS) -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -Wl,-Map=$(TARGET).map,--cref -o $@ $(OBJ) # extended listing %.lst: %.elf $(OBJDUMP) -h -S $< > $@ # output file %.hex: %.elf $(OBJCOPY) -j .text -j .data -O ihex $< $@ clean: rm -f $(TARGET) $(TARGET).hex $(TARGET).elf $(TARGET).lst $(TARGET).map $(LST) $(OBJ)