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: James Washer
Subject: Re: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments
Date: Mon, 6 Dec 2004 12:52:38 -0800

Bingo... with Dave (and others help).. I know have the following, which allows 
me to work with PORTx, PINx, and DDRx. This allows me to change the assignment 
of a pin in one place in the code, and have the DDRx change along with it.. Cool

 - jim


#include <avr/io.h>

#define DATA1         D, 7
#define DATA2         C, 3
#define DATA3         B, 3

#define PINDEF_PORT(a,b)        (PORT##a)
#define DDR(a,b)        (DDR##a)
#define PINDEF_PIN(a,b) (b)

//Set a pin
#define SETPIN(pindef)  PINDEF_PORT(pindef) |= (1 << PINDEF_PIN(pindef))

//Clear a pin
#define CLRPIN(pindef)  PINDEF_PORT(pindef) &= ~(1 << PINDEF_PIN(pindef))

//Set a IO to output
#define DDR_OUT(pindef) DDR(pindef) |= (1 << PINDEF_PIN(pindef))

//Set a IO to input
#define DDR_IN(pindef)  DDR(pindef) &= ~(1 << PINDEF_PIN(pindef))

//Read the value of a pin
#define GETPIN(pindef)  PINDEF_PORT(pindef) & (1 << PINDEF_PIN(pindef))

int main(void){
uint8_t value;


        DDR_OUT( DATA1 );
        DDR_IN( DATA2 );
        SETPIN( DATA1 );
        CLRPIN( DATA2 );
        value=GETPIN( DATA2 );
      
}

On Mon, 6 Dec 2004 11:45:49 -0800
"Dave Hylands" <address@hidden> wrote:

> 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 );
> 
> Y


reply via email to

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