Problem with GLCD (KS0108)

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

Hi

I have a problem with a GLCD i bought from China..
I dont manage to alter any of the pixels, they just appear scattered around, but at same positions every time. (see pic)
I have checked the connections a few times, and they appear ok since i am able to enable the display.

Here is the code im trying to run, it doesn't do anything useful, just trying to see if the lcd does anyting useful.. Sorry about the code, i'm new to this..

#define F_CPU 8000000UL

#include 
#include 

#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2
#define LCD_CS1 5
#define LCD_CS2 4

#define LCD_cmd_paa 0x3f
#define LCD_cmd_av 0x3e
#define LCD_cmd_setY 0x40
#define LCD_cmd_setX 0xb8
#define LCD_cmd_setZ 0xc0

int LCD_status(char);
void LCD_cmd(char, char);
void LCD_data(char, char);
void LCD_CS_off(void);

int main(void){

	int i,j;

	DDRA = 0x00;
	DDRB = 0xff;
	DDRD = 0xff;
	PORTB = 0x00;

	for (i=0; i<20; i++)
		_delay_ms(10);

	while ((LCD_status(3) & 0x80) != 0);	

	LCD_cmd(3, LCD_cmd_setX + 0);
	LCD_cmd(3, LCD_cmd_setY + 0);
	LCD_cmd(3, LCD_cmd_setZ + 0);
	LCD_cmd(3, LCD_cmd_paa);

	for (i=0; i<7; i++)
	{
		LCD_cmd(1, LCD_cmd_setX + i);
		LCD_cmd(1, LCD_cmd_setY + 0);
		for (j=0; j<63; j++)
		{
			LCD_data(1, j);
		}
	}

	PORTD |= (1<<7);
	while (1){
	}
}

int LCD_status(char cs)
{
	int status;

	switch(cs){
		case 1:PORTB |= (1<<LCD_CS1); PORTB &= ~(1<<LCD_CS2); break;
		case 2:PORTB |= (1<<LCD_CS2); PORTB &= ~(1<<LCD_CS1); break;
		case 3:PORTB |= ((1<<LCD_CS1) | (1<<LCD_CS2)); break;
	}

	PORTB |= (1<<LCD_RW);
	PORTB &= ~(1<<LCD_RS);
	PORTB |= (1<<LCD_EN);
	_delay_ms(10);
	status = PINA;
	PORTB &= ~(1<<LCD_EN);		
	return status;
}

void LCD_cmd(char cs, char cmd)
{
	while ((LCD_status(cs) & 0x80) != 0);	
	DDRA = 0xff;
	PORTB &= ~((1<<LCD_RW) | (1<<LCD_RS));
	PORTA = cmd;
	PORTB |= (1<<LCD_EN);
	_delay_ms(10);
	PORTB &= ~(1<<LCD_EN);
	DDRA = 0x00;
	LCD_CS_off();
}

void LCD_data(char cs, char data)
{
	while ((LCD_status(cs) & 0x80) != 0);	
	DDRA = 0xff;
	PORTB &= ~(1<<LCD_RW);
	PORTB |= (1<<LCD_RS);
	PORTA = data;
	PORTB |= (1<<LCD_EN);
	_delay_ms(10);
	PORTB &= ~(1<<LCD_EN);
	DDRA = 0x00;
	LCD_CS_off();
}

void LCD_CS_off(void){
	PORTB &= ~((1<<LCD_CS1) | (1<<LCD_CS2));
}

Thanks for any suggestions :wink:

Attachment(s): 

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

Go have a look at this thread. You may find some tips.
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=90506

X & Y in the document are typically "backwards" from what people consider x & y.
So for clarity I always use "col" and "page" to keep things clear.

Some modules require a reset before they work properly.
The picture looks odd enough that it looks like perhaps the chips are reset or not properly reset.

The command, write, and status routines look ok, as do the command defines.

The delays are super overkill but ok for this level of testing.

Not sure of your display size and chip dimensions but your loop seems to cover an area 56 pixels tall by 62 pixels wide on chip #1.

The loop in your code would produce "odd" results as it looks like it is attempting to go down the display each 8 pixel row at a time and write the X coordinate position to the page at that column. So it would be a binary increment of 8 pixels across is that what you were going for?

What is hooked up to bit 7 on port D?
Is that just a debug pin?

Do you have a data sheet for you module?

--- bill

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

Thanks for your suggestions.

After a bit searching on the internet i discovered the display doesn't use a KS0108 controller as described in the ebay listing, but a ST7920 controller. :evil:

Now i am not sure if the display supports graphic display, it looks more like a HD44780 based controller with good support for chinese characters..

But at least it works now after modifying the program to interface a ST7920 instead..

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

It's a graphics display.  It just uses a different chip.

 

There are Arduino libs for this chip, if you want to get some clues about how to use it.

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

@wallyowen, after almost 7 years I expect th83 figured it out or moved on...

David (aka frog_jr)

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

Sometimes if the frequency of your clock is high, the MCU can not respond. You can reduce your clock frequency and check agail. For example set it on 1MHz.