We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I've been using defines as fucntions like this:
sbit DRIVE_PIN05 = P1^3;
#define DRIVE_PIN05_HIGH (P1MDOUT |= 0x08);(DRIVE_PIN05 = 0) #define DRIVE_PIN05_LOW (P1MDOUT |= 0x08);(DRIVE_PIN05 = 1) #define DRIVE_PIN05_OFF (P1MDOUT &= 0xF7);(DRIVE_PIN05 = 1)
Is it there anything wrong with doing it like this? It gives me problems when I include the above define into another define, why?
#define SUPPLY_ON (DRIVE_PIN05_HIGH);(DRIVE_PIN24_LOW) #define SUPPLY_OFF (DRIVE_PIN05_OFF);(DRIVE_PIN24_OFF)
Maybe my syntax is incorrect or it can't be done?
in other words: is e.g. DRIVE_PIN05 defined earlier in the file than the include of #define DRIVE_PIN05_OFF (P1MDOUT &= 0xF7);(DRIVE_PIN05 = 1). The preprocessor is not multi pass, if something is not defined before it is used, no go.
Not quite. It's not necessarily a problem if the definition of DRIVE_PIN05 doesn't precede the line
#define DRIVE_PIN05_OFF (P1MDOUT &= 0xF7);(DRIVE_PIN05 = 1)
It only has to precede every actual expansion of DRIVE_PIN05_OFF, i.e. each time it's DRIVE_PIN05_OFF is used outside of a macro body.
#define B A #define A C B
preprocesses to
C
as intended.