What protocol should I be using - LCD display

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks,

I've got an LCD that I salvaged from a cell phone. It's working but I'm bit-banging all the communications and it was pointed out to me that this might work better if I use hardware based communications.

Below you will find the code I use to write to the display. From the datasheet for the controller chip I know there are three logic connections: SCL, SIO, and CS. The CS pin is used to tell the controller to interpret the data as a command.

I don't think this is I2C or SPI but then again I don't really know. Can anyone give me a shove in the right direction? Thanks!

void LCD_Out(unsigned char Data, unsigned char isCmd) {
	if(isCmd) LCD_PORT |= LCD_CS;  
	LCD_PORT &= ~(LCD_CLK|LCD_CS);  //Clock and CS low

	LCD_PORT |= LCD_SIO;		//SData High
	if(isCmd) LCD_PORT &= ~LCD_SIO; //If it is a command, SData Low

	LCD_PORT |= LCD_CLK;		//Clock High

	for(char x=0; x<8; x++)	{
		LCD_PORT &= ~(LCD_SIO|LCD_CLK);		//Clock and SData low
		if(Data & 128) LCD_PORT |= LCD_SIO;  	// Mask MSB - SData high if it is a 1
		LCD_PORT |= LCD_CLK;			//Clock High
		Data=Data<<1;				//Shift bits 1 left (new MSB to be read)
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well the actual data shift portion is simple SPI, but the rest is not.

Your handling for cmd/data at the top seems confusing. As you only seem to pulse CS for a brief moment. (~1 cycle of the CPU clock) And then you seem to affect the state of the data line based on if it is a command or not.

Perhaps a timing diagram of what it is you are trying to create would be of help here.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The controller chip is an S1D15G14. I am using a 9-bit interface and have attached the timing diagram from the datasheet.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This looks like good ole SPI to me, maybe inverted clock phase, it's usually configurable in the micro anyways.

EDIT: Hmm actually it looks like a combination of SPI and I2C. Protocol uses a chip select line like SPI, but ALSO a read/write bit like I2C. If you can somehow configure the AVR's SPI port to work in 9-bits mode, it should work fine. I think the internal shifter is only 8-bits wide though....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, so CS has NOTHING to do with command or data, as you described above. CS is the chip select. What you have is a 9-bit SPI. Unfortunately the AVR's SPI hardware does not do a 9 bit mode. You could try hacking some hybrid code together that bit-bangs out the D/C bit, and then uses SPI to transfer the rest.

Given the timing diagrams above, the following line in your previous code is meaningless.

 if(isCmd) LCD_PORT |= LCD_CS; 

Note that you should break the CS control out of the write/read functions, so that you can transfer more than one byte at a time, when appropriate.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

UNiXWHoRe wrote:

EDIT: Hmm actually it looks like a combination of SPI and I2C. Protocol uses a chip select line like SPI, but ALSO a read/write bit like I2C. If you can somehow configure the AVR's SPI port to work in 9-bits mode, it should work fine. I think the internal shifter is only 8-bits wide though....

What read/write bit? There is a data/command bit, but no read/write bit as far as I can tell. It is the command itself that determines if the rest of the operation is a read or write. It is a pure 9-bit SPI interface.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looked up the data sheet... note that there is an 8 bit serial mode, in which case the A0 pin is used for the DC bit, allowing you to use the AVR's SPI hardware directly. (not sure if this signal is available for you on your display, but if it is, use it, it would simplify your code greatly.)

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the help. Unfortunately I don't have access to the A0 input so I must use 9-bit SPI.

Thanks for pointing out the problems with my code. I wrote it quite a while ago and am just getting back into it to make it better.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

glitch wrote:
UNiXWHoRe wrote:

EDIT: Hmm actually it looks like a combination of SPI and I2C. Protocol uses a chip select line like SPI, but ALSO a read/write bit like I2C. If you can somehow configure the AVR's SPI port to work in 9-bits mode, it should work fine. I think the internal shifter is only 8-bits wide though....

What read/write bit? There is a data/command bit, but no read/write bit as far as I can tell. It is the command itself that determines if the rest of the operation is a read or write. It is a pure 9-bit SPI interface.

My bad, I'm not really used to playing with character LCD's... :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

UNiXWHoRe wrote:
My bad, I'm not really used to playing with character LCD's... :)

?? this is a graphic LCD/controller, not a character one.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah I didn't read the datasheet, you caught me...