0

The original code works fine, it is :

for(i = 0; i < 8; i++){
  while(readPortAPin1() == BAIXO);
  writePortAPin2(value & 0x01);
  value >>= 1;
  while(readPortAPin1() == ALTO);
}

In the first code, if value = 10101010 it will be sent as 01010101. I would like to change the order of transmission, for example, if value = 10101010, I woul like to transmit 10101010.

To implement this, I did the following code:

for(i = 0; i < 8; i++){
  while(readPortAPin1() == BAIXO);
  writePortAPin2(value & 0x80);
  value <<= 1;
  while(readPortAPin1() == ALTO);
}

But, it is not working, it is transmiting all 0s. Am I doing something wrong ?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Daniel
  • 107
  • 6

1 Answers1

1

Apparently writePortAPin2() writes the least significant bit of the operand. You need to write the most significant bit of value

Change this

writePortAPin2(value & 0x80);

to this

writePortAPin2((value >> 7) & 0x01);
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243