EmbeddedRelated.com
Forums

Dynamic C Output macro

Started by gieltjev February 10, 2010
Hi,

Im just new to the rabbit platform, and i am trying to make macro's to
set pins and clear them.

Ive created this three Macro's to set or get the value from a pin:
  #define setPin(p,b,highval)   BitWrPortI(p,& ## p ##
Shadow,highval,b)
  #define clearPin(p,b,highval) BitWrPortI(p,& ## p ## Shadow,highval
^ 1,b)
  #define getPin(p,b)   BitRdPortI(p,b)

If i use the macro's manually the SetPin and ClearPin work perfectly,
but i want to put the pins in a define.
I've given pin Names (like DO_0, DI_1, DO_4), they are defined as
following:
	#define DO_1 	PEDR,4,1
	#define DO_2 	PEDR,5,1
	#define DO_3 	PEDR,6,1
	#define DO_4 	PEDR,7,1
	#define DO_5 	PEDR,3,1

when i execute the macro's with DO_1 as argument the compiler gives
the following error:: "Wrong number of arguments in macro call."

What do i need to adjust to get this working?

Thanks in advantage,

Michiel


On Feb 11, 3:45=A0am, gieltjev <gielt...@hotmail.com> wrote:
> Hi, > > Im just new to the rabbit platform, and i am trying to make macro's to > set pins and clear them. > > Ive created this three Macro's to set or get the value from a pin: > =A0 #define setPin(p,b,highval) =A0 BitWrPortI(p,& ## p ## > Shadow,highval,b) > =A0 #define clearPin(p,b,highval) BitWrPortI(p,& ## p ## Shadow,highval > ^ 1,b) > =A0 #define getPin(p,b) =A0 BitRdPortI(p,b) > > If i use the macro's manually the SetPin and ClearPin work perfectly, > but i want to put the pins in a define. > I've given pin Names (like DO_0, DI_1, DO_4), they are defined as > following: > =A0 =A0 =A0 =A0 #define DO_1 =A0 =A0PEDR,4,1 > =A0 =A0 =A0 =A0 #define DO_2 =A0 =A0PEDR,5,1 > =A0 =A0 =A0 =A0 #define DO_3 =A0 =A0PEDR,6,1 > =A0 =A0 =A0 =A0 #define DO_4 =A0 =A0PEDR,7,1 > =A0 =A0 =A0 =A0 #define DO_5 =A0 =A0PEDR,3,1 > > when i execute the macro's with DO_1 as argument the compiler gives > the following error:: "Wrong number of arguments in macro call." > > What do i need to adjust to get this working? > > Thanks in advantage, > > Michiel
Try this #define setPinHelper(p,b,highval) BitWrPortI(p,& ## p ## Shadow,highval,b) #define setPin(v) setPinHelper(v) setPin(DO_1) Macro arguments don't get expanded until after the macro has been invoked.