[Top][All Lists]
[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
- Re: [avr-gcc-list] efficiency of assigning bits, (continued)
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/14
- Re: [avr-gcc-list] efficiency of assigning bits, Jamie Morken, 2005/03/17
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/17
- Re: [avr-gcc-list] efficiency of assigning bits, Royce & Sharal Pereira, 2005/03/17
- Re: [avr-gcc-list] efficiency of assigning bits, Dave Hansen, 2005/03/18
- Re: [avr-gcc-list] efficiency of assigning bits, David Brown, 2005/03/21
- Re: [avr-gcc-list] efficiency of assigning bits, Dave Hansen, 2005/03/21
- Re: [avr-gcc-list] efficiency of assigning bits, Royce & Sharal Pereira, 2005/03/18
- Re: [avr-gcc-list] efficiency of assigning bits, E. Weddington, 2005/03/18
- Re: [avr-gcc-list] efficiency of assigning bits, Jim Brain, 2005/03/18
- Re: [avr-gcc-list] efficiency of assigning bits, Graham Davies, 2005/03/19
- Re: [avr-gcc-list] efficiency of assigning bits, Jim Brain, 2005/03/19