?? spi.c
字號:
/*= spi.c =====================================================================
*
* Written by Greg Hunter, University of Technology, Sydney, 2007 for sdcc compiler
* See spi.h for details
*
*==============================================================================
*/
#include "regs24e1.h"
#include "spi.h"
//********************************************************
// SpiRadio
// Initialise spi bus for radio
//********************************************************
void SpiRadio(void)
{
SPICLK = 0; // Max SPI clock (XTAL/8)
P0_DIR &= ~0x20; // Set P0.5 as output
P0 |= 0x20; // Set P0.5 high to disable spi netburner chip select
SPI_CTRL = 0x02; // Connect internal SPI controller to Radio
}
//********************************************************
// SpiReadWrite
// Read and write byte on spi bus
//********************************************************
unsigned char SpiReadWrite(unsigned char b)
{
//Clear SPI interrupt
EXIF &= ~0x20;
//Move byte to send to SPI data register
SPI_DATA = b;
//Wait until SPI hs finished transmitting
while((EXIF & 0x20) == 0x00) ;
//return data read
return SPI_DATA;
}
//********************************************************
// SpiReadBuf
// Read to a buffer from the spi bus
// Usage:
// SpiReadBuf(&RXbuf,n);
// where n is the number of bytes to be read from the spi bus
//********************************************************
void SpiReadBuf(unsigned char* buf, unsigned char n)
{
unsigned char i;
for (i=0;i<n;i++)
{
*buf = SpiReadWrite(0);
buf++;
}
}
//********************************************************
// SpiWriteBuf
// Write to a buffer from the spi bus
// Usage:
// SpiWriteBuf(&TXbuf,n);
// where n is the number of bytes to be written to the spi bus
//********************************************************
void SpiWriteBuf(unsigned char* buf, unsigned char n)
{
unsigned char i;
for (i=0;i<n;i++)
{
SpiReadWrite(*buf);
buf++;
}
}
//********************************************************
// SpiReadWriteBuf
// read and write to and from a buffer from the spi bus
// Usage:
// SpiReadWriteBuf(&TXbuf,&RXbuf,n);
// where n is the number of bytes to be read from and written to the spi bus
//********************************************************
void SpiReadWriteBuf(unsigned char* TXbuf, unsigned char* RXbuf, unsigned char n)
{
unsigned char i;
for (i=0;i<n;i++)
{
*RXbuf = SpiReadWrite(*TXbuf);
RXbuf++;
TXbuf++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -