如果系统的实时性要求很高,内存还有一些,那我推荐你使用该招数。该招数的变招--使用宏函数而不是函数。举例如下:
方法C:
#define bwMCDR2_ADDRESS 4
#define bsMCDR2_ADDRESS 17
int BIT_MASK(int __bf)
{
return ((1U << (bw ## __bf)) - 1)<< (bs ## __bf);
}
void SET_BITS(int __dst,
int __bf, int __val)
{
__dst = ((__dst) & ~(BIT_MASK(__bf))) |
\
(((__val) << (bs ## __bf))
& (BIT_MASK(__bf))))
}
SET_BITS(MCDR2, MCDR2_ADDRESS,RegisterNumber);
方法D:
#define bwMCDR2_ADDRESS 4
#define bsMCDR2_ADDRESS 17
#define bmMCDR2_ADDRESS BIT_MASK(MCDR2_ADDRESS)
#define BIT_MASK(__bf)
(((1U << (bw ## __bf)) - 1)
<< (bs ## __bf))
#define SET_BITS(__dst, __bf, __val)
\
((__dst) = ((__dst) & ~(BIT_MASK(__bf)))
| \
(((__val) << (bs ## __bf))
& (BIT_MASK(__bf))))
SET_BITS(MCDR2, MCDR2_ADDRESS,
RegisterNumber);
2021-07-09 14:57
2021-07-08 14:39
2021-07-08 14:39
2021-07-08 14:27
2021-07-08 14:26
2021-07-08 14:25
2021-07-07 15:33
2021-07-07 15:32
2021-07-07 15:31
2021-07-07 15:08
2021-07-07 15:06
2021-07-06 14:23
2021-07-06 14:22
2021-07-06 14:21