View Full Version : LCD question
02-08-2005, 07:24 AM
· I am working on an LCD demonstration and I have run into a very odd response to my code.· The LCD is being programmed to print the following:
"This is a test"
It holds this for a few seconds, and then it puts a "*" in the home position, then moves it all the way to the right side of the screen and then back to the left.· Now, here's the problem.· In order to write "This is a test", I need to use 14 spaces on the LCD, and so I use the following code to do this:
' Begin writing text to LCD
' write "This"
FOR k=1 TO 4
' Space -- send cursor to the right
' Write "is"
FOR k=1 TO 2
' space -- send cursor to the right
' send cursor into next register
FOR k=1 TO 32
' space -- send cursor to the right
' write "test"
FOR k=1 TO 4
So, this works fine.· But when I try to move the asterisk into the next register, I use the shift-display-right command, but I have to do it 79 times to get it so show up in the next register.· Does anyone know why this would happen?
02-08-2005, 08:13 AM
·· First of all, you posted the working code, and not the problem code.· However, based on your post I think I see what's going on...You didn't specify how many lines and characters in the display either, so I will guess it's a 1 line display with 16 characters.
·· LCD Displays have their memory mapped by lines.··Some 1 line displays (I have 2 myself) have 2 eight character banks (lines) mapped into 1 line.· But line one's memory is 80 characters before it hits line two.· What you may have to do is shift it 8 times (Actually 9 to scroll off the first section), then jump to address 81 and print the asterisk and continue shifting.
When you say next register, I am assuming the later half of the screen, but again, it could just as easily apply to line 2 on a two-line display.· Let me know how that works out for you...
02-08-2005, 08:15 AM
To be candid you're making things a little harder than you need to. When I want to send a string to an LCD I store it in a DATA statement and use a loop to send the characters (the string is terminated with zero so I know when to exit the loop). Have a look at StampWorks or our LCD Terminal AppMod docs to LCD code that will help you out.
Applications Engineer, Parallax
Dallas, TX· USA
02-08-2005, 09:38 AM
Let me be a little more clear.· I am not trying to run the LCD as much as I am trying to·demonstrate how an LCD works.· As I understand it, the LCD has 80 bytes of RAM, and the visible portion which shows up in the display is RAM addresses 0 through 7 and 40 through 47.· So, if I am in cursor increment mode, and I·write, "this is a test".· Once·I have reached the "s" in the word "is", I am at RAM address 8, and so the following character "a" will have to show up in RAM address 40 in order that the words appear together on the screen.· I do this by shifting the cursor 32 or so times to the right.· And this works perfectly.· Now, the second part of this demonstration is to get an asterisk to move from RAM address 0 to RAM address 79 and back in a seemingly continuous fashion.· So, I put the asterisk onto the home position, then I shift the display 7 times, with a 100 ms pause between shifts.· At this point I am at the end of the visible portion of what I call the left register.· Then I create a FOR loop and I shift the display to the right 32 times, and the asterisk should show up in RAM address 40, or what I call the first position of the right regsiter.· It doesn't.· In fact, if I shift the display 72 times, then it shows up in the right register.· What am I doing wrong?· Or better yet, how can I get the asterisk to sweep across the screen of LCD?
02-10-2005, 01:06 AM
·· Okay, now I see what you've got.· If the second half of the display is mapped at address 40-47, then you are actually wasting time shifting the cursor right all those times.· What you should do, is print what you need in the first 8 locations, then send the LCD the command to set the DD Address to 40.· This will start you printing at that location.
·· All you need to do for your asterisk routine is handle the first half of the display in a loop, and the other half in another.· Don't try to shift the cursor all those extra spaces, just jump to the absolute address.· That is how I have handled this issue in the 2 displays I have that are mapped like that.
·· Actually there are 2 ways if you're using a serial backpack.· I can tell from your code you're not, but if you wanted to, it might help.· Most serial backpacks will allow you to specify the number of lines in the display.· In these displays there are actually 2, mapped as one line.· In any event you could, if using serial backpack print the first 8 characters, then following with a CR/LF, then print line 2.· For example:
SEROUT LCD, Baud, ["This is ", 13, 10, "a test."]