clang setbit clearbit
原文链接: clang setbit clearbit
/include/linux/bitops.h
#define SET_BIT(x, n) (x |= (1 << n))
#define CLR_BIT(x, n) (x &= ~(1 << n))
#define GET_BIT(x, n) ((x >> n) & 0x01)
#define set_bit(register_8, bit) (register_8 |= (1 << bit))
#define clear_bit(register_8, bit) (register_8 &= ~(1 << bit))
#define toggle_bit(register_8, bit) (register_8 ^= (1 << bit))
#define set_bit(reg,bit) reg|=(1<<bit) //pondra en 1 el bit elegido de la variable elegida.
#define clr_bit(reg,bit) reg&=~(1<<bit) //pondra en 0 el bit elegido de la variable elegida.
#define tog_bit(reg,bit) reg^=(1<<bit) //toggleara el bit elegido de la variable elegida.
#define set_output(ddr,bit) ddr|=(1<<bit) //setea salida.
#define set_input(ddr,bit) ddr&=~(1<<bit) //setea entrada.
#define get_bit(ddr,bit) ((ddr>>bit)&1) //devuelve el bit elegido de la variable elegida (para if).
#define clr_reg(reg) reg&=0 //limpia el registro elegido.
#define set_reg(reg) reg|=255
#define led4_out set_output(DDRD,4)
#define led5_out set_output(DDRD,5)
#define led6_out set_output(DDRD,6)
#define led7_out set_output(DDRD,7)
#define led4_off set_bit(PORTD,4)
#define led5_off set_bit(PORTD,5)
#define led6_off set_bit(PORTD,6)
#define led7_off set_bit(PORTD,7)
#define HIGH 1
#define LOW 0
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
#define TOGGLE 2
#define ENABLE 1
#define DISABLE 0
#define ENABLED 1
#define DISABLED 0
#define NO 0
#define YES 1
#define PRESSED 1
#define STOP 0
#define FORWARD 1
#define REVERSE 2
#define SPIN_RIGHT 3
#define SPIN_LEFT 4
#define set_bit(var, pin) var |= 1<<(unsigned char) pin
#define clear_bit(var, pin) var &= ~(1<<(unsigned char)pin)
#define test_bit(var, pin) ((var & (1<<(unsigned char) pin)) >> pin)
#define toggle_bit(var, pin) var ^= 1<<(unsigned char) pin
#define clr_bit(var, pin) clear_bit(var,pin)
#define tog_bit(var, pin) toggle_bit(var,pin)
#define tst_bit(var, pin) var & (1<<(unsigned char) pin)
//#define set_bit(var, pin) var |= 1<<(unsigned char) pin
//#define clr_bit(var, pin) var &= ~(1<<(unsigned char)pin)
//#define tog_bit(var, pin) var ^= 1<<(unsigned char) pin
#define input_bit(var, pin) var &= ~(1<<(unsigned char) pin)
#define output_bit(var, pin) var |= 1<<(unsigned char) pin
#define digital_read(pin) pin_value(pin + 8)
#define quit() while(1)
#endif
contect
/* Handy macros for GPIO */
#define CONCAT(a, b) a##_##b
#define PORT(a, b) CONCAT(a , b)
#define LED_PORT PD
#define LED_PIN PIN3
/* GPIO setup */
// Set pin data direction as output
PORT(LED_PORT, DDR) |= LED_PIN; // i.e. PB_DDR |= (1 << 5);
// Set pin as "Push-pull"
PORT(LED_PORT, CR1) |= LED_PIN; // i.e. PB_CR1 |= (1 << 5);