Hi,

some people do prefer homemade functions or macros, maybe only for 
confusing others, but i do prefer the standard way, iso646, which is part
of C99 and gcc/mspgcc:

#ifndef _ISO646_H
#define _ISO646_H

#ifndef __cplusplus
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
#endif

#endif

So if you want to set BIT3 and BIT5 you only have to write

P0OUT or_eq BIT3 bitor BIT5;

and if you want to clear BIT2 and BIT6 you write

P0OUT and_eq compl BIT2 bitand compl BIT6;

or

P0OUT and_eq compl (BIT2 bitor BIT6);

That's much easier to read and understand and therefore a good way
to reduce the number of errors; e. g. mix up and and bitand.

The bits BIT0, BIT1 ... are common bits, defined in common.h; the is no need
to make homemade other defines if you do not want to confuse others.

Regards,

Rolf


mspgcc-users@lists.sourceforge.net schrieb am 11.02.06 02:23:43:
> 
> Hi everyone, 
> 
> Cann't find anything in the docs or header files on bit bashing except mask 
> defs for each pin. 
> 
> P0OUT |= P0OUT_0 and P0OUT &= ~P0OUT_0 certainly work but seem very verbose 
> for bit bashing a single pin. 
> 
> Is there a clearer way? I'd like to be able to write something like P0OUT.0 = 
> 1;. 
> 
> Keep the good work up, 
> 
> John Pote 

Reply via email to