On Friday 07 December 2007, David VanHorn wrote: > > Next you are counting on reading the state of PORTB to toggle its > > output. With many CPUs reading an output port reads the actual pin > > states not the value previously written. I don't recall the AVR acts > > that way, but there is an easier way to toggle an AVR output pin: Write > > a 1 to its input. Like this: > > > > PINB = 0xff; // toggle all output pins on PORTB > > Reading the PORT register tells you what the bits are supposed to be. > Reading the PIN register tells you what they ARE. (assuming they are > inputs) Toggling by writing to PIN does not work on all AVRs. > > The easiest version would be to read PORT into a register, invert it, > and write it back. > Alternatively, you could save a byte in SRAM or a register, and every > timer through, complement it and write to PORT.
Or let the compiler handle reading from PIN and writing to PORT by using: PORTB ^= 0xff; -- Julius _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list