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: Dave Hylands
Subject: RE: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Mon, 6 Dec 2004 11:45:49 -0800

Hi Jim,

> What I'm hoping for is the ability to change the definition 
> of "switch" at any time, and have everything work

Here's my thoughts, which run similar to what others have reported but
with a couple minor refinements:

#define SWITCH        PORTD, 7
#define PINDEF_PORT(a,b)        (a)
#define PINDEF_PIN(a,b) (b)

#define setpin(pindef)  PINDEF_PORT(pindef) |= (1 << PINDEF_PIN(pindef))

And use it as:

        setpin( SWITCH );

You can generalize this and make a "definition" contain as many comma
separated attributes  as you like and then create "accessors" to just
return individual items.

Another, different approach, is to do something like this:

#define SWITCH_PORT     PORTD
#define SWITCH_PIN      7

#define setpin(pindef)  pindef ## _PORT |= (1 << pindef ## _PIN)

And use it as:

        setpin( SWITCH );

And as somebody else mentioned, you don't want to be #define'ing
"switch" to be anything since it's a reserved word in C.

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/ 



reply via email to

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