?? spi.c
字號:
/****************************************Copyright (c)**************************************************
**--------------File Info-------------------------------------------------------------------------------
** File name: SPI.C
** Last modified Date:2007-12-20
** Last Version: 1.0
** Descriptions: SPI數據操作
**------------------------------------------------------------------------------------------------------
** Created by: Rein Lee
** Created date: 2007-12-20
** Version: 1.0
** Descriptions: The original version
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
********************************************************************************************************/
#include "config.h"
#define HC595_CS 1<<24 /*P0.24口為74HC595的片選*/
/*********************************************************************************************************
** 函數名稱: MSpiIni()
** 功能描述: 初始化SPI接口,設置為主
** 輸 入: 無
** 輸 出: 無
** 全局變量: 無
** 調用模塊: 無
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void MSpiIni(void)
{
PINSEL1 &= ~(3 << (2 * (24 - 16))); //P0.23 CS
PINSEL1 = (PINSEL1 & (~0xcc)) | 0x88; // 不影響其它管腳連接,設置I/O連接到I2C
IO0DIR |= HC595_CS;
S1PCCR=0x52; //設置SPI時鐘分頻
S1PCR=0x30; //設置SPI接口模式,MSTR=1,CPOL=1,CPHA=0,LSBF=0
}
/*********************************************************************************************************
** 函數名稱: MSendData()
** 功能描述: 向SPI總線發送數據
** 輸 入: 待發送的數據
** 輸 出: 返回發送的數據
** 全局變量: 無
** 調用模塊: 無
**------------------------------------------------------------------------------------------------------
** Created by Rein Lee
** Created date: 2007-12-20
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 MSendData(uint8 data)
{ IO0CLR=HC595_CS; //片選
S1PDR=data;
while(0==(S1PSR&0x80)); //等待SPIF置位,即等待數據發送完畢
IO0SET=HC595_CS;
return(S1PDR);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -