#define error - Codevision

Last post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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

If it is meant to happen... it WILL happen!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look up your PORTG0 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.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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!!

If it is meant to happen... it WILL happen!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mike B wrote:
Look up your PORTG0 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

If it is meant to happen... it WILL happen!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

beer_bains wrote:
write this in binary
Not sure what you mean exactly. Maybe this?
#define input ((PING & 0b00000001) != 0)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

If it is meant to happen... it WILL happen!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bit manipulation 101 read and enjoy.