avr-gcc-list
[Top][All Lists]
Advanced

[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: David VanHorn
Subject: Re: [avr-gcc-list] Problem with timer0 overflow interrupt in c language..
Date: Thu, 6 Dec 2007 18:30:05 -0500

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




reply via email to

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