For pin and LED control related #define directives use C language
compound statements. This lets call sites use the macros in intended
ways (like regular function calls) without needing to worry about their
implementation details, or suffering from unexpected behaviour.
Strictly speaking the single statement variants don't require the
wrapper, but I've added one for improved future maintenance.
#define SET_CALIBRATION_PULSE(x)
#define SET_CALIBRATION_PULSE(x)
-#define TOGGLE_CALIBRATION_PIN() PA7 = !PA7
+#define TOGGLE_CALIBRATION_PIN() do { PA7 = !PA7; } while (0)
-#define LED_CLEAR() PC0 = 1; PC1 = 1;
-#define LED_GREEN() PC0 = 1; PC1 = 0;
-#define LED_RED() PC0 = 0; PC1 = 1;
+#define LED_CLEAR() do { PC0 = 1; PC1 = 1; } while (0)
+#define LED_GREEN() do { PC0 = 1; PC1 = 0; } while (0)
+#define LED_RED() do { PC0 = 0; PC1 = 1; } while (0)
#include <delay.h>
#include <setupdat.h>
#include <delay.h>
#include <setupdat.h>
-#define SET_ANALOG_MODE() PA7 = 1
+#define SET_ANALOG_MODE() do { PA7 = 1; } while (0)
#define SET_COUPLING(x)
#define SET_CALIBRATION_PULSE(x)
#define SET_COUPLING(x)
#define SET_CALIBRATION_PULSE(x)
-#define TOGGLE_CALIBRATION_PIN() PC2 = !PC2
+#define TOGGLE_CALIBRATION_PIN() do { PC2 = !PC2; } while (0)
-#define LED_CLEAR() PC0 = 1; PC1 = 1;
-#define LED_GREEN() PC0 = 1; PC1 = 0;
-#define LED_RED() PC0 = 0; PC1 = 1;
+#define LED_CLEAR() do { PC0 = 1; PC1 = 1; } while (0)
+#define LED_GREEN() do { PC0 = 1; PC1 = 0; } while (0)
+#define LED_RED() do { PC0 = 0; PC1 = 1; } while (0)
#include <delay.h>
#include <setupdat.h>
#include <delay.h>
#include <setupdat.h>
-#define SET_ANALOG_MODE() PA7 = 1
+#define SET_ANALOG_MODE() do { PA7 = 1; } while (0)
#define SET_COUPLING(x) set_coupling(x)
#define SET_CALIBRATION_PULSE(x) set_calibration_pulse(x)
/* Note: There's no PE2 as IOE is not bit-addressable (see TRM 15.2). */
#define SET_COUPLING(x) set_coupling(x)
#define SET_CALIBRATION_PULSE(x) set_calibration_pulse(x)
/* Note: There's no PE2 as IOE is not bit-addressable (see TRM 15.2). */
-#define TOGGLE_CALIBRATION_PIN() IOE = IOE ^ 0x04
+#define TOGGLE_CALIBRATION_PIN() do { IOE = IOE ^ 0x04; } while (0)
#define LED_CLEAR() NOP
#define LED_GREEN() NOP
#define LED_CLEAR() NOP
#define LED_GREEN() NOP