void SPI_SEND_ONE_DATA(uchar i) //SPI发一个字节
{
uchar loop;
uint delay;
uchar temp;
temp = 0x80;
for(loop = 0; loop < 8; loop++)
{
if((i & (temp >> loop)))
DIN_1;
else
DIN_0;
for(delay = 10;delay > 0; delay--);
SCLK_1;
for(delay = 50;delay > 0; delay--);
SCLK_0;
for(delay = 50;delay > 0; delay--);
}
// for(delay = 50;delay> 0; delay--);
}
uchar SPI_READ_ONE_DATA(void) //SPI收一个字节
{
uchar loop;
uint delay;
uchar temp;
uchar i;
i = 0x00;
for(loop = 0; loop < 8; loop++)
{
i = i << 1;
SCLK_1;
for(delay = 50; delay > 0; delay--);
temp = P1IN;
if((temp & 0x08))
i |= 0x01;
SCLK_0;
for(delay = 50;delay > 0; delay--);
}
// for(delay = 50;delay > 0; delay--);
return i;
}
|