PDA

View Full Version : LCD displaying problem..



sirvo
- 28th July 2007, 19:03
Hello all!

I'm trying to display this:



speed VAR WORD
LCDOUT $FE,$8D, DEC speed, "km/h"


LCD results:

Let's say speed is increasing and then decresing:


98km/h
99km/h
100km/h
101km/h
100km/h
99km/hh ----> THE PROBLEM


What is the 'secret' to solve this little problem?

Thanks..

Sylvio

mackrackit
- 28th July 2007, 19:13
Try clearing the screen.


speed VAR WORD
LCDOUT $FE,1 'CLEARS THE SCREEN
LCDOUT $FE,$8D, DEC speed, "km/h"

OR

LCDOUT $FE,1,$8D, DEC speed, "km/h"

Charles Linquis
- 28th July 2007, 19:13
There are several ways, but the easiest is to add some blank spaces after "km/h" so your code instead looks like

LCDOUT $FE,$8D, DEC speed, "km/h "

keithdoxey
- 28th July 2007, 20:29
There are several ways, but the easiest is to add some blank spaces after "km/h" so your code instead looks like

LCDOUT $FE,$8D, DEC speed, "km/h "

But that would result in the display moving about.

Better to conditionally add space BEFORE the value to be display eg

If speed < 10 then LCDOUT " " ' 1 space
If speed < 100 then LCDOUT " " ' 1 space
LCDUT DEC speed,"km/h"

IF the speed is 100 or greater then no spaces are prefixed
If the speed is 10-99 then one space will be prefixed
If the speed is below 10 then both conditions will be met and two spaces prefixed resulting the display remaining in a static position on the screen

GrandPa
- 29th July 2007, 05:34
First of all, I wonder about this line: LCDOUT $FE,$8D, DEC speed, "km/h "
--- > $8D ??? I think you meant $80 (beginning of first line)

Then, if it's the case you can use:

If speed < 100 then X= 1
If speed < 10 then X = 2
LCDOUT $FE,$8D + X, DEC speed, "km/h"


Cleaver!

keithdoxey
- 29th July 2007, 11:28
First of all, I wonder about this line: LCDOUT $FE,$8D, DEC speed, "km/h "
--- > $8D ??? I think you meant $80 (beginning of first line)

Then, if it's the case you can use:

If speed < 100 then X= 1
If speed < 10 then X = 2
LCDOUT $FE,$8D + X, DEC speed, "km/h"


Cleaver!

Whilst that would keep the "km/h" in the same position on the screen it WONT clear text that is previously written which is why you need to print spaces.

With the above code you would get the following

9 would give "9km/h"

49 would give "49km/h"

103 would give "103km/h"

but when the speed drops you would get the following problem due to not clearing the leading digits

87 would give "187km/h" (the "1" not being cleared)
5 would give "185km/h" (both the "1" and the "8" not being cleared)

Melanie
- 29th July 2007, 11:35
Actually GrandPa your option won't work.

Your logic is good, but you haven't completely thought it thru... (you still had $8D instead of $80 by the way - but forgetting that)...

Suppose you're dropping in speed... 101, 100, 99 <<< and there's the problem...

The last display was 100, you now shift over by one character postition and you display '99' over the top of the '00' part of 100. You haven't erased the '1' so your display goes...

101, 100, 199, 198 etc etc...

Keith hit it in one... but if you don't want a waving km/h display those first... and then just concentrate on the numbers. You can have leading or trailing blanks then (depending if you want left or right numeric justification).

OK... Keith got there first... *smiles*

keithdoxey
- 29th July 2007, 11:52
OK... Keith got there first... *smiles*

That makes a change :)

Normally I type a reply and post it to find that 3 or 4 other people have replied whilst I was typing.

The problem was even worse on one forum when I didnt have access during the day. By the time I got to read the messages there was no point in replying until I had read all messages as invariably someone eles had already said what I was going to!




$8D ??? I think you meant $80 (beginning of first line)


$80 would indeed be the start of the first line but $8D would be character position 14 on the first line. With a 20 character display this would give space for xxxkm/h to be right justified on the display which is what I suspect sirvo is trying to achieve.

bill12780
- 29th July 2007, 18:35
Man I learn alot reading this forum!

Where is the above mentioned "$8D" command documented? I had no idea you could do that? I knew you could shift right or left but did not know you could "jump" to a position...

Thanks to everyone for the education!

Bill12780

keithdoxey
- 29th July 2007, 19:26
Man I learn alot reading this forum!

Where is the above mentioned "$8D" command documented? I had no idea you could do that? I knew you could shift right or left but did not know you could "jump" to a position...

Thanks to everyone for the education!

Bill12780

Hi Bill,

It isnt specifically mentioned in the PBP manual as it depends on the LCD driver chip in your display but for any HD44780 or compatable controller it will work.

Download the datasheet for an HD44780 and look for the section on setting the registers.

DDRAM is the command to look at.

With bit 7 set you are setting where the data sent to the display is written.

%1xxxxxxx

$80 which is %10000000 is the first display position on Line1
$C0 which is %11000000 is the first position on line 2

increasign either of those values will move you along the line so that you can write at any position. This means you dont have to rewrite the entire display if all that is changing is a single character.

sirvo
- 29th July 2007, 19:32
That makes a change :)
$80 would indeed be the start of the first line but $8D would be character position 14 on the first line. With a 20 character display this would give space for xxxkm/h to be right justified on the display which is what I suspect sirvo is trying to achieve.

EXACTLY! I'm using a 4x20 display and the speed is going to be right justified!

Thanks All for helping!

Regards

Sylvio, :)

paul borgmeier
- 29th July 2007, 19:52
Man I learn alot reading this forum!

Where is the above mentioned "$8D" command documented? I had no idea you could do that? I knew you could shift right or left but did not know you could "jump" to a position...

Thanks to everyone for the education!

Bill12780

Although Keith answered your question quite well, this information is documented on page 94 of the PicBasic Pro manual under the LCDOUT command section (pg 94 of the online version here http://www.melabs.com/downloads/pbpm304.pdf )

keithdoxey
- 29th July 2007, 20:08
Although Keith answered your question quite well, this information is documented on page 94 of the PicBasic Pro manual

Oops :)

Cant find my printed manual at the moment to check if it is in there but on my Intranet I have the HTML version of the manual which I use as my reference.

It must be a much older version as it doesnt have the sentance about

LCDOUT $FE, $80+4.

It just says "See the data sheet for the particular LCD device for the character memory locations and additional commands"

GrandPa
- 30th July 2007, 00:39
This will cover everything

LCDOUT $FE,1, $80 + X, "your text here"

OR

LCDOUT $FE,1, $80 + X, #VAR here


Where X is the number of needed space.
Can also be broken in 2 instructions: LCDOUT $FE,1 : LCDOUT $FE, $80 + X, ...

Note: I strongly recommend against using spaces, mainly because it eats up more program memory, hard to see on source code too:



ex 1 : lcdout $FE,$80," 99" ---> 294 bytes used
ex 2 : lcdout $FE,$80+15,"99" ---> 200 bytes used

Can make a big difference if used extensively!

Hope It helps you sirvo and bill12780

bill12780
- 30th July 2007, 00:43
Feels like I am at the Church of the Blessed PIC!

Ok so here is a prime example of why you should read the entire section of the commmand.

I glazed over it to get to the defines section so I could change the default port from A to D. I totally skipped the section on memory mapping.

If I had read it, it would not have been such a revelation that the "commands" has they are refered to (in the manual) are actually "pointers" (for lack of a better term) to memory location within the LCD. I thought it was all PBP thing. Not LCD specific. Now I now...hahaha

I am going to go over the Datasheet for the HD44780 when I get a sec. Cause I bet I can finally figure out how they do scrolling (horizontal and vertical). But for now still working on my Keypad project...

Thanks you two! Time here is never wasted in my opinion. I learn something new each and everytime I come in here.

Oh and by the way...I have just (like a month ago) ordered the upgrade from MElabs to 2.47. My orginal (your not gonna belive this) came on a FLOPPY! So I ordered the printed manual as well. My manual is the same as the online version. I am a bit old school (Still have my old TI Logic Databooks!) I like having the printed book. You can order just the manual from MELabs for like 10-15 bucks...

Thanks again everyone!
Bill12780

GrandPa
- 30th July 2007, 00:49
Bill

Ask (search) about BIG number whenever you feel ready. Someone made a really nice routine to display 4*4 number on LCD.

J-P

bill12780
- 30th July 2007, 04:09
Grandpa,

Here is the the link of which you speak of.

Its mostly all over my head at this point. But I am learning fast. I book marked it and post it here for others refrence.


http://www.picbasic.co.uk/forum/showthread.php?p=26736

Thanks all!

Bill12780