[Top][All Lists]
[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 14:33:44 -0800 |
Nice catch Dave... Might have taken a month of sundays to figure out why my
inputs were ALWAYS 0 ;-)
- jim
On Mon, 06 Dec 2004 16:55:49 -0500
"Dave Hansen" <address@hidden> wrote:
> From: James Washer <address@hidden>
> [...]
> >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)
>
> You might simplify some of your macros if you change this one to
>
> #define PINDEF_PIN(a,b) (1<<(b))
>
> >
> >//Set a pin
> >#define SETPIN(pindef) PINDEF_PORT(pindef) |= (1 << PINDEF_PIN(pindef))
>
> Then this one becomes
>
> #define SETPIN(pindef) PINDEF_PORT(pindef) |= PINDEF_PIN(pindef)
>
> >
> >//Clear a pin
> >#define CLRPIN(pindef) PINDEF_PORT(pindef) &= ~(1 << PINDEF_PIN(pindef))
>
> And this one
>
> #define CLRPIN(pindef) PINDEF_PORT(pindef) &= ~PINDEF_PIN(pindef)
>
> and so forth...
>
> [...]
> >//Read the value of a pin
> >#define GETPIN(pindef) PINDEF_PORT(pindef) & (1 << PINDEF_PIN(pindef))
>
> You'll probably be disappointed with this one. Try
>
> #define PINDEF_PINPORT(pindef) (PIN ## a)
> #define GETPIN(pindef) PINDEF_PINPORT(pindef) & (1 <<
> PINDEF_PIN(pindef))
>
> Regards,
> -=Dave
>
>
RE: [avr-gcc-list] Question about gcc preprocessing and port/pin assignments, Dave Hylands, 2004/12/08