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: Colin Wall
Subject: Re: [avr-gcc-list] simple macro to dig w/ ports
Date: Fri, 24 Mar 2006 09:17:31 +1200

> ----- Message from Jkx <address@hidden> on Thu, 23 Mar 2006 13:52:
> 34 +0100 -----
> 
> To:
> 
> address@hidden
> 
> Subject:
> 
> [avr-gcc-list] simple macro to dig w/ ports
> 
> 
> I'm wondering if one of you have some macros or interesting
> idea to simplifie the sbi/cbi code. A example is nicer than
> a long talk. 
> 
> I want to transform this:
> - sbi(PORTD,PD6)
> - to something like sbi(PD6) (yes i use a the old fashion
>   sbi/cbi code, because I'm a old fashion guy:)
> 
> And I'm wondering if I can extend this kind of stuff to 
> other stuffs like DDR* .. 
> 
> In fact, I'm trying to teach the AVR programming to some 
> newbie, and having to play w/ a bunch of stuffs isn't really
> the best way. 
> 
> 
> Thanks for any help.

Try these macros:
#define pin_high(signal)   \
{                          \
        signal ## _port |= _BV(signal ## _pin);   \
}

#define pin_low(signal)    \
{                          \
        signal ## _port &= ~_BV(signal ## _pin);   \
}

and define your pins like this:
#define LED_port                PORTD
#define LED_pin         PD2

then write code like this:
pin_high(LED);
pin_low(LED);

You have to be consistent with the pin definitions, but it works ok. You 
can extend the idea to include DDR and PIN registers.

Cheers,
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.
###########################################################################




reply via email to

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