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

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

Re: [avr-gcc-list] efficiency of assigning bits


From: Ned Konz
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Fri, 18 Mar 2005 09:28:24 -0800
User-agent: KMail/1.7.2

On Friday 18 March 2005 8:59 am, E. Weddington wrote:
> When you are using symbolic names you have the opportunity to not be
> tied to a particular implementation. What this means is that if that
> particular bit changed position, then you wouldn't have to change all
> these hardcoded numbers all over your code. You just change the
> definition of the symbol. This method works very well in your own
> application where you can provide application specific symbols, such as:
>
> #define STATUS_LED    3
> //......
> PORTA |= _BV(STATUS_LED);
>
> What if the above code was for a prototype board, which then needed to
> be re-layed out? What if the status LED needed to move to a different
> pin? Then all you have to do is to change the definition, in one place
> only; the code stays the same.


Even better, use higher-level constructs like inline functions (better than 
macros, because they're type-safe and can do more). In this case, of course, 
it would be easy to do with a macro.

/* in a header file */

const uint8_t STATUS_LED = 3;

static inline
void turnLedOn(void)
{
 PORTA |= _BV(STATUS_LED);
}

/* in your main C source */

#include "myIODefinitions.h"

...
 turnLedOn();
...


-- 
Ned Konz
http://bike-nomad.com





reply via email to

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