void SPI_Configuration(void)
{
P15_Quasi_Mode; // P15 (SS) Quasi mode
P10_Quasi_Mode; // P10(SPCLK) Quasi mode
P00_Quasi_Mode; // P00 (MOSI) Quasi mode
P01_Quasi_Mode; // P22 (MISO) Quasi mode
set_DISMODF; // SPI 禁止模式错误检测
clr_SSOE; // 从机选择输出使能位0 = ss作为普通 I/O.
clr_LSBFE; // MSB first 0 = SPI优先传输最高位MSB数据
clr_CPOL; // The SPI clock is low in idle mode
set_CPHA; // The data is sample on the second edge of SPI clock
set_MSTR; // SPI in Master mode
SPICLK_DIV16; // Select SPI clock
set_SPIEN; // Enable SPI function
clr_SPIF;
}
/*******************************************************************************
** Function name: SPI_SendByte
**
** Descriptions : SPI发送一个字节
**
*******************************************************************************/
void SPI_SendByte(UINT8 ch)
{
//SPSR –SPI 状态寄存器
while((SPSR & SET_BIT2) != 0);//有数据待发送或是读取
//SPDR – SPI数据寄存器
SPDR = ch;
Timer0_Delay10us(1);
while(!(SPSR & SET_BIT7));
clr_SPIF;
}
/*******************************************************************************
** Function name: SPI_ReadByte
**
** Descriptions : SPI读取一个字节
**
*******************************************************************************/
uint8_t SPI_WrRdByte(uint8_t byte)
{
while((SPSR & SET_BIT2) != 0);
SPDR = byte;
while(!(SPSR & SET_BIT7));
clr_SPIF;
byte = SPDR;
return byte;
}现在的配置是这样子
|