使用Visual Studio为AVR编码 [英] Using Visual Studio to code for AVR

查看:486
本文介绍了使用Visual Studio为AVR编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2013编写AVR的代码.我一直在教程.

I am using Visual Studio 2013 to write code for AVR. I have been following this tutorial.

在编写代码时,我注意到Visual Studio一直在强调DDRBPORTB之类的内容,并不断出现诸如Error: identifier "PORTB" is undefined之类的错误,但是,程序可以正确编译.

Whilst writing the code, I noticed that Visual Studio kept on underlining things like DDRB or PORTB and I keep on getting errors like Error: identifier "PORTB" is undefined, however, the program compiles correctly.

有趣的是,在按 alt - F12 时,Visual会找到许多在其中定义文件的文件.

Interestingly enough, upon pressing alt-F12 Visual finds numerous files where they are defined.

推荐答案

您的Makefile运行带有-mmcu = YOURCHIP选项的编译器.这隐式定义了与您的芯片相对应的宏.例如,对于atmega32u4,宏为 AVR_ATmega32U4 . Intellisense在编译器外部运行,因此它不知道此宏,并且在解析标准avr标头时(例如avr/io.h)会跳过特定MCU的标头文件的正确包含.就像这样:

Your Makefile runs compiler with an option -mmcu=YOURCHIP. This implicitly defines macro corresponding to your chip. For instance for atmega32u4 the macro is AVR_ATmega32U4. Intellisense is run 'outside' of your compiler so it's not aware of this macro and when parsing standard avr header - like avr/io.hit skips the proper inclusion of header file for your particular MCU. It's something like:

#elif defined (__AVR_ATmega32U4__)
#  include <avr/iom32u4.h>

因此,如果要对这些标头中定义的内容提供智能支持,则可能需要在源顶部定义该宏,如下所示:

So, if you want to have intellisense support for stuff defined in those headers you might need to define that macro, at the top of your source, like this:

#define __AVR_ATmega32U4__ 
#include <avr/io.h> 
int main() { 
    char a = PORTB;
}

您可能会在此中间找到与哪个MCU对应的宏页面

这篇关于使用Visual Studio为AVR编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆