小编Cal*_*nes的帖子

功能相同的代码,结果不同

我有2段代码,它们执行的功能完全相同,但是实际上并没有用。谁能解释为什么?

该代码通过spi将数据发送到运行显示器的FPGA。我几乎没有足够的代码存储在芯片上,因此我正在尝试尽可能地减少代码。下面的更改由于某种原因而最终中断,该程序的其余部分与之完全相同。

//Looping to execute code twice doesnt work
for (byte i = 0; i < 3; i++)
      {
        temp2 = temp % 10;
        temp /= 10;
        temp2 |= 0x40;
        for (byte k = 0; k < 2; k++)
        {
          SPI.transfer(reg[j]);
          delayMicroseconds(10);
          SPI.transfer(temp2);
          delayMicroseconds(10);
        }
        reg[j] -= 1;
      }
Run Code Online (Sandbox Code Playgroud)

//But copy-paste does
for (int i = 0; i < 3; i++)
          {
            temp2 = temp % 10;
            temp /= 10;
            temp2 |= 0x40;
            SPI.transfer(reg[j]);
            delayMicroseconds(10);
            SPI.transfer(temp2);
            delayMicroseconds(10);
            SPI.transfer(reg[j]);
            delayMicroseconds(10); …
Run Code Online (Sandbox Code Playgroud)

c++ arduino arduino-uno

5
推荐指数
1
解决办法
143
查看次数

标签 统计

arduino ×1

arduino-uno ×1

c++ ×1