WinAVR/GCC 使用一个叫 Makefile 的文件,存放这些参数。在WinAVR上也有一个叫mfile的应用程序去处理这个Makefile 文件。但我们测试时发现,mfile 的缺陷很多,不好用,并且容易弄错。我们推荐大家直接用记事本等,直接编译这个文件。为了方便阅读与修改,我们将最常用的内容,放到Makefile的最前面,并且作了中文注解。
你可以点击此处下载这个makefile文件的压缩包((需要解压后才能使用,不要改名))。为了方便阅读,我们将这个Makefile排版成彩色的网页格式,你也可以直接点击这里查看makefile的具体内容。
# MCU name
# 单片机类型 参考格式是:atmega8 / at90s2313 / attiny15
MCU = atmega16
# Processor frequency.
# 系统时钟频率(Hz),用于生成延时 _delay_us() _delay_ms() 见delay.h
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
F_CPU = 1000000
# Target file name (without extension).
# 目标文件名(即生成的.hex/.eep/.elf的文件名)
TARGET = main
# List C source files here. (C dependencies are automatically generated.)
# C源文件名(不带路径)
# 多个文件名间用空格隔开 例如 SRC = file1.c file2.c file3.c
# 不需要加上 h头文件
SRC = $(TARGET).c
#**************后面内容基本不需要修改,除非你是老手*****************************#
# Output format. (can be srec, ihex, binary)
# 输出烧录文件格式
FORMAT = ihex
# Optimization level, can be [0, 1, 2, 3, s].
# 优化级别
# ...... 下面的内容此处省略 ....
将我们这个示范的 Makefile 文件,下载后拷贝到 c:\avr_test 目录中。上面我们已经设置了ATmega16芯片,工作在1M的频率里,主文件名叫 main.c ,只有一个文件。