Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. ##########------------------------------------------------------##########
  2. ##########              Project-specific Details                ##########
  3. ##########    Check these every time you start a new project    ##########
  4. ##########               Book Make: AVR Programming             ##########
  5. ##########    https://github.com/hexagon5un/AVR-Programming     ##########
  6. ##########------------------------------------------------------##########
  7.  
  8. MCU   = atmega328p
  9. F_CPU = 1000000
  10. BAUD = 9600
  11. ## Also try BAUD = 19200 or 38400 if you're feeling lucky.
  12.  
  13. ## This is where your main() routine lives
  14. #MAIN = Serial_HC595_v1.c
  15. #MAIN = Serial_HC595_v2.c
  16. MAIN = Serial_HC595_v3.c
  17.  
  18. ## If you've split your program into multiple .c / .h files,
  19. ## include the additional source (in same directory) here
  20. LOCAL_SOURCE =
  21.  
  22. ## Here you can link to one more directory (and multiple .c files)
  23. #EXTRA_SOURCE_DIR = ../../AVR-Programming-Library/
  24. EXTRA_SOURCE_DIR =
  25. EXTRA_SOURCE_FILES =
  26.  
  27. ##########------------------------------------------------------##########
  28. ##########                 Programmer Defaults                  ##########
  29. ##########          Set up once, then forget about it           ##########
  30. ##########        (Can override.  See bottom of file.)          ##########
  31. ##########------------------------------------------------------##########
  32.  
  33. PROGRAMMER_TYPE = usbasp
  34. # extra arguments to avrdude: baud rate, chip type, -F flag, etc.
  35. PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0
  36.  
  37. ##########------------------------------------------------------##########
  38. ##########                   Makefile Magic!                    ##########
  39. ##########         Summary:                                     ##########
  40. ##########             We want a .hex file                      ##########
  41. ##########        Compile source files into .elf                ##########
  42. ##########        Convert .elf file into .hex                   ##########
  43. ##########        You shouldn't need to edit below.             ##########
  44. ##########------------------------------------------------------##########
  45.  
  46. ## Defined programs / locations
  47. CC = avr-gcc
  48. OBJCOPY = avr-objcopy
  49. OBJDUMP = avr-objdump
  50. AVRSIZE = avr-size
  51. AVRDUDE = avrdude
  52.  
  53. ## Compilation options, type man avr-gcc if you're curious.
  54. CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -DBAUD=$(BAUD) -Os -I. -I$(EXTRA_SOURCE_DIR)
  55. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  56. CFLAGS += -Wall -Wstrict-prototypes
  57. CFLAGS += -g -ggdb
  58. CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--relax
  59. CFLAGS += -std=gnu99
  60. ## CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm  ## for floating-point printf
  61. ## CFLAGS += -Wl,-u,vfprintf -lprintf_min      ## for smaller printf
  62.  
  63. ## Lump target and extra source files together
  64. TARGET = $(strip $(basename $(MAIN)))
  65. SRC = $(TARGET).c
  66. EXTRA_SOURCE = $(addprefix $(EXTRA_SOURCE_DIR), $(EXTRA_SOURCE_FILES))
  67. SRC += $(EXTRA_SOURCE)
  68. SRC += $(LOCAL_SOURCE)
  69.  
  70. ## List of all header files
  71. HEADERS = $(SRC:.c=.h)
  72.  
  73. ## For every .c file, compile an .o object file
  74. OBJ = $(SRC:.c=.o)
  75.  
  76. ## Generic Makefile targets.  (Only .hex file is necessary)
  77. all: $(TARGET).hex
  78.  
  79. %.hex: %.elf
  80.     $(OBJCOPY) -R .eeprom -O ihex $< $@
  81.  
  82. %.elf: $(SRC)
  83.     $(CC) $(CFLAGS) $(SRC) --output $@
  84.  
  85. %.eeprom: %.elf
  86.     $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
  87.  
  88. debug:
  89.     @echo
  90.     @echo "Source files:"   $(SRC)
  91.     @echo "MCU, F_CPU, BAUD:"  $(MCU), $(F_CPU), $(BAUD)
  92.     @echo  
  93.  
  94. # Optionally create listing file from .elf
  95. # This creates approximate assembly-language equivalent of your code.
  96. # Useful for debugging time-sensitive bits,
  97. # or making sure the compiler does what you want.
  98. disassemble: $(TARGET).lst
  99.  
  100. disasm: disassemble
  101.  
  102. eeprom: $(TARGET).eeprom
  103.  
  104. %.lst: %.elf
  105.     $(OBJDUMP) -S $< > $@
  106.  
  107. # Optionally show how big the resulting program is
  108. size:  $(TARGET).elf
  109.     $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf
  110.  
  111. clean:
  112.     rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \
  113.     $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \
  114.     $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \
  115.     $(TARGET).eeprom
  116.  
  117. squeaky_clean:
  118.     rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~
  119.  
  120. ##########------------------------------------------------------##########
  121. ##########              Programmer-specific details             ##########
  122. ##########           Flashing code to AVR using avrdude         ##########
  123. ##########------------------------------------------------------##########
  124.  
  125. flash: $(TARGET).hex
  126.     $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$<
  127.  
  128. ## An alias
  129. program: flash
  130.  
  131. flash_eeprom: $(TARGET).eeprom
  132.     $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$<
  133.  
  134. avrdude_terminal:
  135.     $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt
  136.  
  137. ## If you've got multiple programmers that you use,
  138. ## you can define them here so that it's easy to switch.
  139. ## To invoke, use something like `make flash_arduinoISP`
  140. flash_usbtiny: PROGRAMMER_TYPE = usbtiny
  141. flash_usbtiny: PROGRAMMER_ARGS =  # USBTiny works with no further arguments
  142. flash_usbtiny: flash
  143.  
  144. flash_usbasp: PROGRAMMER_TYPE = usbasp
  145. flash_usbasp: PROGRAMMER_ARGS =  # USBasp works with no further arguments
  146. flash_usbasp: flash
  147.  
  148. flash_arduinoISP: PROGRAMMER_TYPE = avrisp
  149. flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P /dev/ttyACM0
  150. ## (for windows) flash_arduinoISP: PROGRAMMER_ARGS = -b 19200 -P com5
  151. flash_arduinoISP: flash
  152.  
  153. flash_109: PROGRAMMER_TYPE = avr109
  154. flash_109: PROGRAMMER_ARGS = -b 9600 -P /dev/ttyUSB0
  155. flash_109: flash
  156.  
  157. ##########------------------------------------------------------##########
  158. ##########       Fuse settings and suitable defaults            ##########
  159. ##########------------------------------------------------------##########
  160.  
  161. ## Mega 48, 88, 168, 328 default values
  162. LFUSE = 0x62
  163. HFUSE = 0xdf
  164. EFUSE = 0x00
  165.  
  166. ## Generic
  167. FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
  168.  
  169. fuses:
  170.     $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \
  171.                $(PROGRAMMER_ARGS) $(FUSE_STRING)
  172. show_fuses:
  173.     $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv  
  174.  
  175. ## Called with no extra definitions, sets to defaults
  176. set_default_fuses:  FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
  177. set_default_fuses:  fuses
  178.  
  179. ## Set the fuse byte for full-speed mode
  180. ## Note: can also be set in firmware for modern chips
  181. set_fast_fuse: LFUSE = 0xE2
  182. set_fast_fuse: FUSE_STRING = -U lfuse:w:$(LFUSE):m
  183. set_fast_fuse: fuses
  184.  
  185. ## Set the EESAVE fuse byte to preserve EEPROM across flashes
  186. set_eeprom_save_fuse: HFUSE = 0xD7
  187. set_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m
  188. set_eeprom_save_fuse: fuses
  189.  
  190. ## Clear the EESAVE fuse byte
  191. clear_eeprom_save_fuse: FUSE_STRING = -U hfuse:w:$(HFUSE):m
  192. clear_eeprom_save_fuse: fuses