我正在尝试shiftOut()在我的 mcu 上的原生 c 中创建等效的 arduino函数。
我想int gTempCmd = 0b00000011;通过shiftOut()带有MSBFIRST.
这个伪代码看起来像什么,所以我可以尝试将它映射到我的 mcu 的 gpio 功能?
谢谢
float readTemperatureRaw()
{
int val;
// Command to send to the SHT1x to request Temperature
int gTempCmd = 0b00000011;
sendCommandSHT(gTempCmd);
...
return (val);
}
//Send Command to sensor
void sendCommandSHT(int command)
{
int ack;
shiftOut(dataPin, clockPin, MSBFIRST, command);
....
}
Run Code Online (Sandbox Code Playgroud)
考虑以下“psuedo-c++”
代码的工作原理如下:
通过添加重复次数参数将其扩展为任意位数(最多 32 位)是相当简单的
void shiftOut(GPIO dataPin, GPIO clockPin, bool MSBFIRST, uint8_t command)
{
for (int i = 0; i < 8; i++)
{
bool output = false;
if (MSBFIRST)
{
output = command & 0b10000000;
command = command << 1;
}
else
{
output = command & 0b00000001;
command = command >> 1;
}
writePin(dataPin, output);
writePin(clockPin, true);
sleep(1)
writePin(clockPin, false);
sleep(1)
}
}
Run Code Online (Sandbox Code Playgroud)