lcd rolling text help

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

hi in this part o f my code its for rolling a text to first line of lcd

char array[21]={"Please Press a Buton"};

for(j=0;j<19;j++)

{
lcd_gotoxy(0,0);
lcd_putsf(" ");
if(j==0)lcd_gotoxy(15,0);
else if(j==1)lcd_gotoxy(14,0);
else if(j==2)lcd_gotoxy(13,0);
else if(j==3)lcd_gotoxy(12,0);
else if(j==4)lcd_gotoxy(11,0);
else if(j==5)lcd_gotoxy(10,0);
else if(j==6)lcd_gotoxy(9,0);
else if(j==7)lcd_gotoxy(8,0);
else if(j==8)lcd_gotoxy(7,0);
else if(j==9)lcd_gotoxy(6,0);
else if(j==10)lcd_gotoxy(5,0);
else if(j==11)lcd_gotoxy(4,0);
else if(j==12)lcd_gotoxy(3,0);
else if(j==13)lcd_gotoxy(2,0);
else if(j==14)lcd_gotoxy(1,0);
else if(j==15)lcd_gotoxy(0,0);

for(i=0;i<20;i++)
{
c=array[i];
lcd_putchar(c);
}
lcd_gotoxy(0,1);
lcd_putsf(" ");
delay_ms(500);

if (PINB.0==0) { adder(); };
}

my problem is that the display shows only the 16 chars "Please Press
a B" and starts fron begginig

any idea to fix this?

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

Can your delay_ms function support a parameter of 500? The built-in one (in gcc anyways) needs to have something like <20 as parameter. If that's the case, your delay might not be happening, which means it'll rip through the code and quickly display everything and all you'll see is the last one that displays the whole line from the left edge.

Try replacing delay_ms(500) with a for loop that calls delay_ms(10) 50 times.

Clancy _________________ Step 1: RTFM Step 2: RTFF (Forums) Step 3: RTFG (Google) Step 4: Post

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

Or replace:
else if(j==7)lcd_gotoxy(8,0);
with:
else if(j==7)while (1) {};

That way it should freeze after it's done the first 7 iterations and you should see the text displayed in the last 7 spots on the LCD. That way you know it's working like you want and it's the delay that's screwing things up.

Clancy _________________ Step 1: RTFM Step 2: RTFF (Forums) Step 3: RTFG (Google) Step 4: Post

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

no the delay it works... the problem is that the scroling stops at 15char and does not continue to 16th i cand discrive well with words because i dont speek so good english

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
if(j==0)lcd_gotoxy(15,0);
else if(j==1)lcd_gotoxy(14,0);
else if(j==2)lcd_gotoxy(13,0);
else if(j==3)lcd_gotoxy(12,0);
else if(j==4)lcd_gotoxy(11,0);
else if(j==5)lcd_gotoxy(10,0);
else if(j==6)lcd_gotoxy(9,0);
else if(j==7)lcd_gotoxy(8,0);
else if(j==8)lcd_gotoxy(7,0);
else if(j==9)lcd_gotoxy(6,0);
else if(j==10)lcd_gotoxy(5,0);
else if(j==11)lcd_gotoxy(4,0);
else if(j==12)lcd_gotoxy(3,0);
else if(j==13)lcd_gotoxy(2,0);
else if(j==14)lcd_gotoxy(1,0);
else if(j==15)lcd_gotoxy(0,0); 

Couldn't this be simplified to:

lcd_gotoxy(15-j,0);

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

Couldn't this be simplified to:

lcd_gotoxy(15-j,0);


must be:
lcd_gotoxy(j <= 15 ? 15 - j : 0, 0);

because of

for(j=0;j<19;j++)

in front of that

CU

Programmers never die
they just GOSUB without RETURN

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

Ahh, I see what you're trying to do. You account for moving the beginning all the way back to the left edge, but you don't account for moving it behind the left edge. When you get past displaying 16 characters, you have to set the pointer to 0,0 still, but you have to strip off the first leading characters of the string.

Try something like:

#define STRING_LENGTH	21
#define LCD_MAX		15

char array[STRING_LENGTH] = { "Please Press a Button" };

for ( j = 0; j < STRING_LENGTH; j++ )
{
    if ( j >= LCD_MAX )
        lcd_gotoxy( 0, 0 );
    else
        lcd_gotoxy( LCD_MAX - j, 0 );

    int start = (j <= LCD_MAX) ? 0 : (j - LCD_MAX);
    int end   = (j <= LCD_MAX) ? j : (start + LCD_MAX);

    if ( end >= STRING_LENGTH )
        end = STRING_LENGTH - 1;

    for ( i = start; i <= end; i++ )
        lcd_putchar( array[i] );
    
    delay_ms(500);
}

I added defines to make it easier to change string length and hopefully to make it a bit clearer what's being calculated.

This one will only display as many characters as will fit on screen. Some LCD's have only a limited buffer you can write to beyond the width. If you have a large enough string, you might write past the line1 buffer and display on line2.

Haven't verified this, but hopefully it works =) Might need a tweak or two.

Clancy _________________ Step 1: RTFM Step 2: RTFF (Forums) Step 3: RTFG (Google) Step 4: Post

Last Edited: Thu. Apr 19, 2007 - 03:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another thing you can look at is that man LCD's have the ability to shift the display for you. You can write the entire string starting from position 15 and then repeatedly issue scroll left commands until you've scrolled the entire string. Something like:

#define STRING_LENGTH	21
#define LCD_WIDTH	16

char array[STRING_LENGTH] = { "Please Press a Button" };

lcd_gotoxy( LCD_WIDTH, 0 );

for ( j = 0; j < STRING_LENGTH; j++ )
    lcd_putchar( array[i] );

for ( j = 0; j < STRING_LENGTH; j++ )
{
    lcd_shiftleft();
    delay_ms(500);
}

You'd have to make sure your display supports this, though, and would have to implement lcd_shiftleft().

Clancy _________________ Step 1: RTFM Step 2: RTFF (Forums) Step 3: RTFG (Google) Step 4: Post

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

with the firs example i get 2 errors

int start = (j <= LCD_MAX) ? 0 : (j - LCD_MAX);
error: must declare first in block

int end = (j <= LCD_MAX) ? j : (start + LCD_MAX);
error: must be cnstant exeption

and the lcd_shiftleft(); does not recognized from cavr!! :( time for another copiler

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

You can't use variables for a static, compile time initialiser. But you should find that:

  int end; 
  end = (j <= LCD_MAX) ? j : (start + LCD_MAX); 

compiles OK as it then will generate code to calculate the 'end' value at runtime.

Cliff

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

What LCD library are you using???

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

dclark,

I thought it might be:

http://homepage.hispeed.ch/peter...

or

http://hubbard.engr.scu.edu/avr/...

but actually the API looks to be subtly different to both (though fairly close to the first).

Cliff

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

I said you'd have to implement lcd_shiftleft() yourself as it's a function I made up. The functionality should be in at least some LCD controllers I think, but I don't know if it's been implemented in any libraries.

As for the compilation errors on the first thing... what Cliff said =)

Clancy _________________ Step 1: RTFM Step 2: RTFF (Forums) Step 3: RTFG (Google) Step 4: Post

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

Guys,

He's using Codevision and has been asking the same questions (and MANY more) over there.

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

If you are using a 44780 compatable display controller and you read the datasheet then you'll see that the controller can implement whats called a display shift for you in hardware when its fed the correct commands.Obviously if you are using a 2 line x 16 character display then the first address of the first line would normally be 0x00 and the first address of the second line would be 0x40 follwong a hardware display shift then the addres will be 0x01 and 0x41 repectivly.
the character ram in the display controller has 80 memory locations but the display only shows a small number of those characters at any time so you can think of a display shift as moving display window over the unshown characters.