Help porting Graphic LCD code

25 Sep 2014

I need some help porting test code for a graphic LCD into mbed. The display is like this one and are also available through CrystalFontz.

http://www.ebay.com/itm/2-1-128x64-Graphic-LCD-Module-Parallel-Serial-SPI-SPLC501-Black-White-Arduino-/301052582832?pt=LH_DefaultDomain_0&hash=item461821dbb0

I have it setup as 8-bit parallel. I am using the same pins as the text LCD that also runs on 8-bit parallel. My pinout is:

TextLCD lcd(p21, p22, p23, p24, p25, p26, p30, 8, 2); (rs, rw, e, d0, d1, d2, d3, n_column, n_rows).

The manufacturer published some test code to display some characters and pictures.

http://www.buydisplay.com/download/democode/ERC12864-12.1_DemoCode_8bit_8080.txt

Looking at the code I Have modified the pin definition to match mine. I can not get this to compile without lots and lots of errors.

I would appreciate anyone that can help. I did not see this chip listed in the cookbook or I would have started there.

Thanks in Advance.

25 Sep 2014

Oh, Forgot to mention. I have to drive this in parallel mode. I have already used up 2X SPI and 2X serial ports on the device. I am running out of room.

25 Sep 2014

Well it seems this will not work. I just realized my previous display was running in 4-bit mode. Not 8-bit. I have to figure out where to get those extra 4 pins from. I guess I could use the digital I/O pins. Would that work? Any example code?

26 Sep 2014

Hi James,

A couple of thoughts that may be helpful - mostly focused on the SPI interface to reduce the pin-count.

  1. If your SPI peripherals each have a chip-select, then you can certainly hang more than one item on each SPI bus. The driver for each peripheral would have to take care that the SPI bus wasn't already 'busy' - a simple semaphore would likely work.
  2. You can also bit-bang SPI on discrete IO pins, that's pretty simple, and is shown in this version of the demo. Just define a couple of DigitalOut and I think this was a 'write-only' display, so you don't need a DigitalIn.
26 Sep 2014

Thank you David.

Are there any examples for bit-bang SPI on IO pins for mbed?

Could I use pins 21-26 for this? I have never set up something like this and do not know enough background code to start from scratch.

27 Sep 2014

test - ignore

27 Sep 2014

Hi James, the link "this version" is to the generic code on buydisplay.com. That code has a bit-bang SPI driver in it. Here's the pieces of interest from that link:

#define CS1                    P3_5
#define RS                     P3_3
sbit SDA=P1^7;
sbit SCK=P1^6;

#pragma disable
void Write_Data(unsigned char dat)
{
    unsigned char idata i;
    RS=1;
	SCK=0;
	CS1=0;
	Delay(10);
	for(i=0;i<8;i++)
	{
	    SCK=0;
		_nop_();
		_nop_();
		SDA=dat&0x80;
		dat=dat<<1;
		_nop_();
		_nop_();
		SCK=1;
		_nop_();
		_nop_();
	}
	CS1=1;
	Delay(5);
	return;
}


#pragma disable
void Write_Instruction(unsigned char idata cmd)
{
    unsigned char idata i;
    RS=0;
	SCK=0;
	CS1=0;
	Delay(10);
	for(i=0;i<8;i++)
	{
	    SCK=0;
		_nop_();
		_nop_();
		SDA=cmd&0x80;
		cmd=cmd<<1;
		_nop_();
		_nop_();
		SCK=1;
		_nop_();
		_nop_();
	}
	CS1=1;
	Delay(5);
	return;
}

Here's my quick translation to the mbed code - but I didn't compile this, so it might need a little more change to make it work. You'll need to map the right p21-p24 pins for instance. Also, the _nop_() are intended to create a very small delay. I don't know if that is truly needed, but for the mbed delay_us() could be used - you might try some different values in the range of 1 to 100.

DigitalOut CS1(p21);         // #define CS1                    P3_5
DigitalOut RS(p22);           //#define RS                     P3_3
DigitalOut DSA(p23);         // sbit SDA=P1^7;
DigitalOut SCK(p24);         // sbit SCK=P1^6;

// #pragma disable
void Write_Data(unsigned char dat)
{
    unsigned char i;  //    unsigned char idata i;
    RS=1;
	SCK=0;
	CS1=0;
	delay_ms(10);      // Delay(10);
	for(i=0;i<8;i++)
	{
	    SCK=0;
		delay_us(10);   // _nop_();
		// _nop_();
		SDA=dat&0x80;
		dat=dat<<1;
		delay_us(10);   // _nop_();
		// _nop_();
		SCK=1;
		delay_us(10);   // _nop_();
		// _nop_();
	}
	CS1=1;
	delay_ms(5);         // Delay(5);
	return;
}

Make the same changes to the Write_Instruction().

Hopefully this will get you close enough to see something happen and take it from there.

29 Sep 2014

Hi James, The ERC12864 has a IC driver NT7538, should be compatible with SR7565. I use a EA DOGL128W-6 (same SR7565), with ONE single SPI shared with a SD card.
Some very useful links I used:
http://edeca.net/wp/electronics/the-st7565-display-controller/
http://mbed.org/users/dreschpe/code/C12832_lcd/
https://mbed.org/users/igorsk/notebook/dogl128-lcd-module/
http://mbed.org/users/tonydbeck/code/gLCD/
http://mbed.org/handbook/SDFileSystem for the SD card and some comments from Chan
The constructor of the SPI object is within the SD software and the LCD uses a pointer to this object.
I hope this can help you .
Robert

01 Oct 2014

Thanks for the help. I hope to get through some of the examples posted and report back.