Home - Search - Members
Full Version: 2 Line LCD 8051 (Strange problem)
say2paul
Jul 3 2008, 10:30 AM
Please look at the following code and let me know where I am wrong? In the following code I am not using the BF flag instead I am providing a delay using for loop (12 MHz).

The output is sometimes printed well on the LCD but sometimes it just print the first line and does not print the second line.

Can anyone help me rectifying it?

CODE:

/*********************************************************  
*    PROGRAM TO TEST LCD INTERFACE                                       *

*    ADDRESS OF LED'S = 0XFD00                                                   *
*********************************************************/

         
#include<P89V51RX2.h>
#include<intrins.h>
#include<string.h>

/*********************************************************
Function Prototypes
*********************************************************/

void delay(void);
void writecommand(unsigned char);
void writedata(unsigned char);
void printlcd(unsigned char *);
void nextline(void);
/*********************************************************/


xdata volatile unsigned char rs _at_ 0xFE01;
//xdata volatile unsigned char en _at_ 0xFE00;
xdata volatile unsigned char lcd _at_ 0xFE00;



/*********************************************************
Function which causes some  delay
*********************************************************/

void delay()
{
int k;
for(k=0;k<=9000;k++);
}
/*********************************************************/


/*********************************************************
Function to initialize lcd
*********************************************************/

void init_lcd()
{
writecommand(0x38);
writecommand(0x06);
writecommand(0x0e);

writecommand(0x01); //Clear the display

}

/*********************************************************/


/*********************************************************
Function to write data into lcd
*********************************************************/

void writecommand(unsigned char data1)
{
lcd=data1;
//en=1;
//en=1;
_nop_();
_nop_();
//en=0;
delay();
}
/*********************************************************/

void writedata(unsigned char data2)
{
rs=data2;
//en=1;
//en=1;
_nop_();
_nop_();
//en=0;
//delay();
}

/*********************************************************
Function to print a string data into lcd
*********************************************************/


 void printlcd(unsigned char *str)
{
unsigned char len,i;

//rs=1;

len=strlen(str);

        for(i=1;i<=len;i++)
        {
        writedata(*str);
        str++;
        }
}

/*********************************************************/



/*********************************************************
Function to send a command to print in 2nd line
*********************************************************/


void nextline()
{
//rs=0;
writecommand(0xc0);
}

/*********************************************************/


void main()
{

AUXR=0x03;
//rw=0;                        //read/write pin made 0

init_lcd();                          //initialize lcd

printlcd("Hello how r u?");              //send a string for display

nextline(); // Next Line

printlcd("I am fine");           //send a string for display

while(1);

}
 
Amin Sharif
Jul 3 2008, 8:35 PM
Hello

increase the delay to about 15 to 20 mili seconds.
Give delay in Write data command routine too.
say2paul
Jul 3 2008, 10:18 PM
If I give more delay then it does not look nice when the display shifts left or right.

Can anyone tell me how to achieve the following feature in 2 line LCD:

- Line 1 display shift left.
- Line 2 display shift right.

or

- Line 1 display no shift.
- Line 2 display shift right.

Ajay
Jul 3 2008, 11:28 PM
use an array and rotate it..

shift that array left or right one byte or say one element, display on LCD, then give some delay before shifting the next element.

you can do this shift as you want. IT Pro wont have any problem doing it
say2paul
Jul 4 2008, 2:07 AM
Smart!! but I was talking about the display shift commands.

Suppose I give right shift command to the LCD, both the lines start moving in the right direction, but I want only one line to move and other to stay intact.

So, its display shift commands
Ajay
Jul 7 2008, 7:52 AM
well display shift will shift the entire display (behind the scene.. it shift the ram content in cyclic way) so its not possible to shift a single line.

only possible with software...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007