Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD Problem

Status
Not open for further replies.

elexhobby

New Member
Hi..
I am learning interfacing a LCD with uC.
I could successfully display characters on the LCD. I have set the cursor shift left command to give an impression of a scrolling text. But the problem is whenever the length of my string becomes more than 24 characters, the next character automatically starts being displayed on line 2 (I am using a 16 X 2 LCD). Is this bcoz of limited amount of memory? What is the solution to this?
i.e. Suppose my string is ‘Hi How are you? I am fine here’ It is displayed as shown, since upto letter 'n' of the word 'fine', there are 24 characters. (Only last 16 characters will be present at any instant in upper line)

re you? I am fin
_____________e here

Please help me..
Thanks in advance
 
I'm not very sure what your problem is?, you say you are using "cursor shift left", do you mean "display shift"?.

You should consider how the LCD works, basically they are almost all 2x40 characters internally, a 2x16 only has 16 visible at a time, but it's still 40 chracters wide internally. The display shift instructions move the visible 'window' along the 40 character buffer.
 
Hi…
Sorry, I was not clear in stating my problem.
Infact, I am confused with screen & cursor shift also, besides my above problem.
The command for cursor/screen shift is- 000001 I/O S
The data sheet says –
I/O = 1/0: Cursor R/L, Screen L/R
S = 1/0: Shift screen/cursor
Now I send 06 or 04 as the command word, & text as “Hello” starting from address 87H, then ‘H’ is displayed at 87H, ‘e’ at 88H & so on till ‘o’ at 8BH. The display is the same whether I send command word as 06 or 04.
On the other hand, if I send command word as 07 or 05 (result same for both), ‘o’ is displayed at 86H, ‘l’ at 85H & so on till ‘H’ at 82H. Thus it progressively moves in the left direction, if address is 87H, as each character is sent. Note that when I send first ‘H’ to 87H in this left shift mode, it is displayed at a previous address, i.e. 86H & then it progressively shifts left, as I send ‘e’,’l’,’l’,’o’.
06,04 = right shift
05,07=left shift
Since I wanted to make a scrolling display (like marquee in html), I sent the string ‘Hello’ at address 90H, so that it starts shifting left from address 8Fh. And I am using a sufficient delay between sending two characters, to give the impression of movement. This worked fine as long as my string was short like ‘Hello’.
But when I sent – “Hello, How r u? I am fine here” – Note that ‘n’ in ‘fine’ is the 24th character. So it does the scrolling in the first line as expected upto ‘n’. But the character ‘e’ starts in the second line.
So ultimately the final display looks as shown (last 16 characters present at any instant)

? I am fin
_______e here

(Discard the underscore, it is just to push ‘e here’ after ‘fine’).

Here is the code that I am using –

RS equ P1.2
RW equ P1.1
E equ P1.0
FLAG equ P2.7
DATAPRT equ P2
lcd:
mov A,#38h
acall Command
mov A,#0Ch
acall Command
mov A,#07
acall Command
mov A,#01h
acall Command
mov A,#90h
acall Command

;Display starts here
mov dptr,#Character
Back2:
clr A
movc A,@A+dptr
jz Here
acall Display
inc dptr
sjmp Back2
here:
sjmp here

Command:
acall Ready
clr E
mov DATAPRT,A
clr RS
clr RW
setb E
clr E
ret


Display:
acall Ready
clr E
mov DATAPRT,A
setb RS
clr RW
setb E
clr E
acall Delay
ret

Ready:
push A
clr A
clr E
setb RW
clr RS
mov DATAPRT,#0FFh
Wait:
setb E
clr E
dec A
jz Out
jb FLAG,Wait
Out:
pop A
ret

Delay:
mov R2,#02h
again2:
mov R0,#0FFh
again1:
nop
mov R1,#0FFh
back1:
djnz R1,back1
djnz R0,again1
djnz R2,again2
ret

Character:
db 'Hello, How r u? I am fine here',0
end

Sorry for such a long post. Please do spare time to read & answer my doubt.
Thanks a lot...
 
elexhobby said:
But when I sent – “Hello, How r u? I am fine here” – Note that ‘n’ in ‘fine’ is the 24th character. So it does the scrolling in the first line as expected upto ‘n’. But the character ‘e’ starts in the second line.

As I said before, your LCD is 2x40 characters, with a 2x16 'window' on to it, if you start your string from position 16 on the first line, then the 'n' in 'fine' will be the last character on the first line, so the string will continue on the second line, just as it does on your computer screen!.
 
OK I now understand the problem..

But is there any solution to this, if I want the text to be displayed on the first line only..

There is a clear memory instruction available, but it will clear the whole memory, so the last visible text will also be deleted, & there will be a kind of discontinuity in the displayed text..

One solution is - maintain a count register, & as soon as 24 characters are over, delete memory, resend the last 16 characters without a delay between them, & then send the next 8 characters with a delay between them.. This way the user won't notice because of persistence..

But this way, you can send only 8 more characters each time you carry out this procedure.. Is there a better method available?
Thanks for clearing my doubt..
 
elexhobby said:
But is there any solution to this...

it depends on your LCD.
look at it, and see what IC's are attached to it. It will probably be something like HD47780.

now go to google, and type in the number you saw on the IC and you should see information about the IC, including the bit definitions.
 
elexhobby said:
OK I now understand the problem..

But is there any solution to this, if I want the text to be displayed on the first line only..

There is a clear memory instruction available, but it will clear the whole memory, so the last visible text will also be deleted, & there will be a kind of discontinuity in the displayed text..

One solution is - maintain a count register, & as soon as 24 characters are over, delete memory, resend the last 16 characters without a delay between them, & then send the next 8 characters with a delay between them.. This way the user won't notice because of persistence..

But this way, you can send only 8 more characters each time you carry out this procedure.. Is there a better method available?
Thanks for clearing my doubt..

There are two basic methods of using an LCD, firstly as you are doing now, effectively using the LCD's facilities - this is easy and simple, but you are limited to what it's original designers (or more correctly, Hitachi's original designers!) decided on.

Secondly, you take complete control of the display, which means you NEVER write outside the visible area, and you DON'T use it's scrolling capabilites. You need to maintain a buffer of characters in your code, and only ever write the 16 that are needed for the display, and move the start pointer to your text string to implement the scrolling.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top