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

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

Re: [avr-gcc-list] simple macro to dig w/ ports


From: Jerome Kerdreux
Subject: Re: [avr-gcc-list] simple macro to dig w/ ports
Date: Sat, 25 Mar 2006 21:06:50 +0100


Dave Hansen give me a better solution I think, 
here a cut / paste of his anwser

--- begin included file ---
#define BIT(p,b)                (b)

#define PORT(p,b)               (PORT ## p)
#define PIN(p,b)                (PIN ## p)
#define DDR(p,b)                (DDR ## p)

#define MASK(b)                 (1 << (b))

#define Set_Port_Bit(p,b)       ((p) |= MASK(b))
#define Clr_Port_Bit(p,b)       ((p) &= ~MASK(b))
#define Tgl_Port_Bit(p,b)       ((p) ^= MASK(b))

#define Get_Port_Bit(p,b)       (((p) & MASK(b)) != 0)

#define Set_Output(io)          Set_Port_Bit(PORT(io),BIT(io))
#define Reset_Output(io)        Clr_Port_Bit(PORT(io),BIT(io))
#define Toggle_Output(io)       Tgl_Port_Bit(PORT(io),BIT(io))
#define Get_Output(io)          Get_Port_Bit(PORT(io),BIT(io))

#define Get_Input(io)           Get_Port_Bit(PIN(io),BIT(io))

#define Tristate(io)            Clr_Port_Bit(DDR(io),BIT(io))
#define Drive(io)               Set_Port_Bit(DDR(io),BIT(io))

--- end included file ---


A little example:

#define LED  B,6

Set_Ouput(LED);

I tweaked this a bit, to rename some stuff, but it's work fine,
and it's easy to use. 

I guess Dave win the contest ;) 


Thanks






reply via email to

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