Define Macros to SET and CLEAR bit of a PIN in C
Given a PIN (value in HEX) and bit number, we have to SET and then CLEAR given bit of the PIN (val) by using Macros.
Macros definitions:
#define SET(PIN,N) (PIN |= (1<<N))
#define CLR(PIN,N) (PIN &= ~(1<<N))
Here,
- SET and CLR are the Macro names
- PIN is the value whose bit to set or/and clear
- N is the bit number to set or/and clear
Example:
Output
Explanation: