displaying data on LCD

jonphenry

New Member
Hi, Im fairly new to the picaxe and the programming world in general. Ive been tinkering around with a 14M and have run in to a minor problem I cant see to get a leg over. I d appreciate any help.

I wrote a very simple little program, counts # of pulses over 5 sec and display the PPM and COUNT. Problem is the words PPM and COUNT display fine on my lcd but the actual w3 and w4 data values are displayed as random characters. Heres the code
<code>
main:

count 2, 5000, w2
let w3=w2*12
let w4=w4+w2
debug
serout 0,T2400,(254,1)
pause 30
serout 0,T2400,(254,128,"PPM =",#w3)
pause 30
serout 0,T2400,(254,192,"Count =",#w4)
pause 3000
goto main
<code>

Again it all seems to work fine except the data display. I thank you in advance for any help I can get.
 

hippy

Technical Support
Staff member
It should work, although DEBUG also uses Output Pin 0 so I'd recommend removing that to see if it improves things. Because the baud rate is T2400, Output Pin 0 should be set high before the first SerOut.

The only other thought is that it is related to an already identified issue ( <A href='http://www.rev-ed.co.uk/picaxe/forum/topic.asp?topic_id=7455&amp;forum_id=31&amp;Topic_Title=Serout+on+14M+V9%2EB&amp;forum_title=PICAXE+Forum&amp;M=False&amp;S=True' Target=_Blank>External Web Link</a> ) but Output Pin 0 reportedly works as expected.

Replace the Debug with &quot;High 0:pause 100&quot; and if that doesn't fix it, cut your code right back to<code><pre><font size=2 face='Courier'> High 0
Do
Pause 1000
SerOut 0,T2400,(#w0)
Loop </font></pre></code> which should slowly fill the display with &quot;0&quot;. Then try ...<code><pre><font size=2 face='Courier'> High 0
Do
Pause 1000
SerOut 0,T2400,(254,1)
Pause 100
SerOut 0,T2400,(#w0)
w0 = w0+1
Loop </font></pre></code> Then start adding text and other LCD command values one at a time until it stops working, then you'll have an idea as to where the problem lies which you can report back as, &quot;this works, but adding this breaks it&quot;.
 

jonphenry

New Member
Thanks for the response Hippy. I replaced the debug with no luck. When I entered your first code example, it did as you said except it wasnt a zero it was the division symbol(dash with a dot on top and bottom). When I entered the second code example, it appeared as if it were counting up but using extended ascii characters, not numbers.
Im using the Reved LCD firmware chip and 16x2 display. Is it possible to have something wired backwards to cause this?
 

hippy

Technical Support
Staff member
That you got &quot;PPM&quot; and &quot;Count&quot; to display correctly suggests it's not a wiring issue and nothing is backwards. The divide character bears no relationship to zero in my LCD character map, so it doesn't look like a baud rate issue - I can only assume it's an issue with SerOut on the 14M.

You can double-check your wiring and LCD operation using -<code><pre><font size=2 face='Courier'> High 0
Do
Pause 1000
SerOut 0,T2400,(&quot;U&quot;)
Loop </font></pre></code>

Edited by - hippy on 28/07/2007 16:07:48
 

jonphenry

New Member
Thanks again Hippy. I had torn the breadboard apart before I got the message to try &quot;U&quot;. I rebuilt with a 40x1 and it displayed perfectly. Must be a 14m issue.
Have another question though. As I was pulsing away I noticed if I made the PPM go into three characters, going back below 100 didnt get rid of the third character. IE If my reading now was 112, and five seconds later my reading should have been 85 the PPM would read 852. I could fix this by putting s serout with clear command in the loop, but that would cause my display to flash every 5 sec. Is there a way around this?
 

papaof2

Senior Member
Test the value of the output number, and send spaces to pad the display.

pseudocode:
if number &lt;10 then
send two spaces
elseif number &lt;100 then
send one space
else
send no space
end if
send number

John



 
 

jonphenry

New Member
Thanks papa. I can test the numbers no problem but how do I send these extra spaces to the lcd. I cant find any info on sending extra spaces, only moving the cursor over
 

jonphenry

New Member
Thanks so much guys. All works like a champ now.

high 7
pause 100
serout 7,T2400,(254,1)
main:

count 3, 5000, w0
let w1=w0*12
let w2=w2+w0
high 7
pause 100
if w1&lt;10 then
goto digit1
elseif w1&lt;100 then
goto digit2
else goto digit3
endif

total:

if w2&lt;10 then
goto total1
elseif w2&lt;100 then
goto total2
else goto total3
endif

digit1:

serout 7,T2400,(254,128,&quot; PPM = &quot;,#w1)
pause 30
goto total

total1:

serout 7,T2400,(254,192,&quot; Total = &quot;,#w2)
pause 30
goto main

digit2:

serout 7,T2400,(254,128,&quot; PPM = &quot;,#w1)
pause 30
goto total

total2:
serout 7,T2400,(254,192,&quot; Total = &quot;,#w2)
pause 30
goto main

digit3:

serout 7,T2400,(254,128,&quot; PPM =&quot;,#w1)
pause 30
goto total

total3:
serout 7,T2400,(254,192,&quot; Total =&quot;,#w2)
pause 30
goto main

Any tips on shortening or rearranging for less code, same effect?
Ive seen all code so for with serout have the short pauses after the command. Is it really needed and what is the purpose?

Edited by - Jon Henry on 28/07/2007 23:16:17
 

hippy

Technical Support
Staff member
I'd probably go with something (untested) like this ...<code><pre><font size=2 face='Courier'>High 7
Pause 100
SerOut 7,T2400,(254,1)

Do
Count 3, 5000, w0
w1 = w0 * 12
w2 = w2 + w0
SerOut 7,T2400,(254,128,&quot; PPM = &quot;) : w0 = w1 : Gosub PrintNumber
SerOut 7,T2400,(254,192,&quot; Total = &quot;) : w0 = w2 : Gosub PrintNumber
Loop

PrintNumber:
SerOut 7,T2400,(#w0)
Do While w0 &lt; 10000
SerOut 7,T2400,(&quot; &quot;)
w0 = w0 * 10 MIN 10
Loop
Return </font></pre></code> This removes unwanted trailing digits. If you wanted right aligned numbers, move the &quot;SerOut...(#w0)&quot; in PrintNumber to after the Loop command.

The Pauses after SerOut are there to give the LCD time to update the display, but are not necessary in most cases.

Edited by - hippy on 29/07/2007 03:01:39
 
Top