SparkFun's Nokia knock-off uses a 9 bit serial word. I looked at code examples for this and it just didn't make sense to use built-in SPI features to send 8 bits then change the port to a logic port and bit bang out 1 bit. So here's the bit bang C function I used to send the 9 bit serial word.
Code:
void sdata9 (unsigned int dat9) // dat9 is 9bits sent MSB first
{
unsigned char i;
unsigned int mag = 256; // mag=(256,128,64,32,16,8,4,2,1)
for (i=9; i>0; i--) // count bits 9 to 1
{
SCLK=0; // serial clock pin low
if (dat9 >= mag) // is dat9 greater than mag?
{
dat9 = dat9-mag; // if yes subtract mag
SDATA=1; // if yes data output pin high
}
else SDATA=0; // if no data output pin low
mag = mag>>1; // divide by 2, next magnitude
SCLK=1; // serial clock pin high
} // loop back for next bit
}
Example:
Send display "common scan" 80 to 1 and 160 to 81.
Command is a 0 and Data is a 1. Same as A0 bit.
sdata9(0x0BB); // send display Comand BB
sdata9(0x103); // send display Data 03
C doesn't make the most perfect timing signals. Here's the same thing with a do nothing operation to add a few dozen nSec to make sure timing is at least double the minimum spec of the display when clocking at 50 MIPS.
Code:
void sdata9 (unsigned int dat9)
{
unsigned char nop;
unsigned char i;
unsigned int mag = 256;
nop = nop>>1; // NOP do nothing but waist time !
for (i=9; i>0; i--)
{
SCLK=0;
if (dat9 >= mag)
{
dat9 = dat9-mag;
SDATA=1;
}
else SDATA=0;
mag = mag>>1;
SCLK=1;
nop = nop<<1; // NOP do nothing but waist time !
}
}