⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi.c

📁 智能水表程序 来着互联网
💻 C
字号:
//-----------------------------------------------------------------------------
// spi.c
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <reg52.h>
#include <intrins.h>
#include "cpu/cpu.h"
#include "misc/general.h"
//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
void spi_Write_Byte ( char dat );
char spi_Read_Byte  ( void );
//------------------------------------------------------------------------------------
// spi Write Byte Routine
//------------------------------------------------------------------------------------
void spi_Write_Byte ( char dat )
{
    char nBit = 8;

	do {   
	    spi_CLK = LOW;
	    if ( MSB & dat )
			spi_SI = HIGH;
	    else
			spi_SI = LOW;
   		spi_CLK = HIGH;
		dat <<= 1;
	} while ( --nBit );
	spi_SI = LOW;
}
//------------------------------------------------------------------------------------
// spi Read Byte Routine
//------------------------------------------------------------------------------------
char spi_Read_Byte ( void )
{
    char nBit = 8;	
	char dat = 0;
 
    do {   
		spi_CLK = HIGH;
	   	spi_CLK = LOW;
		dat <<= 1;
		if ( spi_SO )	dat |= LSB;
	} while ( --nBit );
    return dat;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -