/***
Software SPI
Note: Maximum SPI frequency is 2MHz. Typical frequency achived by function below
is 1,5MHz with a Xmega AVR at 32MHz systemclock. If using other systems, possibly
you have to insert delays, to slow down SPI frequency.
***/
uint8_t _SPI_RW (uint8_t output)
{
uint8_t input=0;
uint8_t i;
for (i=0; i<8; i++)
{
DISPLAY_SPI_PORT &= ~(1<<DISPLAY_SPI_SCK); // SCK low
if (output & 0x80)
DISPLAY_SPI_PORT |= 1<<DISPLAY_SPI_MOSI; // MOSI high
else
DISPLAY_SPI_PORT &= ~(1<<DISPLAY_SPI_MOSI); // MOSI low
DISPLAY_SPI_PORT |= 1<<DISPLAY_SPI_SCK; // SCK high
input <<= 1; // Input MISO
if (DISPLAY_SPI_INPORT & (1<<DISPLAY_SPI_MISO))
input |= 1;
else
input &= ~1;
output <<= 1;
}
return input; //return the byte clocked in from SPI slave
}