diff --git a/AVR-Programming-Library/Makefile b/AVR-Programming-Library/Makefile index 3d9e5445..2f5d1c54 100644 --- a/AVR-Programming-Library/Makefile +++ b/AVR-Programming-Library/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/AVR-Programming-Library/include.mak b/AVR-Programming-Library/include.mak new file mode 100644 index 00000000..19a02f0b --- /dev/null +++ b/AVR-Programming-Library/include.mak @@ -0,0 +1,180 @@ +##########------------------------------------------------------########## +########## Programmer Defaults ########## +########## Set up once, then forget about it ########## +########## (Can override. See bottom of file.) ########## +##########------------------------------------------------------########## + +PROGRAMMER_TYPE = usbtiny +# extra arguments to avrdude: baud rate, chip type, -F flag, etc. +PROGRAMMER_ARGS = + +##########------------------------------------------------------########## +########## Program Locations ########## +########## Won't need to change if they're in your PATH ########## +##########------------------------------------------------------########## + +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +AVRSIZE = avr-size +AVRDUDE = avrdude + +##########------------------------------------------------------########## +########## Makefile Magic! ########## +########## Summary: ########## +########## We want a .hex file ########## +########## Compile source files into .elf ########## +########## Convert .elf file into .hex ########## +########## You shouldn't need to edit below. ########## +##########------------------------------------------------------########## + +## The name of your project (without the .c) +# TARGET = blinkLED +## Or name it automatically after the enclosing directory +TARGET = $(lastword $(subst /, ,$(CURDIR))) + +# Object files: will find all .c/.h files in current directory +# and in LIBDIR. If you have any other (sub-)directories with code, +# you can add them in to SOURCES below in the wildcard statement. +SOURCES=$(wildcard *.c $(LIBDIR)/*.c) +OBJECTS=$(SOURCES:.c=.o) +HEADERS=$(SOURCES:.c=.h) + +## Compilation options, type man avr-gcc if you're curious. +CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) +CFLAGS = -Os -g -std=gnu99 -Wall +## Use short (8-bit) data types +CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +## Splits up object files per function +CFLAGS += -ffunction-sections -fdata-sections +LDFLAGS = -Wl,-Map,$(TARGET).map +## Optional, but often ends up with smaller code +LDFLAGS += -Wl,--gc-sections +## Relax shrinks code even more, but makes disassembly messy +## LDFLAGS += -Wl,--relax +## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf +## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf +TARGET_ARCH = -mmcu=$(MCU) + +## Explicit pattern rules: +## To make .o files from .c files +%.o: %.c $(HEADERS) Makefile + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; + +$(TARGET).elf: $(OBJECTS) + $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%.eeprom: %.elf + $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ + +%.lst: %.elf + $(OBJDUMP) -S $< > $@ + +## These targets don't have files named after them +.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses + +all: $(TARGET).hex + +debug: + @echo + @echo "Source files:" $(SOURCES) + @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) + @echo + +# Optionally create listing file from .elf +# This creates approximate assembly-language equivalent of your code. +# Useful for debugging time-sensitive bits, +# or making sure the compiler does what you want. +disassemble: $(TARGET).lst + +disasm: disassemble + +# Optionally show how big the resulting program is +size: $(TARGET).elf + $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf + +clean: + rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ + $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ + $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ + $(TARGET).eeprom + +squeaky_clean: + rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom + +##########------------------------------------------------------########## +########## Programmer-specific details ########## +########## Flashing code to AVR using avrdude ########## +##########------------------------------------------------------########## + +flash: $(TARGET).hex + $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< + +## An alias +program: flash + +flash_eeprom: $(TARGET).eeprom + $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< + +avrdude_terminal: + $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt + +## If you've got multiple programmers that you use, +## you can define them here so that it's easy to switch. +## To invoke, use something like `make flash_arduinoISP` +flash_usbtiny: PROGRAMMER_TYPE = usbtiny +flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments +flash_usbtiny: flash + +flash_usbasp: PROGRAMMER_TYPE = usbasp +flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments +flash_usbasp: flash + +flash_arduinoISP: PROGRAMMER_TYPE = avrisp +flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 +## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 +flash_arduinoISP: flash + +flash_109: PROGRAMMER_TYPE = avr109 +flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 +flash_109: flash + +##########------------------------------------------------------########## +########## Fuse settings and suitable defaults ########## +##########------------------------------------------------------########## + +## Mega 48, 88, 168, 328 default values +LFUSE ?= 0x62 +HFUSE ?= 0xdf +EFUSE ?= 0x00 + +## Generic +FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m + +fuses: + $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ + $(PROGRAMMER_ARGS) $(FUSE_STRING) +show_fuses: + $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv + +## Called with no extra definitions, sets to defaults +set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m +set_default_fuses: fuses + +## Set the fuse byte for full-speed mode +## Note: can also be set in firmware for modern chips +set_fast_fuse: LFUSE = 0xE2 +set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m +set_fast_fuse: fuses + +## Set the EESAVE fuse byte to preserve EEPROM across flashes +set_eeprom_save_fuse: HFUSE = 0xD7 +set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m +set_eeprom_save_fuse: fuses + +## Clear the EESAVE fuse byte +clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m +clear_eeprom_save_fuse: fuses diff --git a/Chapter02_Programming-AVRs/blinkLED/Makefile b/Chapter02_Programming-AVRs/blinkLED/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter02_Programming-AVRs/blinkLED/Makefile +++ b/Chapter02_Programming-AVRs/blinkLED/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter02_Programming-AVRs/blinkLED_AVR_style/Makefile b/Chapter02_Programming-AVRs/blinkLED_AVR_style/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter02_Programming-AVRs/blinkLED_AVR_style/Makefile +++ b/Chapter02_Programming-AVRs/blinkLED_AVR_style/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter03_Digital-Output/povToy/Makefile b/Chapter03_Digital-Output/povToy/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter03_Digital-Output/povToy/Makefile +++ b/Chapter03_Digital-Output/povToy/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter03_Digital-Output/povToy_1up/Makefile b/Chapter03_Digital-Output/povToy_1up/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter03_Digital-Output/povToy_1up/Makefile +++ b/Chapter03_Digital-Output/povToy_1up/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter03_Digital-Output/povToy_cylonEyes/Makefile b/Chapter03_Digital-Output/povToy_cylonEyes/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter03_Digital-Output/povToy_cylonEyes/Makefile +++ b/Chapter03_Digital-Output/povToy_cylonEyes/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter03_Digital-Output/povToy_invaders/Makefile b/Chapter03_Digital-Output/povToy_invaders/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter03_Digital-Output/povToy_invaders/Makefile +++ b/Chapter03_Digital-Output/povToy_invaders/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/cylonEyes/Makefile b/Chapter04_Bit-Twiddling/cylonEyes/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/cylonEyes/Makefile +++ b/Chapter04_Bit-Twiddling/cylonEyes/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/cylonEyes_16LFSR/Makefile b/Chapter04_Bit-Twiddling/cylonEyes_16LFSR/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/cylonEyes_16LFSR/Makefile +++ b/Chapter04_Bit-Twiddling/cylonEyes_16LFSR/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/cylonEyes_8LFSR/Makefile b/Chapter04_Bit-Twiddling/cylonEyes_8LFSR/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/cylonEyes_8LFSR/Makefile +++ b/Chapter04_Bit-Twiddling/cylonEyes_8LFSR/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/cylonEyes_counting/Makefile b/Chapter04_Bit-Twiddling/cylonEyes_counting/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/cylonEyes_counting/Makefile +++ b/Chapter04_Bit-Twiddling/cylonEyes_counting/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/cylonEyes_halfStepping/Makefile b/Chapter04_Bit-Twiddling/cylonEyes_halfStepping/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/cylonEyes_halfStepping/Makefile +++ b/Chapter04_Bit-Twiddling/cylonEyes_halfStepping/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/cylonEyes_naive/Makefile b/Chapter04_Bit-Twiddling/cylonEyes_naive/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/cylonEyes_naive/Makefile +++ b/Chapter04_Bit-Twiddling/cylonEyes_naive/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/cylonEyes_quasiRandomToggle/Makefile b/Chapter04_Bit-Twiddling/cylonEyes_quasiRandomToggle/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/cylonEyes_quasiRandomToggle/Makefile +++ b/Chapter04_Bit-Twiddling/cylonEyes_quasiRandomToggle/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter04_Bit-Twiddling/showingOffBits/Makefile b/Chapter04_Bit-Twiddling/showingOffBits/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter04_Bit-Twiddling/showingOffBits/Makefile +++ b/Chapter04_Bit-Twiddling/showingOffBits/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter05_Serial-IO/serialLoopback/Makefile b/Chapter05_Serial-IO/serialLoopback/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter05_Serial-IO/serialLoopback/Makefile +++ b/Chapter05_Serial-IO/serialLoopback/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter05_Serial-IO/serialOrgan/Makefile b/Chapter05_Serial-IO/serialOrgan/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter05_Serial-IO/serialOrgan/Makefile +++ b/Chapter05_Serial-IO/serialOrgan/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter06_Digital-Input/avrMusicBox/Makefile b/Chapter06_Digital-Input/avrMusicBox/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter06_Digital-Input/avrMusicBox/Makefile +++ b/Chapter06_Digital-Input/avrMusicBox/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter06_Digital-Input/bossButton/Makefile b/Chapter06_Digital-Input/bossButton/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter06_Digital-Input/bossButton/Makefile +++ b/Chapter06_Digital-Input/bossButton/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter06_Digital-Input/debouncer/Makefile b/Chapter06_Digital-Input/debouncer/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter06_Digital-Input/debouncer/Makefile +++ b/Chapter06_Digital-Input/debouncer/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter06_Digital-Input/simpleButton/Makefile b/Chapter06_Digital-Input/simpleButton/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter06_Digital-Input/simpleButton/Makefile +++ b/Chapter06_Digital-Input/simpleButton/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter06_Digital-Input/toggleButton/Makefile b/Chapter06_Digital-Input/toggleButton/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter06_Digital-Input/toggleButton/Makefile +++ b/Chapter06_Digital-Input/toggleButton/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter06_Digital-Input/toggleButton_debounced/Makefile b/Chapter06_Digital-Input/toggleButton_debounced/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter06_Digital-Input/toggleButton_debounced/Makefile +++ b/Chapter06_Digital-Input/toggleButton_debounced/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter07_Analog-to-Digital-Conversion-I/lightSensor/Makefile b/Chapter07_Analog-to-Digital-Conversion-I/lightSensor/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter07_Analog-to-Digital-Conversion-I/lightSensor/Makefile +++ b/Chapter07_Analog-to-Digital-Conversion-I/lightSensor/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter07_Analog-to-Digital-Conversion-I/nightLight/Makefile b/Chapter07_Analog-to-Digital-Conversion-I/nightLight/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter07_Analog-to-Digital-Conversion-I/nightLight/Makefile +++ b/Chapter07_Analog-to-Digital-Conversion-I/nightLight/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter07_Analog-to-Digital-Conversion-I/slowScope/Makefile b/Chapter07_Analog-to-Digital-Conversion-I/slowScope/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter07_Analog-to-Digital-Conversion-I/slowScope/Makefile +++ b/Chapter07_Analog-to-Digital-Conversion-I/slowScope/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter08_Hardware-Interrupts/capSense/Makefile b/Chapter08_Hardware-Interrupts/capSense/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter08_Hardware-Interrupts/capSense/Makefile +++ b/Chapter08_Hardware-Interrupts/capSense/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter08_Hardware-Interrupts/helloInterrupt/Makefile b/Chapter08_Hardware-Interrupts/helloInterrupt/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter08_Hardware-Interrupts/helloInterrupt/Makefile +++ b/Chapter08_Hardware-Interrupts/helloInterrupt/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter08_Hardware-Interrupts/helloPinChangeInterrupt/Makefile b/Chapter08_Hardware-Interrupts/helloPinChangeInterrupt/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter08_Hardware-Interrupts/helloPinChangeInterrupt/Makefile +++ b/Chapter08_Hardware-Interrupts/helloPinChangeInterrupt/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter09_Introduction-to-Timer-Counter-Hardware/amRadio/Makefile b/Chapter09_Introduction-to-Timer-Counter-Hardware/amRadio/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter09_Introduction-to-Timer-Counter-Hardware/amRadio/Makefile +++ b/Chapter09_Introduction-to-Timer-Counter-Hardware/amRadio/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter09_Introduction-to-Timer-Counter-Hardware/reactionTimer/Makefile b/Chapter09_Introduction-to-Timer-Counter-Hardware/reactionTimer/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter09_Introduction-to-Timer-Counter-Hardware/reactionTimer/Makefile +++ b/Chapter09_Introduction-to-Timer-Counter-Hardware/reactionTimer/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter09_Introduction-to-Timer-Counter-Hardware/timerAudio/Makefile b/Chapter09_Introduction-to-Timer-Counter-Hardware/timerAudio/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter09_Introduction-to-Timer-Counter-Hardware/timerAudio/Makefile +++ b/Chapter09_Introduction-to-Timer-Counter-Hardware/timerAudio/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter10_Pulse-Width-Modulation/bruteForcePWM/Makefile b/Chapter10_Pulse-Width-Modulation/bruteForcePWM/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter10_Pulse-Width-Modulation/bruteForcePWM/Makefile +++ b/Chapter10_Pulse-Width-Modulation/bruteForcePWM/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter10_Pulse-Width-Modulation/pwm/Makefile b/Chapter10_Pulse-Width-Modulation/pwm/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter10_Pulse-Width-Modulation/pwm/Makefile +++ b/Chapter10_Pulse-Width-Modulation/pwm/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter10_Pulse-Width-Modulation/pwmOnAnyPin/Makefile b/Chapter10_Pulse-Width-Modulation/pwmOnAnyPin/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter10_Pulse-Width-Modulation/pwmOnAnyPin/Makefile +++ b/Chapter10_Pulse-Width-Modulation/pwmOnAnyPin/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter10_Pulse-Width-Modulation/pwmTimers/Makefile b/Chapter10_Pulse-Width-Modulation/pwmTimers/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter10_Pulse-Width-Modulation/pwmTimers/Makefile +++ b/Chapter10_Pulse-Width-Modulation/pwmTimers/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter10_Pulse-Width-Modulation/pwm_cross-fading_cylons/Makefile b/Chapter10_Pulse-Width-Modulation/pwm_cross-fading_cylons/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter10_Pulse-Width-Modulation/pwm_cross-fading_cylons/Makefile +++ b/Chapter10_Pulse-Width-Modulation/pwm_cross-fading_cylons/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter11_Driving-Servo-Motors/servoSundial/Makefile b/Chapter11_Driving-Servo-Motors/servoSundial/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter11_Driving-Servo-Motors/servoSundial/Makefile +++ b/Chapter11_Driving-Servo-Motors/servoSundial/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter11_Driving-Servo-Motors/servoWorkout/Makefile b/Chapter11_Driving-Servo-Motors/servoWorkout/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter11_Driving-Servo-Motors/servoWorkout/Makefile +++ b/Chapter11_Driving-Servo-Motors/servoWorkout/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter12_Analog-to-Digital-Conversion-II/footstepDetector/Makefile b/Chapter12_Analog-to-Digital-Conversion-II/footstepDetector/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter12_Analog-to-Digital-Conversion-II/footstepDetector/Makefile +++ b/Chapter12_Analog-to-Digital-Conversion-II/footstepDetector/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter12_Analog-to-Digital-Conversion-II/voltmeter/Makefile b/Chapter12_Analog-to-Digital-Conversion-II/voltmeter/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter12_Analog-to-Digital-Conversion-II/voltmeter/Makefile +++ b/Chapter12_Analog-to-Digital-Conversion-II/voltmeter/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter13_Advanced-PWM-Tricks/adsr/Makefile b/Chapter13_Advanced-PWM-Tricks/adsr/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter13_Advanced-PWM-Tricks/adsr/Makefile +++ b/Chapter13_Advanced-PWM-Tricks/adsr/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter13_Advanced-PWM-Tricks/arpeggiator/Makefile b/Chapter13_Advanced-PWM-Tricks/arpeggiator/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter13_Advanced-PWM-Tricks/arpeggiator/Makefile +++ b/Chapter13_Advanced-PWM-Tricks/arpeggiator/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter13_Advanced-PWM-Tricks/dds/Makefile b/Chapter13_Advanced-PWM-Tricks/dds/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter13_Advanced-PWM-Tricks/dds/Makefile +++ b/Chapter13_Advanced-PWM-Tricks/dds/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter13_Advanced-PWM-Tricks/dds_interrupts/Makefile b/Chapter13_Advanced-PWM-Tricks/dds_interrupts/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter13_Advanced-PWM-Tricks/dds_interrupts/Makefile +++ b/Chapter13_Advanced-PWM-Tricks/dds_interrupts/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter13_Advanced-PWM-Tricks/dds_saw15/Makefile b/Chapter13_Advanced-PWM-Tricks/dds_saw15/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter13_Advanced-PWM-Tricks/dds_saw15/Makefile +++ b/Chapter13_Advanced-PWM-Tricks/dds_saw15/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter13_Advanced-PWM-Tricks/dialTone/Makefile b/Chapter13_Advanced-PWM-Tricks/dialTone/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter13_Advanced-PWM-Tricks/dialTone/Makefile +++ b/Chapter13_Advanced-PWM-Tricks/dialTone/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter13_Advanced-PWM-Tricks/fatSaw/Makefile b/Chapter13_Advanced-PWM-Tricks/fatSaw/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter13_Advanced-PWM-Tricks/fatSaw/Makefile +++ b/Chapter13_Advanced-PWM-Tricks/fatSaw/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter14_Switches/dcMotorWorkout/Makefile b/Chapter14_Switches/dcMotorWorkout/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter14_Switches/dcMotorWorkout/Makefile +++ b/Chapter14_Switches/dcMotorWorkout/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter15_Advanced-Motors/hBridgeWorkout/Makefile b/Chapter15_Advanced-Motors/hBridgeWorkout/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter15_Advanced-Motors/hBridgeWorkout/Makefile +++ b/Chapter15_Advanced-Motors/hBridgeWorkout/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter15_Advanced-Motors/stepperWorkout/Makefile b/Chapter15_Advanced-Motors/stepperWorkout/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter15_Advanced-Motors/stepperWorkout/Makefile +++ b/Chapter15_Advanced-Motors/stepperWorkout/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter16_SPI/spiEEPROMDemo/Makefile b/Chapter16_SPI/spiEEPROMDemo/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter16_SPI/spiEEPROMDemo/Makefile +++ b/Chapter16_SPI/spiEEPROMDemo/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter17_I2C/i2cThermometer/Makefile b/Chapter17_I2C/i2cThermometer/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter17_I2C/i2cThermometer/Makefile +++ b/Chapter17_I2C/i2cThermometer/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter17_I2C/loggingThermometer/Makefile b/Chapter17_I2C/loggingThermometer/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter17_I2C/loggingThermometer/Makefile +++ b/Chapter17_I2C/loggingThermometer/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/progmemDemo1/Makefile b/Chapter18_Using-Flash-Program-Memory/progmemDemo1/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/progmemDemo1/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/progmemDemo1/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/progmemDemo2/Makefile b/Chapter18_Using-Flash-Program-Memory/progmemDemo2/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/progmemDemo2/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/progmemDemo2/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/progmemDemo3/Makefile b/Chapter18_Using-Flash-Program-Memory/progmemDemo3/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/progmemDemo3/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/progmemDemo3/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/progmemDemo4/Makefile b/Chapter18_Using-Flash-Program-Memory/progmemDemo4/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/progmemDemo4/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/progmemDemo4/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/progmemDemo5/Makefile b/Chapter18_Using-Flash-Program-Memory/progmemDemo5/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/progmemDemo5/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/progmemDemo5/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/Makefile b/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/Makefile index 5c588dcc..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 8000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_1bit/Makefile b/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_1bit/Makefile index 609e6e25..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_1bit/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_1bit/Makefile @@ -4,183 +4,14 @@ ########## Check these every time you start a new project ########## ##########------------------------------------------------------########## -MCU = atmega168 -F_CPU = 8000000 -BAUD = 9600 +MCU = atmega168p +F_CPU = 1000000UL +BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. -## This is where your main() routine lives (without .c extension) -TARGET = speech_1_bit_diff -## If you've split your program into multiple .c / .h files, -## include the additional source here (without the .c or .h extension) -LOCAL_SOURCE = +## A directory for common include files and the simple USART library. +## If you move either the current folder or the Library folder, you'll +## need to change this path to match. +LIBDIR = ../../AVR-Programming-Library -EXTRA_SOURCE_DIR = ../../../learningAVR/ -EXTRA_SOURCE_FILES = USART - -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## Defined programs / locations -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -## Compilation options, type man avr-gcc if you're curious. -CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -DBAUD=$(BAUD) -Os -I. -I$(EXTRA_SOURCE_DIR) -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -CFLAGS += -Wall -Wstrict-prototypes -CFLAGS += -g -ggdb -CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--relax -CFLAGS += -std=gnu99 -## CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf - -## Lump target and extra source files together -TARGET = $(strip $(basename $(MAIN))) -SRC = $(TARGET).c -EXTRA_SOURCE = $(addprefix $(EXTRA_SOURCE_DIR), $(EXTRA_SOURCE_FILES)) -SRC += $(EXTRA_SOURCE) -SRC += $(LOCAL_SOURCE) - -## List of all header files -HEADERS = $(SRC:.c=.h) - -## For every .c file, compile an .o object file -OBJ = $(SRC:.c=.o) - -## Generic Makefile targets. (Only .hex file is necessary) -all: $(TARGET).hex - -%.hex: %.elf - $(OBJCOPY) -R .eeprom -O ihex $< $@ - -%.elf: $(SRC) - $(CC) $(CFLAGS) $(SRC) --output $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -debug: - @echo - @echo "Source files:" $(SRC) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -eeprom: $(TARGET).eeprom - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_2bit/Makefile b/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_2bit/Makefile index 09f3b4db..2f5d1c54 100644 --- a/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_2bit/Makefile +++ b/Chapter18_Using-Flash-Program-Memory/talkingVoltmeter/cornell/dpcm_2bit/Makefile @@ -4,183 +4,14 @@ ########## Check these every time you start a new project ########## ##########------------------------------------------------------########## -MCU = atmega168 -F_CPU = 8000000 -BAUD = 9600 +MCU = atmega168p +F_CPU = 1000000UL +BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. -## This is where your main() routine lives (without .c extension) -TARGET = speech_644_GCC -## If you've split your program into multiple .c / .h files, -## include the additional source here (without the .c or .h extension) -LOCAL_SOURCE = +## A directory for common include files and the simple USART library. +## If you move either the current folder or the Library folder, you'll +## need to change this path to match. +LIBDIR = ../../AVR-Programming-Library -EXTRA_SOURCE_DIR = ../../../learningAVR/ -EXTRA_SOURCE_FILES = USART - -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## Defined programs / locations -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -## Compilation options, type man avr-gcc if you're curious. -CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -DBAUD=$(BAUD) -Os -I. -I$(EXTRA_SOURCE_DIR) -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -CFLAGS += -Wall -Wstrict-prototypes -CFLAGS += -g -ggdb -CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--relax -CFLAGS += -std=gnu99 -## CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf - -## Lump target and extra source files together -TARGET = $(strip $(basename $(MAIN))) -SRC = $(TARGET).c -EXTRA_SOURCE = $(addprefix $(EXTRA_SOURCE_DIR), $(EXTRA_SOURCE_FILES)) -SRC += $(EXTRA_SOURCE) -SRC += $(LOCAL_SOURCE) - -## List of all header files -HEADERS = $(SRC:.c=.h) - -## For every .c file, compile an .o object file -OBJ = $(SRC:.c=.o) - -## Generic Makefile targets. (Only .hex file is necessary) -all: $(TARGET).hex - -%.hex: %.elf - $(OBJCOPY) -R .eeprom -O ihex $< $@ - -%.elf: $(SRC) - $(CC) $(CFLAGS) $(SRC) --output $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -debug: - @echo - @echo "Source files:" $(SRC) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -eeprom: $(TARGET).eeprom - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter19_EEPROM/eememDemo/Makefile b/Chapter19_EEPROM/eememDemo/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter19_EEPROM/eememDemo/Makefile +++ b/Chapter19_EEPROM/eememDemo/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter19_EEPROM/favoriteColor/Makefile b/Chapter19_EEPROM/favoriteColor/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter19_EEPROM/favoriteColor/Makefile +++ b/Chapter19_EEPROM/favoriteColor/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter19_EEPROM/quickDemo/Makefile b/Chapter19_EEPROM/quickDemo/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter19_EEPROM/quickDemo/Makefile +++ b/Chapter19_EEPROM/quickDemo/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak diff --git a/Chapter19_EEPROM/vigenereCipher/Makefile b/Chapter19_EEPROM/vigenereCipher/Makefile index 3d9e5445..2f5d1c54 100644 --- a/Chapter19_EEPROM/vigenereCipher/Makefile +++ b/Chapter19_EEPROM/vigenereCipher/Makefile @@ -5,192 +5,13 @@ ##########------------------------------------------------------########## MCU = atmega168p -F_CPU = 1000000UL +F_CPU = 1000000UL BAUD = 9600UL ## Also try BAUD = 19200 or 38400 if you're feeling lucky. ## A directory for common include files and the simple USART library. -## If you move either the current folder or the Library folder, you'll +## If you move either the current folder or the Library folder, you'll ## need to change this path to match. LIBDIR = ../../AVR-Programming-Library -##########------------------------------------------------------########## -########## Programmer Defaults ########## -########## Set up once, then forget about it ########## -########## (Can override. See bottom of file.) ########## -##########------------------------------------------------------########## - -PROGRAMMER_TYPE = usbtiny -# extra arguments to avrdude: baud rate, chip type, -F flag, etc. -PROGRAMMER_ARGS = - -##########------------------------------------------------------########## -########## Program Locations ########## -########## Won't need to change if they're in your PATH ########## -##########------------------------------------------------------########## - -CC = avr-gcc -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AVRSIZE = avr-size -AVRDUDE = avrdude - -##########------------------------------------------------------########## -########## Makefile Magic! ########## -########## Summary: ########## -########## We want a .hex file ########## -########## Compile source files into .elf ########## -########## Convert .elf file into .hex ########## -########## You shouldn't need to edit below. ########## -##########------------------------------------------------------########## - -## The name of your project (without the .c) -# TARGET = blinkLED -## Or name it automatically after the enclosing directory -TARGET = $(lastword $(subst /, ,$(CURDIR))) - -# Object files: will find all .c/.h files in current directory -# and in LIBDIR. If you have any other (sub-)directories with code, -# you can add them in to SOURCES below in the wildcard statement. -SOURCES=$(wildcard *.c $(LIBDIR)/*.c) -OBJECTS=$(SOURCES:.c=.o) -HEADERS=$(SOURCES:.c=.h) - -## Compilation options, type man avr-gcc if you're curious. -CPPFLAGS = -DF_CPU=$(F_CPU) -DBAUD=$(BAUD) -I. -I$(LIBDIR) -CFLAGS = -Os -g -std=gnu99 -Wall -## Use short (8-bit) data types -CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -## Splits up object files per function -CFLAGS += -ffunction-sections -fdata-sections -LDFLAGS = -Wl,-Map,$(TARGET).map -## Optional, but often ends up with smaller code -LDFLAGS += -Wl,--gc-sections -## Relax shrinks code even more, but makes disassembly messy -## LDFLAGS += -Wl,--relax -## LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf -## LDFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf -TARGET_ARCH = -mmcu=$(MCU) - -## Explicit pattern rules: -## To make .o files from .c files -%.o: %.c $(HEADERS) Makefile - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<; - -$(TARGET).elf: $(OBJECTS) - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@ - -%.hex: %.elf - $(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%.eeprom: %.elf - $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ - -%.lst: %.elf - $(OBJDUMP) -S $< > $@ - -## These targets don't have files named after them -.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses - -all: $(TARGET).hex - -debug: - @echo - @echo "Source files:" $(SOURCES) - @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD) - @echo - -# Optionally create listing file from .elf -# This creates approximate assembly-language equivalent of your code. -# Useful for debugging time-sensitive bits, -# or making sure the compiler does what you want. -disassemble: $(TARGET).lst - -disasm: disassemble - -# Optionally show how big the resulting program is -size: $(TARGET).elf - $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf - -clean: - rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ - $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ - $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ - $(TARGET).eeprom - -squeaky_clean: - rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~ *.eeprom - -##########------------------------------------------------------########## -########## Programmer-specific details ########## -########## Flashing code to AVR using avrdude ########## -##########------------------------------------------------------########## - -flash: $(TARGET).hex - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$< - -## An alias -program: flash - -flash_eeprom: $(TARGET).eeprom - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$< - -avrdude_terminal: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt - -## If you've got multiple programmers that you use, -## you can define them here so that it's easy to switch. -## To invoke, use something like `make flash_arduinoISP` -flash_usbtiny: PROGRAMMER_TYPE = usbtiny -flash_usbtiny: PROGRAMMER_ARGS = # USBTiny works with no further arguments -flash_usbtiny: flash - -flash_usbasp: PROGRAMMER_TYPE = usbasp -flash_usbasp: PROGRAMMER_ARGS = # USBasp works with no further arguments -flash_usbasp: flash - -flash_arduinoISP: PROGRAMMER_TYPE = avrisp -flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0 -## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5 -flash_arduinoISP: flash - -flash_109: PROGRAMMER_TYPE = avr109 -flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0 -flash_109: flash - -##########------------------------------------------------------########## -########## Fuse settings and suitable defaults ########## -##########------------------------------------------------------########## - -## Mega 48, 88, 168, 328 default values -LFUSE = 0x62 -HFUSE = 0xdf -EFUSE = 0x00 - -## Generic -FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m - -fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \ - $(PROGRAMMER_ARGS) $(FUSE_STRING) -show_fuses: - $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv - -## Called with no extra definitions, sets to defaults -set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m -set_default_fuses: fuses - -## Set the fuse byte for full-speed mode -## Note: can also be set in firmware for modern chips -set_fast_fuse: LFUSE = 0xE2 -set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m -set_fast_fuse: fuses - -## Set the EESAVE fuse byte to preserve EEPROM across flashes -set_eeprom_save_fuse: HFUSE = 0xD7 -set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -set_eeprom_save_fuse: fuses - -## Clear the EESAVE fuse byte -clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m -clear_eeprom_save_fuse: fuses +include $(LIBDIR)/include.mak