📄 spi._c
字号:
#include <iom64v.h> // change to the appropriate header file
#include "spi.h"
/* spi_init function should be generated using the AppBuilder
*/
/*
** SpiWriteByte() writes a byte to the SPI and waits until
** it has been transmitted. This function doesn't
** return any value back.
*/
void SpiWriteByte(unsigned char byte)
{
SPDR = byte;
while (!(SPSR & 0x80));
byte = SPDR;
}
/*
** SpiReadByte() first writes a byte (a dummy, since
** that byte is to generate clock signals to "poll" home
** the byte from the slave. The function returns the
** received byte.
*/
unsigned char SpiReadByte(void)
{
SPDR = 0x00;
while (!(SPSR & 0x80));
return SPDR;
}
/*
** SpiReadDataReg() reads the last byte in the SPI register
** without any clock signals generated. Could be used
** as reading the last byte received.
*/
unsigned char SpiReadDataReg(void)
{
return SPDR;
}
main()
{
SpiReadDataReg();
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -