
/***********************************************************************
DESC:    Writes a byte to the SPI bus. spi_init must be called first
RETURNS: Nothing
************************************************************************/
void spi_write
  (
  unsigned char dat    // byte to write
  )
{
  // wait for previous transfer to complete
  while (mspibusy);

  // SPI now busy
  mspibusy = 1;

  // write data to SPI bus
  SPDAT = dat;
} // spi_write

/***********************************************************************
DESC:    Initializes the SPI peripheral
         SPI Clock frequency = 93.75 kHz
         Set EA to 1 after calling
RETURNS: Nothing
************************************************************************/
void spi_init
  (
  void
  )
{
  // set MOSI, MISO, /SS and SPICLK as quasi-bidirectional
  P2M1 &= 0xC3;
  P2M2 &= 0xC3;
....