C , , foo(), . , .
#define PIN_00 0x00000001, 0x00000000
#define PIN_01 0x00000002, 0x00000000
#define PIN_31 0x80000000, 0x00000000
#define PIN_32 0x00000000, 0x00000001
#define PIN_63 0x00000000, 0x80000000
inline void foo (unsigned long reg1, unsigned long reg2)
{
register0 |= reg1;
register1 |= reg2;
}
Then, to use this function foo(), you must specify an appropriate definition. Since a bitwise OR with a zero value does not change, the registers will be updated accordingly.
foo (PIN_00);
foo (PIN_01);
foo (PIN_32);
foo (PIN_63);
If you need to add a way to delete bits, you can create a new function using the same settings as below:
inline void fooRemove (unsigned long reg1, unsigned long reg2)
{
register0 &= ~reg1;
register1 &= ~reg2;
}
source
share