void SPI_Write(unsigned char dig)
{
PRT2DR |= CS;
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_TX_BUFFER_EMPTY)){};
PRT2DR &= ~CS; // set slave select low
SPIM_1_SendTxData(dig); // set message to transmit
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_SPI_COMPLETE)){};
PRT2DR |= CS; //
}
unsigned char SPI_Read(void)
{
unsigned char ReceivedData;
PRT2DR |= CS;
PRT2DR &= ~CS;
SPIM_1_SendTxData(0x00); // 写伪数据,以便读到数据
while(!(SPIM_1_bReadStatus() & SPIM_1_SPIM_RX_BUFFER_FULL));//RX Buffer register has received current data
ReceivedData = SPIM_1_bReadRxData();
PRT2DR |= CS;
return ReceivedData;
} |