scrolling display on 16*2 lcd

Status
Not open for further replies.

uday mehta

Advanced Member level 4
Joined
Dec 30, 2011
Messages
104
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Visit site
Activity points
1,979
I write down a program for scrolling display.
it is working properly in first line but then stuck.
when I check this program in keil debugger it works properly.
can you please help me to find where is the problem.
HTML:
#include<reg51.h>

sbit rs=P3^0;
sbit en=P3^1;

 void delay(int c)
{
 int i,j;
 for(i=0;i<c;i++)
 for(j=0;j<1275;j++);
}

void wdata(char a)
{
 rs = 1;
 P2 = a;
 en = 1;
 delay(10);
 en = 0;
}

void wcmd(int b)
{
 rs = 0;
 P2 = b;
 en = 1;
 delay(10);
 en = 0;
}

void lcd(char *disp)
{
 int k;
 int l=0;
 for(k=0;disp[k]!=0;k++)
 {
  wdata(disp[k]);
  if(l>15)
  {
   wcmd(0x07);
   delay(10);
  }
  l++;
  }
  
}

void lcdinit()
{
  wcmd(0x38);
  delay(50);
  wcmd(0x0c);
  delay(50);
  wcmd(0x01);
  delay(50);
  wcmd(0x06);
  delay(50);



}

void main()
{
  lcdinit();
  lcd("this is my first movable display program");
  delay(10);
  wcmd(0x80);
  lcd("i am very happy");
  while(1);


}
 

Attachments

  • moving_display.zip
    53.7 KB · Views: 63

i have slightly modified for your code please make note of it.hope you will get the result what you expected
Code:
void main()
{
  lcdinit();
  while(1)
  {
  wcmd(0x01);
  wcmd(0x8f);
  wcmd(0x07);
  lcd("this is my first movable display program");
  delay(10);
  wcmd(0x8f);
  lcd("i am very happy");
  delay(10);
  }


}
Code:
void lcd(char *disp)
{
 int k=0;
 
 while(disp[k]!='\0')
 {
  wdata(disp[k]);
  
  k++;
  }
  
}
 

thanks Aameer.
it is working, but partially. means now it is not displaying "display program".
and for what command "0x8f" stand for?
and also I am not able to understand the logic.
you type "display shift to left command" only once. then how it is shifting every time?
next question is that is there any character limit or I can write a string as long as I want.
 

0x8F = cursor first row 0x0F th column.

Do you want to scroll only one line or both lines at the same time ? Will there be any other code in the program like button read, led blin, etc... ? If yes then timer interrupt based code has to be used for LCD scrolling.
 

no i don't have any other button.
and i want to display first string in first line.(with scrolling). when is reach its end then start second string just after first one.
means both strings look like single string.

- - - Updated - - -

no i don't have any other button.
and i want to display first string in first line.(with scrolling). when is reach its end then start second string just after first one.
means both strings look like single string.
 

You mean when first string's last letter gets out of the left side of display then first character of the 2nd string appear at the right side of display ?
 

yes.
first of all it print complete string. it is not printing even first line completely.
 

How should the scrolling of 1st string start ? 1st character of 1st string starts at last column of display and shifts to left ?
 


View attachment lcd1 Part -1.pdf
In the attachment read page 7, you can understand how you write commands to LCD, for scrolling and others.
 

sir,
aameer's program working but my string ("this is my first movable display program") print till "disp".
remaining part i.e. "lay program" never printed on lcd.
i just want to print whole string.
and then the second string.
by the way second string is not my main concern. it will be fine if it will display in second line.
 


then you have to write a loop function with required delays ,and a pointer pointing where of array to start display on LCD. though it looks like scrolling you will actually printing the text you want to display.

array[40] = "this is my first movable display program";

for(i=0;i<40;i++)
{
// print first 16 chars on line 1.
// required delay
}
 

In my actual program I have lengthy data so use of for loop is inconvenient. that's why I am using pointer.

- - - Updated - - -


thanks for the link.
I wanted just a single line and now I got it.
thank you very much.

- - - Updated - - -


thanks for the link.
I wanted just a single line and now I got it.
thank you very much.
 

I wanted just a single line and now I got it.

How did you solve problem? Just post your solution and make this thread as solved so others it can be useful for others.
 

It was a single brace that created problem.
Code:
void lcd(char *disp)
{
 int k;
 int l=0;
 for(k=0;disp[k]!=0;k++)
 {
  wdata(disp[k]);
  l++;
  }
  if(l>15)
  {
   wcmd(0x07);
   delay(10);
  }
  
  
}
now it will scroll first line properly.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…