[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] AVR GCC compiler for win98

From: Rob Ward
Subject: Re: [avr-gcc-list] AVR GCC compiler for win98
Date: Fri, 19 Apr 2002 09:56:23 +1200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.9) Gecko/20020311

Great. Ok, I understand that. So the next question...is there any way to toggle an i/o portline in a single clock cycle. On the PIC, it is easy...you can (in modified C) use PORTB.7 = 0 for example to clear bit 7 of portb. Is there some way of and'ing with the port registers on the AVR? The code below apparently did work, so how was that possible? Using pointers maybe?

Thanks in advance.

Rob Ward

Nils Kristian Strom wrote:
On Thu, 2002-04-18 at 16:19, Rob Ward wrote:
Hi. I am using GCC under w2k. I tried using this code from avrfreaks...

#define sw4_pin (1<<4) //this could be (1<<PD4)
#define sw4_port PORTD
#define sw4_dir DDRD
#define sw4_in PIND

Then the following to toggle the pin / i/o direction...

sw4_dir &= ~sw4_pin;//set port as input
sw4_port |= sw4_pin; //switch on pull up

however, I get "Invalid lvalue in assignment" for both the last two
lines when compiling. Could anyone tell my why this is?

If you look deeper into the header files, which declare PORTD and DDRD,
you will se that they look like this:
#define PORTD 0x12
#define PIND 0x10

So what you are writing, is in fact
0x12 |= 0x10;

So the compiler complainst Invalid lvalue (lvalue = left side value).
The compiler error makes prefect sense ;-)

The reason for this, is that IO registers (PORTB etc) are different from
normal registers (r0 through r31). You need to use in/out instructions
to move the contents of the IO registers to normal registers, then do
your arithmetic on these. Most people use the macros inp(), outp(),
sbi() and cbi() for this.

You must use these macros.

outp( sw4_pin, sw4_dir ); /* output */
foo = ~(inp( sw4_in ) ); /* read and invert */
outp( foo, sw4_port ); /* output */


Thanks in advance.

Rob Ward
Beaglehole Instruments Ltd.,
32 Salamanca Road,
New Zealand.
Phone +64 4 473 7749
Fax +64 4 473 2686


avr-gcc-list at http://avr1.org
reply via email to

[Prev in Thread] Current Thread [Next in Thread]