找回密码
 注册
搜索
查看: 829|回复: 0

[MCU资料] 请问应该如何读IO口中的数据?

[复制链接]
发表于 2007-12-7 10:45:14 | 显示全部楼层 |阅读模式
我在利用IO口模拟SPI通信时,出现读IO口的问题,希望高人指点!
#define MOSI P0^0
#define MISO P0^1
#define XCS P0^2
#define SCK P0^3
byte SPITransfer(byte ByteIn)
{
byte i;
byte ByteOut;
for (i = 0; i < 8; i++)
{
  ByteOut <<= 1;
  SCK = 0x00;
  MOSI = ByteIn & 0x01;            // put current outgoing bit on MOSI
  ByteOut |= MISO & 0x01;        // capture current bit on MISO
  SCK = 0x01;                             // set SCK high
  ByteIn >>= 1;                            // shift next bit into LSB
}
return (ByteOut);
}
其中语句ByteOut |= MISO & 0x01; 换为ByteOut |= MISO; 或是bit  tmp = (bit)MISO ; ByteOut |= tmp;得到的结果不对,请问这是什么原因?IO口中的数据是什么呢?为什么ByteOut |= MISO & 0x01这样就有效呢?谢谢指教!!!
高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-10-7 13:14 , Processed in 0.067721 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表