spi.c

来自「EMB91SAM7S64开发板(全套资料)」· C语言 代码 · 共 55 行

C
55
字号
/*----------------------------------------------------------------------------
*         ATMEL Microcontroller Software Support  -  ROUSSET  -
*----------------------------------------------------------------------------
* The software is delivered "AS IS" without warranty or condition of any
* kind, either express, implied or statutory. This includes without
* limitation any warranty or condition with respect to merchantability or
* fitness for any particular purpose, or against the infringements of
* intellectual property rights of others.
*----------------------------------------------------------------------------
* File Name           : Board.h
* Object              : AT91SAM7S Evaluation Board Features Definition File.
*
* Creation            : JPP   16/Jun/2004
*----------------------------------------------------------------------------
*/

#include "spi.h"    

//模拟SPI接口功能传输数据

void OutByte(uchar ByteVal)
{

	uchar i;
	SPI_CLK(0);
	
	for(i=0;i<8;i++)
	{
		if(ByteVal&0x80)	SPI_MOSI(1);	
		else 				SPI_MOSI(0);
		ByteVal=ByteVal<<1;
		SPI_CLK(1);	
		SPI_CLK(0);
	}	
}

uchar InByte()
{
	uchar i,val;
	SPI_CLK(0);
	val=0;
	for(i=0;i<8;i++)
	{
		val=val<<1;
		SPI_CLK(1);
		if(SPI_MISO==1)	val=val+1;
		SPI_CLK(0);
	}
	return val;
}




⌨️ 快捷键说明

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