automatically display character on next line using C for LCD

Status
Not open for further replies.
It depends how you are sending your characters. If you can count them, when you reach the end of the first line, send a cursor position command to the start of the second line. if you are using absolute cursor positioning for each character, if the position is greater than that of the last place on the first line, add the offset of the address of the second line. The line order on most LCD displays is 1,3,2,4 so overlowing the first line will make characters appear on the third line which the LCD controller probably understands even if it doesn't exist on the LCD glass. The offset you add is to make it skip line 3 so the next charcter appears on line 2.

Brian.
 

I am using array for the message,

unsigned char text[] ="This is testing 16x2 HD44780 LCD ";
unsigned char k;

while(1)
{
init_sub();

for (k=0;k<32;k++)
{
if(z <= 16)
lcd_data(text[k]);
else if(z > 16 & z <32)
lcd_data2(text[k]);
}
delay(50);
}

tried to use two subroutine lcd_data and lcd_data2,

can you help?

thanks
 

No need to use two routines but you do need to set the cursor to the start of the second line (DDRAM address 0x40). You can't do that by sending a character to the LCD, you have to send a command.

something like this:
Code:
	k = 0;
	while(k < 32)
	{
		lcd_data(text[k]);
		k++;
		if(k == 16) lcd_command(0xC0); // position cursor at start of second line
	}

I'm assuming you have an equivalent routine to 'lcd_data' called 'lcd_command'.

Brian.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…