Around 40 years ago I wrote a screen driver for a 1602 LCD display.
It has worked well in many projects.
Until today when I bought in a blue 1602 display off ebay.
While I could write to line 1 writing to line 2 only displayed first character.
I tried various addresses for line 2 start but nothing worked.
So into the driver going through every set up instruction.
I then noticed the start of line 2 is 0x40 hex where as I had been using 40 which had previously worked.
Even setting line 2 start to 0x40 didnt work.
So back into the code.
I then noticed the set cursor position has highest bit set to denote set cursor position command and rest of bits are actual position.
I then spotted my mistake, I was anding new cursor position with 0x3f when it should ne 0x7f.
This was clipping the highest address I could send for cursor position.
So changed it to 0x7f and then everything worked fine.
So while 40 worked it really shouldn't have. It worked with many displays I have used over the years.
Never too old to learn from mistakes.
It has worked well in many projects.
Until today when I bought in a blue 1602 display off ebay.
While I could write to line 1 writing to line 2 only displayed first character.
I tried various addresses for line 2 start but nothing worked.
So into the driver going through every set up instruction.
I then noticed the start of line 2 is 0x40 hex where as I had been using 40 which had previously worked.
Even setting line 2 start to 0x40 didnt work.
So back into the code.
I then noticed the set cursor position has highest bit set to denote set cursor position command and rest of bits are actual position.
I then spotted my mistake, I was anding new cursor position with 0x3f when it should ne 0x7f.
This was clipping the highest address I could send for cursor position.
So changed it to 0x7f and then everything worked fine.
So while 40 worked it really shouldn't have. It worked with many displays I have used over the years.
Never too old to learn from mistakes.