[Top][All Lists]

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

Re: [avr-gcc-list] Problem with timer0 overflow interrupt in c language.

From: Julius Luukko
Subject: Re: [avr-gcc-list] Problem with timer0 overflow interrupt in c language..
Date: Fri, 7 Dec 2007 08:55:16 +0200
User-agent: KMail/1.9.6 (enterprise 0.20071012.724442)

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;


reply via email to

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