📄 spi.c
字号:
#include <AT89X55.H>
#include <SPI.h>
/*
***********************************************************************************************
* Read Back One Byte From SPI Interface
*
Description: Read Back One Byte From SPI Interface
*
* Arguments : none
*
* Returns : a 1-byte data sent to SPI interface
*
* Notes :1) LSB first input
***********************************************************************************************
*/
unsigned char SPI_ReadOneByte(void)
{
bit bData;
unsigned char cLoop;
unsigned char cData;
for(cLoop=0;cLoop< 8;cLoop++)
{
SPI_SCK = 0;
cData >>= 1;
SPI_SO = 1;
bData = SPI_SO;
if(bData){
cData |=0x80;
}
SPI_SCK = 1;
}
return cData;
}
/*
***********************************************************************************************
* Write One Byte To SPI Interface
*
* Description: Write One Byte To SPI Interface
*
* Arguments : byteData is a 1-byte data sent to SPI interface
*
* Returns : none
*
* Notes :1) LSB first output
***********************************************************************************************
*/
void SPI_WriteOneByte(unsigned char cData)
{
unsigned char cLoop;
for(cLoop=0; cLoop<8;cLoop++)
{
SPI_SCK = 0;
if((cData&0x01)==0)
{
SPI_SI = 0;
}
else
{
SPI_SI = 1;
}
SPI_SCK = 1;
cData >>= 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -