spi.c

来自「SPI 8051 自己写的,有什么问题请大家多多指教啊」· C语言 代码 · 共 89 行

C
89
字号
#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 + =
减小字号Ctrl + -
显示快捷键?