Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
beer_bains
PostPosted: Nov 19, 2010 - 12:27 AM
Hangaround


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
 
 View user's profile Send private message  
Reply with quote Back to top
Mike B
PostPosted: Nov 19, 2010 - 12:35 AM
Raving lunatic


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.
 
 View user's profile Send private message  
Reply with quote Back to top
ezharkov
PostPosted: Nov 19, 2010 - 12:52 AM
Resident


Joined: Jun 21, 2005
Posts: 965
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
 
 View user's profile Send private message  
Reply with quote Back to top
beer_bains
PostPosted: Nov 19, 2010 - 01:04 AM
Hangaround


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!!
 
 View user's profile Send private message  
Reply with quote Back to top
beer_bains
PostPosted: Nov 19, 2010 - 01:09 AM
Hangaround


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
 
 View user's profile Send private message  
Reply with quote Back to top
ezharkov
PostPosted: Nov 19, 2010 - 01:09 AM
Resident


Joined: Jun 21, 2005
Posts: 965
Location: Chicago area, USA

beer_bains wrote:
write this in binary
Not sure what you mean exactly. Maybe this?
#define input ((PING & 0b00000001) != 0)
 
 View user's profile Send private message  
Reply with quote Back to top
beer_bains
PostPosted: Nov 19, 2010 - 01:23 AM
Hangaround


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.
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: Nov 19, 2010 - 04:26 AM
10k+ Postman


Joined: Nov 17, 2004
Posts: 15021
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.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Nov 19, 2010 - 10:56 AM
10k+ Postman


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

Bit manipulation 101 read and enjoy.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits