上升沿写,下降沿读
SPI写时序
void SPI_write(unsigned char dat)
{
unsigned char temp;
for(temp=0x80;temp!=0;temp>>=1)
{
SCK=0;
if(temp&dat==0)
{
MOSI=0;
}
else
{
MOSI=1;
}
SPI_delay(); //让MOSI稳定
SCK=1;
}
}
SPI读时序
unsigned char SPI_read(void)
{
unsigned char temp;
unsigned char dat;
for(temp=0x80;temp!=0;temp>>=1)
{
SCK=1;
SPI_delay(); //让SCK稳定
SCK=0;
if(MISO==1)
{
dat|=temp;
}
else
{
dat&=~temp;
}
}
return dat;
}