/////////////////////////读写操作/////////////////////////////////////
uchar SPI_RW(uchar byte)
{
uchar bit_ctr;
PORT &=~(BIT(CLK));
for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
{
if(byte & 0x80)
PORT |= BIT(MOSI);
else
{
PORT &= ~(BIT(MOSI)); // output 'byte', MSB to MOSI
}
byte = (byte << 1); // shift next bit into MSB..
PORT |=BIT(CLK); // Set clk high..
if(PIN&(BIT(MISO)))
byte |= BIT0; // capture current MISO bit
else
{
byte &=~BIT0;
}
PORT &=~BIT(CLK); // set clk low
}
PORT &=~(BIT(MOSI)); //PULL DOWN THE MOSI
return(byte); // return read byte
}
为什么还要把MISO读取出来啊???
此帖出自
小平头技术问答
一周热门 更多>