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

📄 s12_spi.c

📁 source code for a sample alarm control panel system using Freescale MC9S12DP256 . The project was im
💻 C
字号:
//=============================================================================
// File: S12_SPI.C - V1.00
// Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd
//=============================================================================

//-- Includes -----------------------------------------------------------------

#include "datatypes.h"
#include "hcs12dp256.h"
#include "s12_spi.h"

//-- Code ---------------------------------------------------------------------

void initSPI0(UINT8 bauddiv, UINT8 cpol, UINT8 cpha) {

	DDRS |= 0xe0;						// SS,SCK,MOSI Output
	SPI0BR = bauddiv;					// set SPI Rate
	// enable SPI, Master Mode, select clock polarity/phase
	SPI0CR1 = BM_SPE | BM_MSTR | (cpol ? BM_CPOL : 0) | (cpha ? BM_CPHA : 0);
	SPI0CR2 = 0;						// as default
	}

//-----------------------------------------------------------------------------

UINT8 xferSPI0(UINT8 abyte) {

	SPI0DR = abyte;						// start transfer
	while((SPI0SR & BM_SPIF) == 0) ;	// wait until transfer finished
	return(SPI0DR);						// read back data received
	}

//=============================================================================

⌨️ 快捷键说明

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