
# Makefile for programming ATMEGA168 family of devices.
You might need to modify the file depending on the specific device:

# ATMEGA168 and ATMEGA168A use:
#   MCU=atmega168
#   avrdude -p m168 ... (3 places)

# ATMEGA168P and ATMEGA168PA use:
#   MCU=atmega168p
#   avrdude -p m168p ... (3 places)


CPPFLAGS=-I. -I../lib
MCU=atmega168p
VPATH=../lib
all: exercise1.hex

exercise1.elf: exercise1.o  

%.o: %.c
	avr-gcc ${CPPFLAGS} -Wall -Os -mmcu=${MCU} -o $@ -c $^

%.elf: %.o
	avr-gcc -Os -mmcu=${MCU} -o $@ $^

%.hex: %.elf
	avr-objcopy -j .text -j .data -O ihex $^ $@

%.lst: %.elf
	avr-objdump -h -S $^ > $@

clean:
	rm -f *.o *.elf *.hex 


program: exercise1.hex
	avrdude -p m168p -P /dev/ttyUSB0 -c avrusb500 -e -U flash:w:$^


# These are the default fuses, which result in using a 1MHz internal osciallator with no CLKOUT signal
fuses:
	avrdude -p m168p -P /dev/ttyUSB0 -c avrusb500 -e -U hfuse:w:0xDF:m
	avrdude -p m168p -P /dev/ttyUSB0 -c avrusb500 -e -U lfuse:w:0x62:m

