#define BIT_CLR(reg,bit) do { (reg) &= ~ _BV(bit); } while (0) #define BIT_SET(reg,bit) do { (reg) |= _BV(bit); } while (0) #define BIT_TST(reg,bit) (((reg) & _BV(bit)) != 0) // I/O port manipulation macros #define DDR_CLR(p,b) BIT_CLR(DDR ## p, b) #define DDR_SET(p,b) BIT_SET(DDR ## p, b) #define PORT_CLR(p,b) BIT_CLR(PORT ## p, b) #define PORT_SET(p,b) BIT_SET(PORT ## p, b) #define PORT_TST(p,b) BIT_TST(PORT ## p, b) #define PIN_TST(p,b) BIT_TST(PIN ## p, b) #define PIN_SET(p,b) BIT_SET(PIN ## p, b) // Macros that can be used with an argument of the form (port,bit) #define INPUT(bit) DDR_CLR bit #define OUTPUT(bit) DDR_SET bit #define CLR(bit) PORT_CLR bit #define SET(bit) PORT_SET bit #define ISSET(bit) PORT_TST bit #define TST(bit) PIN_TST bit #define TOGGLE(bit) PIN_SET bit // Bit string macros #define BIN8(n0) \ ((unsigned char) \ ( ((0x##n0##UL&0x00000001UL)>> 0) \ |((0x##n0##UL&0x00000010UL)>> 3) \ |((0x##n0##UL&0x00000100UL)>> 6) \ |((0x##n0##UL&0x00001000UL)>> 9) \ |((0x##n0##UL&0x00010000UL)>>12) \ |((0x##n0##UL&0x00100000UL)>>15) \ |((0x##n0##UL&0x01000000UL)>>18) \ |((0x##n0##UL&0x10000000UL)>>21) \ ) \ ) #define BIN16(n1,n0) \ ((unsigned short) \ ( (((unsigned short)BIN8(n1))<<8) \ |(((unsigned short)BIN8(n0))<<0) \ ) \ ) #define BIN32(n3,n2,n1,n0) \ ((unsigned long) \ ( (((unsigned long)BIN16(n3,n2))<<16)\ |(((unsigned long)BIN16(n1,n0))<< 0)\ ) \ )