PDA

View Full Version : Newbie - LCDOUT command



SOTASOTA
- 14th December 2010, 20:35
I have a newbie question. I wish to display a value on an LCD 16*2 display.
Got the display working great.

I read the values on PortB and wish to convrt what I read into a percentage of full scale.
I total all the values on PortB and store into variable WTotal (WTotal var WORD). I also have declared variable WTotalPercentage (WTotalPercentage var WORD).

The values go from 0 to 1275.
I wish to show a percentage based on a full scale reading of 1275.
For example:
If I read a vaule of 256, this represents approx. 20% of 1275.
The math being WTotalPercentage = WTotal/1275*100
Simple.
Now how do I display the value of WTotalPercentage in an LCD display?

If I use:
LCDOUT DEC (WTotalPercentage)

I get a reading of zero. I think it lies in the math of WTotalPercentage = WTotal/1275*100, however I do not know how picBasic math function work.
Help!

Acetronics2
- 16th December 2010, 16:27
Hi SOTA^2

I do not understand one thing :

How do you do for entering a 1275 value on portB ??? ....

as maximum value is 255 or %11111111 :confused:


for the math ...

IF your max value is 1275 ...

Wtotal/1275 = 0 or 1 ( :rolleyes: integer math Ok ??? )

if multiplied by 100 ... result is 0 or 100

That's all !!!

first multiply Wtotal by 100 and AFTER that divide by 1275 ...

Alain

marcusvm
- 16th December 2010, 16:46
What I've done with my projects when using a 16F884 is follow the general command of LCDOUT. I copied the code from my last project, I think it should work the same for you. So if I had a value previous stored in the variable V, and wanted to display that value, I would do. The dec4 will show 4 sig figs.


LCDOUT $FE, 1, dec4 V

Another forum member showed me this, but if you want to use decimal precision as well the code is as follows. So say you are reading voltage on a pin and want that displayed with a decimal. You first have to store each digit as a variable, then display it.

V = a number that was been previously stored during the program in a variable




A = V DIG 4
B = V DIG 3
C = V DIG 2
D = V DIG 1

LCDOUT $FE, 1, "Voltage ", dec1 A, dec1 B, ".", dec1 C, dec1 D


Hope this helps.

-Marcus

Plcguy
- 16th December 2010, 21:52
to display volts with a decimal point example

Volts_2=AIN2*50/51
HI_2 = Volts_2/10
LOW_2 = Volts_2//10
Lcdout $fe, 1, "Bat Volts =",#HI_2,".",#LOW_2

leaving volts * 10 or 100 to maintain precision

SOTASOTA
- 16th December 2010, 23:45
I have got it to work using DIV32 command.
Thanks to all!!
Here is the updated code:
mainloop:
WTotal=(W0+W1+W2+W3+W4+W5+W6+W7)
dummy = WTotal*10000
WTotal2 = Div32 1275

LCDOut $fe, 1 ' Clear LCD screen
LCDOut "AUX IN Volume:"
'Charac 1234567890123456
LCDOut $fe, $c0 'Jump to second line
IF WTotal = 0 Then LCDOut "MAXIMUM (100%)"
IF WTotal >0 AND WTotal <130 Then LCDOut "-",DEC(WTotal/10), ".", DEC1(WTotal), "dB (", DEC(WTotal2/100), ".", DEC2(WTotal2),"%)"
IF WTotal >=130 Then LCDOut "-",DEC(WTotal/10), ".", DEC1(WTotal), "dB (", DEC(WTotal2/100), "%)"
Pause 100