Problem with HD44780 LCD - cursor movement

Hi all

I’ve been trying to use a 20x4 HD44780 LCD display as part of my Arduino project.

The HD44780 command set includes commands for moving the cursor left and right, however when using this I have noted some strange behavior.

On each line the cursor moves as expected, however when it gets to the end of the line it does not go to the next line as expected but follows the sequence Line1 → Line3 → Line2 → Line4.

Anyone come across this issue before?

Thanks in anticipation.

Code snippet below…

#include <SoftwareSerial.h>

#define txPin 12

SoftwareSerial LCD = SoftwareSerial(0, txPin);

void setup()
  // Clear display
  // This works as expected filling the screen with 'X's.  Line sequence 1-2-3-4
  for (int i = 1;i<=80;i++)
  // This doesn't work as expected.  Line sequence 1-3-2-4.
  for(int i = 1;i <=80;i++)
    LCD.write(0xFE);     // Command to follow.
    LCD.write(0x14);     // Move cursor to right.

void loop()

Anyone come across this issue before?

Everyone who has dealt with a 4 line display has come across this before since it is a characteristic of the HD44780 controller.

For a complete explanation follow the [u]LCD Addressing[/u] link at


Thanks Don... I'm a newbie so appreciate the info. The link provides an excellent description of the display addressing.

I now see why the 'shift cursor' functions as it does.

Does seem odd that that when writing characters to the display this seems to be compensated for. ie. characters are written to the display as expected... lines 1-2-3-4.