Re: send out ascii characters to bit stream using a GPIO pin
Posted: Tue Oct 10, 2017 5:16 pm
That code sends 7 bits, MSB first.
-->
Open Community Forum for ESP8266, Come share Arduino and IoT (Internet of Things)
https://www.esp8266.com/
tele_player wrote:That code sends 7 bits, MSB first.
b <<= 1;
for (int i = 0; i < 7; i++) { /// MODIFIED FOR 7 BITS ONLY ///
digitalWrite(m_txPin, (b & 0x40) ? HIGH : LOW); /// check the MSB each time and then serialize to m_txPin ///
WAIT;
b <<= 1; // it is doing right shift
}
tele_player wrote:No, you are incorrect.
For this discussion, think of bits in an 8-bit byte numbered b7 to b0, b7 is high bit.
My code uses 0x40 to select b6, loops 7 times, shifting left after sending each bit.
So, it sends b6-b5-b4-b3-b2-b1-b0.
digitalWrite(m_txPin, (b & 0x40) ? HIGH : LOW)