| Author |
Message |
|
|
Posted: Nov 19, 2010 - 12:27 AM |
|

Joined: Nov 18, 2010
Posts: 103
Location: Auckland, New Zealand
|
|
i am using codevision to write a program for a mega64.
in my definitions i used:
#define input PORTG.0
and then in the program i used:
if (input == 1)
{
do this do that etc
}
but when I compile it gives me an error sayin:
"the first argument of the '.' operator must be of 'struct' or 'union' type" and highlights the 'if' line which refers to the #define input line.
Is there something wrong with my syntax? How can I do this, what am I doing wrong?
searching the net, help files, data sheets hasn't really lead me anywhere so your help will be much appreciated.
Thanks |
|
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 12:35 AM |
|


Joined: Jun 22, 2004
Posts: 3849
Location: South West Utah, USA
|
|
Look up your PORTG<decimal>0 syntax in a C manual. The decimal point has a special meaning in C.
If you want to input from an AVR pin, use the PIN register, not the PORT register. Also use a different method of selecting pin 0. |
|
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 12:52 AM |
|

Joined: Jun 21, 2005
Posts: 882
Location: Chicago area, USA
|
|
As far as I remember, the CodeVision's portName.pinNumber extension works only for the first 32 registers. PORTG is outside that area. Therefore you have to access it using standard C methods. For example:
#define input ((PORTG & (1 << 0)) != 0)
But as Mike says, make sure that PORTG is really what you want. You say "input", which means that you probably want PING, not PORTG.
Eugene |
|
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 01:04 AM |
|

Joined: Nov 18, 2010
Posts: 103
Location: Auckland, New Zealand
|
|
|
ezharkov wrote:
As far as I remember, the CodeVision's portName.pinNumber extension works only for the first 32 registers. PORTG is outside that area. Therefore you have to access it using standard C methods. For example:
#define input ((PORTG & (1 << 0)) != 0)
But as Mike says, make sure that PORTG is really what you want. You say "input", which means that you probably want PING, not PORTG.
thanks for that. that explains why the codevision picks up portg as an error and not ports a c and d which i also did using the same way.
Mike is also right I want to use PING0. Can I do that the same way as you mentioned:
#define input ((PORTG & (1 << 0)) != 0)
also if you could please write this in binary, like #define input PING = ob_____ that will be a huge help for me to understand this better.
thanks a lot guys. knowledge gained!! |
|
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 01:09 AM |
|

Joined: Nov 18, 2010
Posts: 103
Location: Auckland, New Zealand
|
|
|
Mike B wrote:
Look up your PORTG<decimal>0 syntax in a C manual. The decimal point has a special meaning in C.
If you want to input from an AVR pin, use the PIN register, not the PORT register. Also use a different method of selecting pin 0.
yes that's right. I should really be using the PIN register. so thanks for that. When you say use a different method. What method could I used??
thank you |
|
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 01:09 AM |
|

Joined: Jun 21, 2005
Posts: 882
Location: Chicago area, USA
|
|
|
beer_bains wrote:
write this in binary
Not sure what you mean exactly. Maybe this?
#define input ((PING & 0b00000001) != 0) |
|
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 01:23 AM |
|

Joined: Nov 18, 2010
Posts: 103
Location: Auckland, New Zealand
|
|
|
ezharkov wrote:
#define input ((PING & 0b00000001) != 0)
thanks for that. sorry if i'm bein annoying... but from what I understand the above is exactly the same as:
#define input ((PING & (1 << 0)) != 0)
and what this does is it defines 'input' as PING0, ya??
cheers. thanks again. |
|
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 04:26 AM |
|

Joined: Nov 17, 2004
Posts: 13847
Location: Vancouver, BC
|
|
|
Quote:
but from what I understand the above is exactly the same as:
Yes.
Quote:
and what this does is it defines 'input' as PING0, ya??
What it does is give you the current value of bit 0 of the PING register. |
_________________ Regards,
Steve A.
The Board helps those that help themselves.
|
| |
|
|
|
|
|
Posted: Nov 19, 2010 - 10:56 AM |
|


Joined: Jul 18, 2005
Posts: 62324
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
|
|
|
|