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

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

Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignm


From: George Kalovyrnas
Subject: Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Thu, 09 Dec 2004 11:14:35 +0200
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

Ned Konz wrote:

There is a useful distinction between registers whose contents are in fact nonvolatile (like for instance DDRB) and those whose contents can be changed by hardware events (like PORTB, PINB, and the ADC value registers).
and,

However, DDRB (say) does not have to be defined as volatile, since hardware isn't going to change it.

I think that the safe way is to declare ALL hardware registers as volatile. You use the example of DDR registers. Consider what will happen in this case:

DDRB = 0x01;
PORTB = 0x01;
/*
Some code here
*/
DDRB = 0x00;
temp = PINB;

I know that it is rare to use a single port pin as input and output, but there are cases that this could happen (I know it happened to me). The optimization would lead to disaster.

Another example of a register who is not going to change by hardware events is the UART Baud Rate Register (UBRR). Again, the optimization will confuse you definitely.


George Kalovyrnas
Athens, Greece


reply via email to

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