STC15W408AS library 0.9.0
bits.h
1#ifndef STC15_BITSH
2#define STC15_BITSH
3/***************************************************************************************************
4 Macros for Bit Manipulation
5 ****************************************************************************************************/
6
7#define bit_shift_right(val, shift_size) (val >> shift_size)
8#define bit_shift_left(val, shift_size) (val << shift_size)
9#define bit_mask(bit_pos) bit_shift_left(1, bit_pos)
10
11#define bit_set(val, bit_mask_val) (val |= bit_mask_val)
12#define bit_clr(val, bit_mask_val) (val &= bit_mask_val)
13#define bit_tgl(val, bit_val) (val ^= bit_mask(bit_val))
14#define get_bit(val, bit_val) (val & bit_mask(bit_val))
15#define get_reg(val, bit_mask_val) (val & bit_mask_val)
16
17#define set_bits(reg, val, pos) (reg |= bit_shift_left(val, pos))
18#define clr_bits(reg, val, pos) (reg &= ~bit_shift_left(val, pos))
19
20#define test_if_bit_set(val, bit_mask_val) ((val & bit_mask_val) != 0)
21#define test_if_bit_cleared(val, bit_mask_val) ((val & bit_mask_val) == 0)
22
23#define test_if_all_bits_set(val, bit_mask_val) (get_reg(val, bit_mask_val) == bit_mask_val)
24#define test_if_any_bit_set(val, bit_mask_val) (get_reg(val, bit_mask_val) != 0)
25
26/**************************************************************************************************/
27
28
29/***************************************************************************************************
30 Definition of common Bit-Masks
31 ***************************************************************************************************/
32
33#define SBIT0 0x01
34#define SBIT1 0x02
35#define SBIT2 0x04
36#define SBIT3 0x08
37#define SBIT4 0x10
38#define SBIT5 0x20
39#define SBIT6 0x40
40#define SBIT7 0x80
41
42#define CBIT0 0xfe
43#define CBIT1 0xfd
44#define CBIT2 0xfb
45#define CBIT3 0xf7
46#define CBIT4 0xef
47#define CBIT5 0xdf
48#define CBIT6 0xbf
49#define CBIT7 0x7f
50
51
52/**************************************************************************************************/
53#endif