对不起...
我刚刚找到了 shiftOut() 函数的实现:
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
uint8_t i;
digitalWrite(clockPin, LOW);
for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}
目前我只想支持 MSBFIRST,所以我的功能看起来像......
#define GPIO0_WRITE(Pin,Value) if ( Value == 0 ) { LPC_GPIO0->FIOCLR|= ( 1 << Pin); } else { LPC_GPIO0->FIOSET |= ( 1 << Pin); }
GPIO0_WRITE(CLOCK_PIN, LOW);
for (i = 0; i < 8; i++)
{
GPIO0_WRITE(DATA_PIN, !!(CMD_TEMPERATURE & (1 << (7 - i))));
GPIO0_WRITE(CLOCK_PIN,HIGH);
GPIO0_WRITE(CLOCK_PIN,LOW);
}
欢迎任何建议。