Hi,
I am currently working with bit banging an SPI protocol using a PIC16F690 and a Nokia 5110 LCD module. I've been using some adapted code from Microchip's library, but it is pretty slow.
I know I can speed it up a little by not having spi_wr call the spi_bit_out function and put that function into spr_wr, but it's still pretty slow.
Bassically, everytime spi_bit_out is called, the register is rotated 7 times to get the MSB, is there a quicker and less costly way of doing this.
As 'data' in the bit_out function is an unsigned char, could I simply subtract 127 from it and leave myself with either 1 or 0 in the data register?
It currently takes about 0.4s to clear the screen on my Nokia 5110 LCD module running at 4MHz. I need to get a quicker routine, as I want to play around with a 1.8" 128x160 colour TTF module. This needs 2 bytes sent to it for every pixel whereas the Nokia 5110 module uses a bit for each pixel.
I am currently working with bit banging an SPI protocol using a PIC16F690 and a Nokia 5110 LCD module. I've been using some adapted code from Microchip's library, but it is pretty slow.
Rich (BB code):
void spi_bit_out(unsigned char data){
SDAT = (data>>7); // output the MSB
SCLK = 1; // clock high
short_delay(); // 2uS delay
SCLK = 0; // clock low
}
//....................................................................
// Writes a byte to the SPI bus
//....................................................................
void spi_wr(unsigned char data, unsigned char com_data)
{
unsigned char i; // loop counter
DC = com_data; // set the data/command pin
for (i = 0; i < 8; i++) // loop through each bit
{
spi_bit_out(data); // output bit
data = data << 1; // shift left for next bit
}
}
Bassically, everytime spi_bit_out is called, the register is rotated 7 times to get the MSB, is there a quicker and less costly way of doing this.
As 'data' in the bit_out function is an unsigned char, could I simply subtract 127 from it and leave myself with either 1 or 0 in the data register?
It currently takes about 0.4s to clear the screen on my Nokia 5110 LCD module running at 4MHz. I need to get a quicker routine, as I want to play around with a 1.8" 128x160 colour TTF module. This needs 2 bytes sent to it for every pixel whereas the Nokia 5110 module uses a bit for each pixel.