AVR的SPI程序
#define SPI_RX_BUFFER_SIZE 10
#define SPI_RX_BUFFER_MASK ( SPI_RX_BUFFER_SIZE - 1 )
#define SPI_TX_BUFFER_SIZE 10
#define SPI_TX_BUFFER_MASK ( SPI_TX_BUFFER_SIZE - 1 )
#define SET_SPI_MODE PORTB.4
#define SPI_MODE PINB.4
static unsigned char SPI_RxBuf[SPI_RX_BUFFER_SIZE];
static volatile unsigned char SPI_RxHead;
static unsigned char SPI_TxBuf[SPI_TX_BUFFER_SIZE];
static volatile unsigned char SPI_TxHead;
//******************************************
// SPI 中斷服務(wù)程序
//******************************************
interrupt [SPI_STC] void spi_isr(void)
{
unsigned char data;
if(spi_m==0)
{
}
else
}
//******************************************
// SPI 初始化
//******************************************
void InitSPI(void)
{
SPCR=0x52;
SPI_RxHead = 0;
SPI_TxHead = 0;
}
//******************************************
//發(fā)送數(shù)據(jù)
//******************************************
void spi_send(void)
{
if(spi_sending==0)
}
void main(void)
{
...
while(1)
{
}
}
評論