here's some snippets from my code base that might help:
// PGA volume control chip
#ifdef USE_PGA
#define PGA_CS_PIN 12
#define PGA_SDATA_PIN 11
#define PGA_SCK_PIN 10
#endif
...
void
PGA_set_volume(byte left, byte right)
{
byte shifted_val = (left << 1); // right is the same (we assume that, anyway)
digitalWrite(PGA_CS_PIN, LOW); // assert CS
SPI_write(shifted_val); // right value (0..255)
SPI_write(shifted_val); // right value (0..255)
digitalWrite(PGA_CS_PIN, HIGH); // deassert CS
}
...
static inline void
SPI_write(byte out_spi_byte)
{
byte i;
// loop thru each of the 8-bits in the byte
for (i=0; i < 8; i++) {
// strobe clock
digitalWrite(PGA_SCK_PIN, LOW);
// send the bit (we look at the high order bit and 'print' that to the remtoe device)
if (0x80 & out_spi_byte) // MSB is set
digitalWrite(PGA_SDATA_PIN, HIGH);
else
digitalWrite(PGA_SDATA_PIN, LOW);
// unstrobe the clock 
digitalWrite(PGA_SCK_PIN, HIGH);
out_spi_byte <<= 1; // left-shift the byte by 1 bit (
}
}