在AVR程序中使用Arduino库

时间:2016-05-07 15:56:44

标签: makefile arduino avr atmega

我试图从使用像Arduino uno这样的开发板到直接编程到AVR的过渡。但是,Arduino库以及一些第三方Arduino库非常有用,我希望能够使用它们,但是我无法调整makefile以包含它们。目前我只是想包含我下载的“TimerOne”库。它只是提供了使用AVR定时器和ISR的便捷方法。我非常简单的测试应用程序只是尝试每秒切换LED。

我的makefile如下所示:

# Name: Makefile
#
# A simple program for the ATMEGA32A-PU that blinks an LED.
#

DEVICE     = atmega32
CLOCK      = 1000000
PROGRAMMER = -c avrisp 
OBJECTS    = main.o

# List any extra directories to look for include files here.
#     Each directory must be seperated by a space.
EXTRAINCDIRS = -IC:\WinAVR-20100110\avr\include\Timer1

# for ATTiny85 - unset CKDIV8
FUSES       = -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 

# Tune the lines below only if you know what you are doing:

AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-g++ $(EXTRAINCDIRS) -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)

# symbolic targets:
all:  main.hex

.c.o:
    $(COMPILE) -c $< -o $@
.cpp.o:
    $(COMPILE) -c $< -o $@

.S.o:
    $(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
    $(COMPILE) -S $< -o $@
.cpp.s:
    $(COMPILE) -S $< -o $@

flash:  all
    $(AVRDUDE) -U flash:w:main.hex:i

fuse:
    $(AVRDUDE) $(FUSES)

# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse

# if you use a bootloader, change the command below appropriately:
load: all
    bootloadHID main.hex

clean:
    rm -f main.hex main.elf $(OBJECTS)

# file targets:
main.elf: $(OBJECTS)
    $(COMPILE) -o main.elf $(OBJECTS)

main.hex: main.elf
    rm -f main.hex
    avr-objcopy -j .text -j .data -O ihex main.elf main.hex
    avr-size --format=avr --mcu=$(DEVICE) main.elf
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

# Targets for code debugging and analysis:
disasm: main.elf
    avr-objdump -d main.elf

cpp:
    $(COMPILE) -E main.c

的main.c

#include "TimerOne.h"
#include <avr/io.h>
void refresh();
int main(void)
{

  DDRD |= 0xff;     //Set PortD Pins as an output
  PORTD |= 0xff;    //Set PortD Pins high to turn on LEDs
  Timer1.initialize(1000000); // 1000000us = 1s
  Timer1.attachInterrupt(refresh);

  while(1) { }          //Loop forever, interrupts do the rest
}

void refresh()
{
    PORTD ^= 0XFF;
}

我运行make时遇到的错误是:

avr-g++ -IC:\WinAVR-20100110\avr\include\Timer1 -Wall -Os -DF_CPU=1000000 -mmcu=atmega32 -c main.c -o main.o
avr-g++ -IC:\WinAVR-20100110\avr\include\Timer1 -Wall -Os -DF_CPU=1000000 -mmcu=atmega32 -o main.elf main.o
main.o: In function `main':
main.c:(.text+0x12): undefined reference to `Timer1'
main.c:(.text+0x14): undefined reference to `Timer1'
main.c:(.text+0x1e): undefined reference to `TimerOne::initialize(long)'
main.c:(.text+0x22): undefined reference to `Timer1'
main.c:(.text+0x24): undefined reference to `Timer1'
main.c:(.text+0x32): undefined reference to `TimerOne::attachInterrupt(void (*)(), long)'
make: *** [main.elf] Error 1  

从外观上看,似乎我没有正确地告诉编译器构建TimerOne库。我错过了什么?
我正在运行Windows10 x64。

0 个答案:

没有答案