I am using Eclipse to program a ATMega2560 and would like to stay away from the Arduino library, While looking through AVR Examples I have seen the syntax
#include <avr/io.h>
PORTD.0 = 1
or
PORTD.DIR = 1;
instead of
PORTD = 0b11111111;
To define and control the Inputs/Outputs when I try to use this syntax I get compiler errors:
error: request for member 'DIR' in '*34u', which is of non-class type 'volatile uint8_t {aka volatile unsigned char}'
I am sure that I am simply missing a include file or something but I can't figure out what I am doing wrong.
-
Where did you find the example code? That is not valid syntax for the AVR io definitions. Looks like PIC.Mikael Patel– Mikael Patel2016年05月19日 19:58:43 +00:00Commented May 19, 2016 at 19:58
-
@MikaelPatel I have seen this quite a few times while searching for AVR, here is one site elecrom.com/2008/02/12/avr-tutorial-2-avr-input-outputAndy Braham– Andy Braham2016年05月19日 20:23:11 +00:00Commented May 19, 2016 at 20:23
-
That is (as below) for another compiler (CodeVisionAVR) and not AVR-GCC which is used for the Arduino IDE. I guess that something similar (e.g. PORT[0]) could be defined in C++ using a class for Ports and an index operator. The dot operator (or struct) would have to be symbols (e.g. PORT.bit0). You could have a look at Cosa, github.com/mikaelpatel/Cosa.Mikael Patel– Mikael Patel2016年05月19日 22:24:12 +00:00Commented May 19, 2016 at 22:24
1 Answer 1
What you're doing wrong is that you're using the wrong compiler. That syntax is for CodeVision or mikroC, but the Arduino IDE uses GCC. Which follows global standards rather than making syntax up.
-
Holy cow! Alright I see, I thought CodeVision was an IDE or something. Too bad, that's a nice way of doing it.Andy Braham– Andy Braham2016年05月19日 21:05:39 +00:00Commented May 19, 2016 at 21:05