Using Visual Studio to code for AVR

孤者浪人 提交于 2019-12-08 02:51:44

问题


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

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.

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


回答1:


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;
}

You may find what macro corresponds to which MCU in the middle of this page




回答2:


i would suggest to simply use the original IDE as Make-File generator and just call that makefile from the VS2013. This has the overhead for maintaining two different projects (but mostly actions that require changes to makefile are rare) but leaves the comfort of the good VS IDE and leaves you the way back to original IDE for debugging.

you also have to set the include directories in the vs2013 project settings to get the intellisense work.



来源:https://stackoverflow.com/questions/21796762/using-visual-studio-to-code-for-avr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!