如何将一个位域和位内部传递给一个函数

时间:2014-11-02 08:49:42

标签: c embedded microcontroller

对于微控制器,您通常有一个寄存器及其位域版本,使您可以单独访问每个引脚

假设我有来自两个位域的两个对象

struct {
        unsigned a_A:1;
        unsigned b_A:1;
        unsigned c_A:1;
        unsigned d_A:1;
        unsigned e_A:1;
        unsigned f_A:1;
        unsigned g_A:1;
        unsigned h_A:1;
        }A;
struct {
        unsigned a_B:1;
        unsigned b_B:1;
        unsigned c_B:1;
        unsigned d_B:1;
        unsigned e_B:1;
        unsigned f_B:1;
        unsigned g_B:1;
        unsigned h_B:1;
        }B;

如何构建一个接受位域及其中一个位作为参数的函数 就像

void my_func(bitfield,bit_name)
对于每种类型的位域,

bit_name应该有所不同

1 个答案:

答案 0 :(得分:0)

怎么样?
void my_func(unsigned a_B);
...
void my_func(unsigned h_B);

并称之为:

my_func(B.a_B);
...
my_func(B.h_B);