如何连接二进制宏值?什么是二进制类型?
How to concatenate binary macro values? What is the binary type?
从事使用二进制命令代码的 arduino 项目。
采样率和滤波器类型是两个串联的代码。
采样率 = MSB 一半,滤波器类型 = LSB 一半。
找到:Bitwise concatenation in C
#include <stdio.h>
int main() {
int first = 0b1010;
//^^v See here
int second = 0b0011;
int result = (first << 4) | second;
printf("%d", result);
return 0;
其中展示了如何连接两个二进制值并将它们相加。
将.h file
中的所有二进制代码作为宏。
我可以对纯二进制值做同样的事情吗?什么类型?
将使用串联的二进制值 - 作为函数中的命令。
Usage of binary code command currently Looks Like
所有宏:
//Sample Rate and Filter Type Codes From ADS1261 Datasheets
/*Binary Code Commands Defining Sampling Rate and Filter Type - http://www.ti.com/lit/ds/symlink/ads1261.pdf#page=61*/
//ADC DATA RATE
#define SPS_2_PT_5 0b00000 //SPS = 2.5
#define SPS_5 0b00001 //SPS = 5
#define SPS_10 0b00010 //SPS = 10
#define SPS_16_PT_6 0b00011 //SPS = 16.6
#define SPS_20_DEFAULT 0b00100 //SPS = 20 <--- this is also the default.
#define SPS_50 0b00101 //SPS = 50
#define SPS_60 0b00110 //SPS = 60
#define SPS_100 0b00111 //SPS = 100
#define SPS_400 0b01000 //SPS = 400
#define SPS_1200 0b01001 //SPS = 1200
#define SPS_2400 0b01010 //SPS = 2400
#define SPS_4800 0b01011 //SPS = 4800
#define SPS_7200 0b01100 //SPS = 7200
#define SPS_14400 0b01101 //SPS = 14400
#define SPS_19200 0b01110 //SPS = 19200
#define SPS_25600 0b00110 //SPS = 25600
#define SPS_40000 0b10000 //SPS (f_CLK - 10.24 MHz)
//Define Filter Types
#define F_SINC1 0b000 //SINC1
#define F_SINC2 0b001 //SINC2
#define F_SINC3 0b010 //SINC3
#define F_SINC4 0b011 //SINC4
#define F_FIR 0b100 //FIR// Default if not specified.
这将是完全相同的代码。宏将替换为二进制文字,文字将被提升为整数,然后左移后跟或运算符将被调用。
从事使用二进制命令代码的 arduino 项目。
采样率和滤波器类型是两个串联的代码。 采样率 = MSB 一半,滤波器类型 = LSB 一半。
找到:Bitwise concatenation in C
#include <stdio.h>
int main() {
int first = 0b1010;
//^^v See here
int second = 0b0011;
int result = (first << 4) | second;
printf("%d", result);
return 0;
其中展示了如何连接两个二进制值并将它们相加。
将.h file
中的所有二进制代码作为宏。
我可以对纯二进制值做同样的事情吗?什么类型?
将使用串联的二进制值 - 作为函数中的命令。
Usage of binary code command currently Looks Like
所有宏:
//Sample Rate and Filter Type Codes From ADS1261 Datasheets
/*Binary Code Commands Defining Sampling Rate and Filter Type - http://www.ti.com/lit/ds/symlink/ads1261.pdf#page=61*/
//ADC DATA RATE
#define SPS_2_PT_5 0b00000 //SPS = 2.5
#define SPS_5 0b00001 //SPS = 5
#define SPS_10 0b00010 //SPS = 10
#define SPS_16_PT_6 0b00011 //SPS = 16.6
#define SPS_20_DEFAULT 0b00100 //SPS = 20 <--- this is also the default.
#define SPS_50 0b00101 //SPS = 50
#define SPS_60 0b00110 //SPS = 60
#define SPS_100 0b00111 //SPS = 100
#define SPS_400 0b01000 //SPS = 400
#define SPS_1200 0b01001 //SPS = 1200
#define SPS_2400 0b01010 //SPS = 2400
#define SPS_4800 0b01011 //SPS = 4800
#define SPS_7200 0b01100 //SPS = 7200
#define SPS_14400 0b01101 //SPS = 14400
#define SPS_19200 0b01110 //SPS = 19200
#define SPS_25600 0b00110 //SPS = 25600
#define SPS_40000 0b10000 //SPS (f_CLK - 10.24 MHz)
//Define Filter Types
#define F_SINC1 0b000 //SINC1
#define F_SINC2 0b001 //SINC2
#define F_SINC3 0b010 //SINC3
#define F_SINC4 0b011 //SINC4
#define F_FIR 0b100 //FIR// Default if not specified.
这将是完全相同的代码。宏将替换为二进制文字,文字将被提升为整数,然后左移后跟或运算符将被调用。