The compiler should be smart enough that it doesn't need us to make things
simpler for it.  The important point is readability so the next person who
has to maintain the code is able to figure out what is going on.  Heck, I
might have to come back to my own code 6 months to a year later and want to
make it so I can quickly understand it again.

One minor point, though.  If you write your macro as:

#define P5_ALARM_ENABLE     (1<<5)

then the precompiler is going to put the "(1<< 5) into your code which is
going to put a 1 into a register and then shift it over before it even
applies the mask, an operation that is going to take several cycles.  I
would think it would be better if you defined things with your "or" case:

#define P5_ALARM_ENABLE   (0x20)

which should execute more efficiently.  Or is the optimizer smart enough to
recognize this too?  I don't know, I haven't looked at the code that these
would generate.

I'll go back to lurking now.

Jeff

On 7/12/06, Peter Jansen <[email protected]> wrote:


> // Alarm output
> #define ALARMENABLE         port2.out.pin5 = 1
> #define ALARMDISABLE        port2.out.pin5 = 0

I prefer to make it simpler for the compiler and generally define things
like

#define P5_ALARM_ENABLE (1<<5)    /* or 0x20 */
#define P5_ALARM        (1<<6)    /* or 0x40 */

and use it in the code like

P5_OUT |= P5_ALARM_ENABLE;
P5_OUT &= ~P5_ALARM_ENABLE;

then this also works,

P5_DIR |= P5_ALARM_ENABLE; /* make the ALARM_ENABLE pin an output */

and

if ((P5_IN & P5_ALARM) != 0)
{
        printf("Alarm set\n");
}

or

if ((P5_OUT & P5_ALARM_ENABLE) != 0)
{
        printf("Alarm enabled\n");
}


Ok, maybe its not as simple to write the main code as BitSet, BitReset
etc macros, bit its always obvious what is going on, and generally
compiles down to compact code,  you do have to know how the bits work,
but as an embedded programmer maybe that is a good thing.

As usual many ways to skin a cat.

Regards,

--
Peter Jansen


___________________________________________________________________________

    Australian Antarctic Division - Commonwealth of Australia
IMPORTANT: This transmission is intended for the addressee only. If you
are not the
intended recipient, you are notified that use or dissemination of this
communication is
strictly prohibited by Commonwealth law. If you have received this
transmission in error,
please notify the sender immediately by e-mail or by telephoning +61 3
6232 3209 and
DELETE the message.
        Visit our web site at http://www.aad.gov.au/

___________________________________________________________________________


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to