Sign in

username:

password:



Not a member?

Search oopic



Search tips

Subscribe to oopic



Ads

Discussion Groups

Discussion Groups | | Serial To LCD messing up

Serial To LCD messing up - ef721 - Jun 14 23:10:30 2008

I am passing a string of numbers to an ooPIC-R through a serial port
and having it display the numbers on a serial LCD. The first time it
gets the string it displays the number correctly. But the second time
it will first show the first string number it received from before and
then show the second string number it received now. Here is my code:
The string of numbers I send from the PC is in the format #xx , e.g.
#12 or #48.
Thank you so much for your help!

,Eric
LCD As oLCDSE
Serial As oSerialH
X As oByte
Y As oByte
total As Byte
X=0
Y=0
total=0
LCD.IOLine = 16
LCD.Baud = cv9600
LCD.Clear
Serial.Operate = cvOn
Serial.Baud = cv9600

Start:
If Serial.Received = cvTrue And Serial.Value = 35 Then
LCD.VString = "got #"
Goto FirstDigit
EndIf
Goto Start

FirstDigit:
If Serial.Received =cvTrue Then
X= Serial.Value
X = X - 48
LCD.Clear
LCD.VString = "got 1st digit: "
LCD.VString = Str$(X)
Goto SecondDigit
EndIf
Goto FirstDigit

SecondDigit:
If Serial.Received = cvTrue Then
Y = Serial.Value
Y = Y - 48
LCD.VString = "got 2nd digit: "
LCD.VString = Str$(Y)
Goto ProcessTones
EndIf
Goto SecondDigit

ProcessTones:
LCD.Clear
total = (X*10 +Y)
LCD.VString = Str$(total)
Serial.VString = Str$(total)
Delay = 2000
LCD.Clear
LCD.VString = " Ready "

Goto Start

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )


Re: Serial To LCD messing up - ef721 - Jun 15 20:29:14 2008

Someone please help , I need it done this week!

Thank you so much in advance!
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - David Warner - Jun 16 0:08:55 2008

I believe the first serial value must be read to clear things for the second digit. You didn't read the first digit.

--- On Sun, 6/15/08, ef721 wrote:

From: ef721
Subject: [oopic] Serial To LCD messing up
To: o...@yahoogroups.com
Date: Sunday, June 15, 2008, 3:10 AM

I am passing a string of numbers to an ooPIC-R through a serial port
and having it display the numbers on a serial LCD. The first time it
gets the string it displays the number correctly. But the second time
it will first show the first string number it received from before and
then show the second string number it received now. Here is my code:
The string of numbers I send from the PC is in the format #xx , e.g.
#12 or #48.
Thank you so much for your help!

,Eric

LCD As oLCDSE
Serial As oSerialH
X As oByte
Y As oByte
total As Byte
X=0
Y=0
total=0

LCD.IOLine = 16
LCD.Baud = cv9600
LCD.Clear
Serial.Operate = cvOn
Serial.Baud = cv9600

Start:
If Serial.Received = cvTrue And Serial.Value = 35 Then
LCD.VString = "got #"
Goto FirstDigit
EndIf
Goto Start

FirstDigit:
If Serial.Received =cvTrue Then
X= Serial.Value
X = X - 48
LCD.Clear
LCD.VString = "got 1st digit: "
LCD.VString = Str$(X)
Goto SecondDigit
EndIf
Goto FirstDigit

SecondDigit:
If Serial.Received = cvTrue Then
Y = Serial.Value
Y = Y - 48
LCD.VString = "got 2nd digit: "
LCD.VString = Str$(Y)
Goto ProcessTones
EndIf
Goto SecondDigit

ProcessTones:
LCD.Clear
total = (X*10 +Y)
LCD.VString = Str$(total)
Serial.VString = Str$(total)
Delay = 2000
LCD.Clear
LCD.VString = " Ready "

Goto Start

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - Andrew Porrett - Jun 16 0:16:17 2008

At 12:08 AM 6/16/2008, David Warner wrote:
>I believe the first serial value must be read to clear things for
>the second digit. You didn't read the first digit.

Sure he does. "X= Serial.Value"
>--- On Sun, 6/15/08, ef721 wrote:
>
>From: ef721
>Subject: [oopic] Serial To LCD messing up
>To: o...@yahoogroups.com
>Date: Sunday, June 15, 2008, 3:10 AM
>I am passing a string of numbers to an ooPIC-R through a serial port
>and having it display the numbers on a serial LCD. The first time it
>gets the string it displays the number correctly. But the second time
>it will first show the first string number it received from before and
>then show the second string number it received now. Here is my code:
>The string of numbers I send from the PC is in the format #xx , e.g.
>#12 or #48.
>Thank you so much for your help!
>
>,Eric
>
>LCD As oLCDSE
>Serial As oSerialH
>X As oByte
>Y As oByte
>total As Byte
>X=0
>Y=0
>total=0
>
>LCD.IOLine = 16
>LCD.Baud = cv9600
>LCD.Clear
>Serial.Operate = cvOn
>Serial.Baud = cv9600
>
>Start:
>If Serial.Received = cvTrue And Serial.Value = 35 Then
>LCD.VString = "got #"
>Goto FirstDigit
>EndIf
>Goto Start
>
>FirstDigit:
>If Serial.Received =cvTrue Then
>X= Serial.Value
>X = X - 48
>LCD.Clear
>LCD.VString = "got 1st digit: "
>LCD.VString = Str$(X)
>Goto SecondDigit
>EndIf
>Goto FirstDigit
>
>SecondDigit:
>If Serial.Received = cvTrue Then
>Y = Serial.Value
>Y = Y - 48
>LCD.VString = "got 2nd digit: "
>LCD.VString = Str$(Y)
>Goto ProcessTones
>EndIf
>Goto SecondDigit
>
>ProcessTones:
>LCD.Clear
>total = (X*10 +Y)
>LCD.VString = Str$(total)
>Serial.VString = Str$(total)
>Delay = 2000
>LCD.Clear
>LCD.VString = " Ready "
>
>Goto Start

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - David Warner - Jun 16 0:16:21 2008


Nope Sorry I see you did read the serial value!

--- On Sun, 6/15/08, ef721 wrote:

From: ef721
Subject: [oopic] Serial To LCD messing up
To: o...@yahoogroups.com
Date: Sunday, June 15, 2008, 3:10 AM

I am passing a string of numbers to an ooPIC-R through a serial port
and having it display the numbers on a serial LCD. The first time it
gets the string it displays the number correctly. But the second time
it will first show the first string number it received from before and
then show the second string number it received now. Here is my code:
The string of numbers I send from the PC is in the format #xx , e.g.
#12 or #48.
Thank you so much for your help!

,Eric

LCD As oLCDSE
Serial As oSerialH
X As oByte
Y As oByte
total As Byte
X=0
Y=0
total=0

LCD.IOLine = 16
LCD.Baud = cv9600
LCD.Clear
Serial.Operate = cvOn
Serial.Baud = cv9600

Start:
If Serial.Received = cvTrue And Serial.Value = 35 Then
LCD.VString = "got #"
Goto FirstDigit
EndIf
Goto Start

FirstDigit:
If Serial.Received =cvTrue Then
X= Serial.Value
X = X - 48
LCD.Clear
LCD.VString = "got 1st digit: "
LCD.VString = Str$(X)
Goto SecondDigit
EndIf
Goto FirstDigit

SecondDigit:
If Serial.Received = cvTrue Then
Y = Serial.Value
Y = Y - 48
LCD.VString = "got 2nd digit: "
LCD.VString = Str$(Y)
Goto ProcessTones
EndIf
Goto SecondDigit

ProcessTones:
LCD.Clear
total = (X*10 +Y)
LCD.VString = Str$(total)
Serial.VString = Str$(total)
Delay = 2000
LCD.Clear
LCD.VString = " Ready "

Goto Start

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - ef721 - Jun 16 0:57:55 2008

--- In o...@yahoogroups.com, David Warner wrote:
> Nope Sorry I see you did read the serial value!
>
> --- On Sun, 6/15/08, ef721 wrote:
I think the problem might be something that keeps on storing but not
clearing. Maybe some array or something , or perhaps the serial buffer
is storing past numbers sent. Anybody have any clue how to clear those
things , and what exactly needs to be cleared.

Thanks guys , appreciate it
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Re: Serial To LCD messing up - Andrew Porrett - Jun 16 2:05:11 2008

At 12:57 AM 6/16/2008, ef721 wrote:
>I think the problem might be something that keeps on storing but not
>clearing.

If there is, it's not in the OOPic.
> Maybe some array or something ,

You're not using any arrays.
> or perhaps the serial buffer
>is storing past numbers sent.

No, it doesn't do that.
> Anybody have any clue how to clear those
>things , and what exactly needs to be cleared.

If you're seeing multiple input sequences on your LCD, either your PC
is somehow sending the old data along with the new data (unlikely if
you're just using a simple terminal emulator program), or the
previously displayed data on the LCD isn't being cleared properly.

We're not there - you are. You'll have to figure out which of these
two possibilities is the culprit.
...Andy

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - ef721 - Jun 16 15:44:37 2008

--- In o...@yahoogroups.com, Andrew Porrett wrote:

> If you're seeing multiple input sequences on your LCD, either your PC
> is somehow sending the old data along with the new data (unlikely if
> you're just using a simple terminal emulator program), or the
> previously displayed data on the LCD isn't being cleared properly.
>
> We're not there - you are. You'll have to figure out which of these
> two possibilities is the culprit.
> ...Andy
>

Even when I output the data to serial it repeats. What am I doing
wrong and how do I clear that old data?
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Re: Serial To LCD messing up - Andrew Porrett - Jun 16 22:49:38 2008

At 03:44 PM 6/16/2008, ef721 wrote:
>Even when I output the data to serial it repeats. What am I doing
>wrong and how do I clear that old data?

Are you saying that the LCD.Clear command isn't working?

The OOPic manual says that command only works on a Scott Edwards LCD
module. If you're using a different module, you have to use its
clear command (or you could write a bunch of blanks)

Is this what your problem is?
...Andy

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - ef721 - Jun 17 8:44:50 2008

--- In o...@yahoogroups.com, Andrew Porrett wrote:
>
> At 03:44 PM 6/16/2008, ef721 wrote:
> >Even when I output the data to serial it repeats. What am I doing
> >wrong and how do I clear that old data?
>
> Are you saying that the LCD.Clear command isn't working?
>
> The OOPic manual says that command only works on a Scott Edwards LCD
> module. If you're using a different module, you have to use its
> clear command (or you could write a bunch of blanks)
>
> Is this what your problem is?
> ...Andy
>

Thanks for the reply.

My problem is as follows, even in this case without an LCD it messes up:
I send the number "1" from the serial port to the ooPIC
The ooPIC reads it and sends it right back out to the serial port,
where it is read by terminal. Up to here everything is working fine
Then when I send another number , lets say "2" , the ooPIC sends out
the serial port the old number (1) AND the new number (2).
So on the terminal window I would see the arrangement "1 1 2".

Why does it store the old number in the ooPIC and how can I clear it,
or perhaps there is something else I could do?

Thanks for helping out here.
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

RE: Re: Serial To LCD messing up - Dave Warner - Jun 17 10:18:58 2008


I think the serial object you're using may have like a four byte buffer if I'm not mistaken. Check that and find out if that's hangin' you up.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008

[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - ef721 - Jun 17 11:21:03 2008

--- In o...@yahoogroups.com, Dave Warner wrote:
> I think the serial object you're using may have like a four byte
buffer if I'm not mistaken. Check that and find out if that's hangin'
you up.
>
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008
>
> [Non-text portions of this message have been removed]
>

I'm using the oSerialH object
http://www.oopic.com/oserialh.htm

It doesn't say anything about a four byte buffer but it would make
sense that a buffer like that is storing the values and repeating them
on output. Any idea how to clear this buffer ( if it exists)?

Thanks so much!
,Eric
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - rtstofer - Jun 17 12:14:41 2008

I'm not sure but I think the OOPic compiler doesn't like that logical
expression in the first IF statement.

In any event, for the V5 compiler, the "Visual Basic" syntax and a
B.2.2+ chip, the following code works:

dim Serial As new oSerialPort
dim X As new oByte
dim Y As new oByte
dim total As new oByte

sub main()

X=0
Y=0
total=0

Serial.Baud = cv9600
Serial.Operate = cvOn

Start:
If (Serial.Received = cvTrue) then
if (Serial.Value = 35) Then
Serial.String = "got #" + Chr$(13) + Chr$(10)
Goto FirstDigit
End If
End If
Goto Start

FirstDigit:
If Serial.Received =cvTrue Then
X= Serial.Value
X = X - 48
Serial.String = "got 1st digit: "
Serial.String = Str$(X) + Chr$(13) + Chr$(10)
Goto SecondDigit
End If
Goto FirstDigit

SecondDigit:
If Serial.Received = cvTrue Then
Y = Serial.Value
Y = Y - 48
Serial.String = "got 2nd digit: "
Serial.String = Str$(Y) + Chr$(13) + Chr$(10)
Goto ProcessTones
End If
Goto SecondDigit

ProcessTones:
total = (X*10 +Y)
Serial.String = "Total = "
Serial.String = Str$(total) + Chr$(13) + Chr$(10)
Goto Start

end sub

I don't have the LCD so I dumped that code.

Richard

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Re: Serial To LCD messing up - Andrew Porrett - Jun 17 13:31:14 2008

At 11:20 AM 6/17/2008, ef721 wrote:
>I'm using the oSerialH object
>http://www.oopic.com/oserialh.htm
>
>It doesn't say anything about a four byte buffer but it would make
>sense that a buffer like that is storing the values and repeating them
>on output. Any idea how to clear this buffer ( if it exists)?

Many of the old timers on this list have stayed away from the newer
features of the V6 compiler. I suspect that this oSerialH object is
one of them. Instead, we have usually used the oSerialPort object,
which does have a four byte buffer and is known to work
properly. Your code should work fine if you just change the one line
where you declare your serial port.
...Andy

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - rtstofer - Jun 17 14:21:20 2008

--- In o...@yahoogroups.com, Andrew Porrett wrote:
>
> At 11:20 AM 6/17/2008, ef721 wrote:
> >I'm using the oSerialH object
> >http://www.oopic.com/oserialh.htm
> >
> >It doesn't say anything about a four byte buffer but it would make
> >sense that a buffer like that is storing the values and repeating them
> >on output. Any idea how to clear this buffer ( if it exists)?
>
> Many of the old timers on this list have stayed away from the newer
> features of the V6 compiler. I suspect that this oSerialH object is
> one of them. Instead, we have usually used the oSerialPort object,
> which does have a four byte buffer and is known to work
> properly. Your code should work fine if you just change the one line
> where you declare your serial port.
> ...Andy
>

I can't speak for the new compiler but that logical expression in the
first IF statement caused the identical symptoms in V5 and B.2.2+.
Just breaking the statement into two if then ... end if solved
the problem.

I suspect there is an issue with not short circuiting the evaluation
when the first equality is false. So what happens when you read the
port and it hasn't received anything? That's exactly what would
happen if the evaluation is not short circuited.

Kind of like 'what happens if I read a circular buffer ahead of the
insert pointer'? Well, I'm going to read the entire buffer again...

Richard

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Re: Serial To LCD messing up - Andrew Porrett - Jun 17 16:13:59 2008

At 02:21 PM 6/17/2008, rtstofer wrote:
>I can't speak for the new compiler but that logical expression in the
>first IF statement caused the identical symptoms in V5 and B.2.2+.
>Just breaking the statement into two if then ... end if solved
>the problem.

Ah yes, you're right. The statement:

if ((serial.received == TRUE) & (serial.value == 123))

produces this code:

55: 44 206 Get Serial.Received
57: 1 Pushb(1)
58: 152 IsEqual

59: 41 225 Get Serial.Value
61: 123 Pushb(123)
62: 152 IsEqual

63: 141 And
64: 137 0 71 BranchOnFalse(71)
130

which obviously evaluates the entire expression before deciding where
to branch to next. Gawd, I hate toy programming languages!
>I suspect there is an issue with not short circuiting the evaluation
>when the first equality is false. So what happens when you read the
>port and it hasn't received anything? That's exactly what would
>happen if the evaluation is not short circuited.

And you have a nasty race condition - if Serial.Received is false and
the trigger character arrives in time to get snagged by the "Get
Serial.Value", the entire expression fails (FALSE & TRUE = FALSE) and
the trigger character isn't detected.
>Kind of like 'what happens if I read a circular buffer ahead of the
>insert pointer'? Well, I'm going to read the entire buffer again...

Which is really dumb, since the firmware can easily do a test and
only advance the read pointer if it's not equal to the write pointer:

get_serial_dot_value:

// don't advance to next character if there isn't one

if (read_pointer != write_pointer)
increment read pointer (and wrap if now past end of buffer)

// return next available character
// (or same as last time if we don't have any new ones)

return (buffer[read_pointer])
It's really not rocket science...

Scott proclaimed one time that the (2.2+?) firmware only has one bug
in it. I doubt he meant this one.
...Andy

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - ef721 - Jun 17 18:33:26 2008

Thanks guys it worked!!!

In case you were all wondering I am working on a project and my
employer wanted a quick demo board up and running. He sent me an ooPIC
-R to work with . Its a good language for a beginner but it seems to
me there is such a big possibility for error when you control
electronics as objects . Needless to say I will be making my own
custom microcontroller board after the demo board is done.

Thanks for all the help!!!
,Eric
http://eRobots.BlogSpot.com
------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )

Re: Serial To LCD messing up - rtstofer - Jun 17 19:28:52 2008

--- In o...@yahoogroups.com, "ef721" wrote:
>
> Thanks guys it worked!!!
>
> In case you were all wondering I am working on a project and my
> employer wanted a quick demo board up and running. He sent me an ooPIC
> -R to work with . Its a good language for a beginner but it seems to
> me there is such a big possibility for error when you control
> electronics as objects . Needless to say I will be making my own
> custom microcontroller board after the demo board is done.
>
> Thanks for all the help!!!
> ,Eric
> http://eRobots.BlogSpot.com
>

Controlling anything with a microcontroller is 'risky'. Remember: if
builders built buildings like programmers write programs, the first
woodpecker to come along would destroy civilization.

Richard

------------------------------------



(You need to be a member of oopic -- send a blank email to oopic-subscribe@yahoogroups.com )