Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Lcd hitachi + at89c51

Status
Not open for further replies.

ReyDemonio

Newbie level 3
Joined
Oct 4, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
Hello, I'm trying to use a LCD Display (LM016L) with Hitachi processor, controlling it with an AT89C5131 and a 4 bits interface, but I'm only getting black rectangles and nothing else in the real kit and nothing at all in the protheus simulation.

Could anyone help me with the code please? Thanks

Code:
#include<at89c5131.h> 
sbit EN = P3^6;
sbit RS = P3^4;
sbit RW = P3^5;

unsigned char dato = 0;
unsigned char code tex1[16] = {' ','L','C','D',' ','d','e',' ','2',' ','f','i','l','a','s',' '};
unsigned char i = 0, j = 0, k = 0, z = 0;
bit BU = 0;

void ini();
void trans (unsigned char i);
void wait (unsigned char z);

void main (void)
{
	ini();		
	for(;;)
	{
		dato = 0x80;
		trans(0);
		for(k=0;k<17;k++)
		{
			dato = tex1[k];
			trans(1);
		}
	}
}

void ini()
{
	wait(0);

	dato = 0x30;
	BU = 0;	                        //Normal delay
	trans(0);				//Function set 1 + wait
	trans(0);				//Function set 2 + wait
	trans(0);				//Functino set 3 + wait 
	
	BU = 1;                              //Wait for BF flag
	dato = 0x20;
	trans(0);
	
	BU = 1;
	dato = 0x80;
	trans(0);
	
	BU = 1;
	dato = 0x01;
	trans(0);

	BU = 1;
	dato = 0x06;
	trans(0);

	BU = 1;
	dato = 0x14;
	trans(0);

	BU = 1;
	dato = 0x02;
	trans(0);

	BU = 1;
	dato = 0x0C;
	trans(0);
}

void trans (unsigned char i)
{
	if (i == 0) 
	{
		RS = 0;
	}
	else
	{
		RS = 1;
	}
	RW = 0;
	P2 = dato;
	EN = 1;
	while (EN == 0);
	EN = 0;
	dato = dato << 4;
	P2 = dato;
	EN = 1;
	while (EN == 0);
	EN = 0;
	wait(BU);
}

void wait (unsigned char z)
{
	if (z == 0) 
	{
		for(i=0;i<255;i++)
		{
			for(j=0;j<80;j++);
		}	
	}
	else
	{
		P2 = 0xFF;
		RS = 0;
		RW = 1;
		EN = 1;
		while (P2_7 == 1);		//Wait for BF to fall
		EN = 0;
		RW = 0;
		P2 = 0x00;
	}
}
 

The LCD you're using is essentially a 20-year old design, based on a device called HD44780.
If you google for that device, you'll find tons of example source code to control it,
and probably lots of example with the same microcontroller you're using too.
I suspect your issue is that you've got no delays, but it's been a while since I tried this
LCD controller. Anyway, as a side note, your code is very odd in that you're using global variables to pass
information that ordinarily could just be parameters in function calls.
 

Sorry for the odd code, i'm only starting with C51 and all this stuff. I've tried to improve it like you said, without using so many global variables.

Code:
#include<at89c5131.h> 
sbit EN = P3^6;
sbit RS = P3^4;
sbit RW = P3^5;

unsigned char code tex1[16] = {' ','L','C','D',' ','d','e',' ','2',' ','f','i','l','a','s',' '};
unsigned char i = 0, j = 0, k = 0, z = 0;
bit BU = 0;

void ini();
void trans (unsigned char i, unsigned char dato);
void wait (unsigned char z);

void main (void)
{
	ini();		
	for(;;)
	{
		trans(0, 0x80);
		for(k=0;k<17;k++)
		{
			trans(1, tex1[k]);
		}
	}
}

void ini()
{
	wait(0);

	BU = 0;	                                //Wait mode - Delay
	trans(0, 0x30);				//Function set 1 + wait
	trans(0, 0x30);				//Function set 2 + wait
	trans(0, 0x30);				//Function set 3 + wait 
	
	BU = 1;                                      //Wait mode - Busy Flag
	trans(0, 0x20);
	trans(0, 0x80);
	trans(0, 0x01);
	trans(0, 0x06);
	trans(0, 0x14);
	trans(0, 0x02);
	trans(0, 0x0C);
}

void trans (unsigned char i, unsigned char dato)
{
	if (i == 0) 
	{
		RS = 0;
	}
	else
	{
		RS = 1;
	}
	RW = 0;
	P2 = dato;
	EN = 1;
	while (EN == 0);
	EN = 0;
	dato = dato << 4;
	P2 = dato;
	EN = 1;
	while (EN == 0);
	EN = 0;
	wait(BU);
}

void wait (unsigned char z)
{
	if (z == 0) 
	{
		for(i=0;i<255;i++)
		{
			for(j=0;j<80;j++);
		}	
	}
	else
	{
		P2 = 0xFF;
		RS = 0;
		RW = 1;
		EN = 1;
		while (P2_7 == 1);		//Wait Busy Flag to fall
		EN = 0;
		RW = 0;
		P2 = 0x00;
	}
}
 

Can at least give me someone a working code for a 8051 micro and a HD44780? I can't find anything useful in google, only parts of the code or invalid codes.
 

The following is a tutorial demoing an HD44780 compatible LCD using 4-bit interface with the 8051 family and provides source code in both Assembly and C languages:

LCD interfacing with Microcontrollers tutorial


Typically, black boxes/rectangles indicated an initialization issue, possibly incorrect delays, connections, etc.


BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top