> ----- Message from Jerome Kerdreux <[EMAIL PROTECTED]> on Sat, 25 Mar
> 2006 21:06:50 +0100 -----
> 
> To:
> 
> [email protected]
> 
> Subject:
> 
> Re: [avr-gcc-list] simple macro to dig w/ ports
> 
> 
> 
> 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 ;) 

Absolutely!
I guess I was about half way there with my attempt, but I was struggling 
with how to combine the port and pin data into one symbol. Thanks to Dave 
Hansen, and thank you for putting it on the list.

Colin

###########################################################################
This e-mail is confidential and may contain information subject to legal 
privilege.  If you are not the intended recipient please advise us of our
error by return e-mail then delete this e-mail and any attached files.  
You may not copy, disclose or use the contents in any way.  

The views expressed in this e-mail may not be those of Gallagher Group 
Ltd or subsidiary companies thereof.
###########################################################################


_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to