Using Visual Studio to code for AVR

2020-07-28 00:00发布

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.

2条回答
小情绪 Triste *
2楼-- · 2020-07-28 00:07

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.

查看更多
倾城 Initia
3楼-- · 2020-07-28 00:14

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

查看更多
登录 后发表回答