unsigned int SPI_WriteByte(unsigned int val)
{
unsigned int ret;
SPI0DAT = val;
while(!SPIF);
SPIF = 0;
ret = SPI0DAT;
return ret;
}
unsigned int SPI_ReadByte(void)
{
unsigned int ret;
SPI0DAT = 0xff; // Dummy write to output serial clock
while (!SPIF); // Wait for the value to be read
SPIF = 0;
ret = SPI0DAT;
return ret;