SEROUT question
Archiver
Posts: 46,084
In the code below, there are 2 SEROUT statements.
1st SEROUT statement:
What exactly is sent by 1st SEROUT statement?
Is 20 sent as %00010100 and BL sent as %01111101?
2nd SEROUT statement:
Does it send out %00001100, then ASCII equivalent of "T", "h", "e"
etc.?
I'm trying to write to a serial LCD on pin 0. The LCD wants data at
9600 bps, inverted.
Thanks for help.
'{$STAMP BS2}
'{$PBASIC 2.5}
Baud CON 16468 'inverted, 9600 bps
TX CON 0
BackLite CON 20
BL CON 125
ClearLCD CON 12
SetCursor CON 17
PAUSE 500
SEROUT TX, Baud, [noparse][[/noparse]BackLite, BL]
SEROUT TX, Baud, [noparse][[/noparse]ClearLCD, "The Basic Stamp"]
END
1st SEROUT statement:
What exactly is sent by 1st SEROUT statement?
Is 20 sent as %00010100 and BL sent as %01111101?
2nd SEROUT statement:
Does it send out %00001100, then ASCII equivalent of "T", "h", "e"
etc.?
I'm trying to write to a serial LCD on pin 0. The LCD wants data at
9600 bps, inverted.
Thanks for help.
'{$STAMP BS2}
'{$PBASIC 2.5}
Baud CON 16468 'inverted, 9600 bps
TX CON 0
BackLite CON 20
BL CON 125
ClearLCD CON 12
SetCursor CON 17
PAUSE 500
SEROUT TX, Baud, [noparse][[/noparse]BackLite, BL]
SEROUT TX, Baud, [noparse][[/noparse]ClearLCD, "The Basic Stamp"]
END
Comments
'20' is sent as CHR(20), aka CHR($14),
aka %00010100 (as a single BYTE).
Then the single byte CHR(125), aka CHR($7D)
is sent.
Then CHR(12) (CHR($0C)), Then
"T","h","e"...
Problems:
1. You are sending out pin 0. Pin 0 does
NOT have a 232 driver on it. Does the LCD
WANT a 232 driver? Typically, 'Invert' mode
is used WITH a 232 driver. You either need
to add a 232 driver to the Stamp side, or
disable the jumper on the LCD side so it uses
0..5Volt signaling. THEN, you have to test
if the 'Invert' is still appropriate. Note
you can't damage anything by using the wrong
'Invert' mode -- so try it both ways and see
what works.
Note you CAN damage things by tying the
output of a 232 driver directly to a Stamp
pin -- you'll need a 22KOhm resistor in
that case.
It looks like you exactly understand what
SEROUT is doing -- the gotcha is that
'Invert' mode, and whether you REALLY
need it or not. I suspect not.
--- In basicstamps@yahoogroups.com, "newbiesda" <newbiesda@y...>
wrote:
> In the code below, there are 2 SEROUT statements.
>
> 1st SEROUT statement:
> What exactly is sent by 1st SEROUT statement?
> Is 20 sent as %00010100 and BL sent as %01111101?
>
> 2nd SEROUT statement:
> Does it send out %00001100, then ASCII equivalent of "T", "h", "e"
> etc.?
>
> I'm trying to write to a serial LCD on pin 0. The LCD wants data
at
> 9600 bps, inverted.
>
> Thanks for help.
>
>
>
> '{$STAMP BS2}
> '{$PBASIC 2.5}
>
> Baud CON 16468 'inverted, 9600 bps
> TX CON 0
> BackLite CON 20
> BL CON 125
> ClearLCD CON 12
> SetCursor CON 17
>
> PAUSE 500
> SEROUT TX, Baud, [noparse][[/noparse]BackLite, BL]
> SEROUT TX, Baud, [noparse][[/noparse]ClearLCD, "The Basic Stamp"]
>
> END
The problem is that when I try to use another "counterfeit Stamp", it
does not work.
So, what I want to know is what exactly is the BS2 sending out with
SEROUT 0, Baud, [noparse][[/noparse]20, 125]?
What exactly does CHR(20) and CHR(125) equate to?
Where can I find a chart that translates decimal number to equivalent
ASCII code?
Thanks.
--- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
wrote:
> Why yes, I believe you have it exactly correct.
>
> '20' is sent as CHR(20), aka CHR($14),
> aka %00010100 (as a single BYTE).
>
> Then the single byte CHR(125), aka CHR($7D)
> is sent.
>
> Then CHR(12) (CHR($0C)), Then
> "T","h","e"...
>
> Problems:
> 1. You are sending out pin 0. Pin 0 does
> NOT have a 232 driver on it. Does the LCD
> WANT a 232 driver? Typically, 'Invert' mode
> is used WITH a 232 driver. You either need
> to add a 232 driver to the Stamp side, or
> disable the jumper on the LCD side so it uses
> 0..5Volt signaling. THEN, you have to test
> if the 'Invert' is still appropriate. Note
> you can't damage anything by using the wrong
> 'Invert' mode -- so try it both ways and see
> what works.
>
> Note you CAN damage things by tying the
> output of a 232 driver directly to a Stamp
> pin -- you'll need a 22KOhm resistor in
> that case.
>
> It looks like you exactly understand what
> SEROUT is doing -- the gotcha is that
> 'Invert' mode, and whether you REALLY
> need it or not. I suspect not.
>
> --- In basicstamps@yahoogroups.com, "newbiesda" <newbiesda@y...>
> wrote:
> > In the code below, there are 2 SEROUT statements.
> >
> > 1st SEROUT statement:
> > What exactly is sent by 1st SEROUT statement?
> > Is 20 sent as %00010100 and BL sent as %01111101?
> >
> > 2nd SEROUT statement:
> > Does it send out %00001100, then ASCII equivalent
of "T", "h", "e"
> > etc.?
> >
> > I'm trying to write to a serial LCD on pin 0. The LCD wants data
> at
> > 9600 bps, inverted.
> >
> > Thanks for help.
> >
> >
> >
> > '{$STAMP BS2}
> > '{$PBASIC 2.5}
> >
> > Baud CON 16468 'inverted, 9600 bps
> > TX CON 0
> > BackLite CON 20
> > BL CON 125
> > ClearLCD CON 12
> > SetCursor CON 17
> >
> > PAUSE 500
> > SEROUT TX, Baud, [noparse][[/noparse]BackLite, BL]
> > SEROUT TX, Baud, [noparse][[/noparse]ClearLCD, "The Basic Stamp"]
> >
> > END
ascii character whose code is '20' (ie the
'space' character). I like that syntax
because it is relatively un-ambiguous.
If I say 'output 20', have I said to
output the two characters '2' and '0', or
the single byte '20'. And if it IS the
single byte '20', is that hexadecimal
'20' or decimal '20'.
Saying 'output CHR(20)' says the single
byte represented by the decimal value 20.
You'll need an ASCII character table to
get more translations -- though I suspect
the codes you're sending out are defined
by the LCD vendor to do 'special things'
with its LCD -- move cursor, blank screen,
etc.
--- In basicstamps@yahoogroups.com, "newbiesda" <newbiesda@y...>
wrote:
> Actually, the code is working. I get what I expect on the serial
LCD.
> The problem is that when I try to use another "counterfeit Stamp",
it
> does not work.
> So, what I want to know is what exactly is the BS2 sending out with
> SEROUT 0, Baud, [noparse][[/noparse]20, 125]?
>
> What exactly does CHR(20) and CHR(125) equate to?
> Where can I find a chart that translates decimal number to
equivalent
> ASCII code?
>
> Thanks.
>
>
>
> --- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
> wrote:
> > Why yes, I believe you have it exactly correct.
> >
> > '20' is sent as CHR(20), aka CHR($14),
> > aka %00010100 (as a single BYTE).
> >
> > Then the single byte CHR(125), aka CHR($7D)
> > is sent.
> >
> > Then CHR(12) (CHR($0C)), Then
> > "T","h","e"...
> >
> > Problems:
> > 1. You are sending out pin 0. Pin 0 does
> > NOT have a 232 driver on it. Does the LCD
> > WANT a 232 driver? Typically, 'Invert' mode
> > is used WITH a 232 driver. You either need
> > to add a 232 driver to the Stamp side, or
> > disable the jumper on the LCD side so it uses
> > 0..5Volt signaling. THEN, you have to test
> > if the 'Invert' is still appropriate. Note
> > you can't damage anything by using the wrong
> > 'Invert' mode -- so try it both ways and see
> > what works.
> >
> > Note you CAN damage things by tying the
> > output of a 232 driver directly to a Stamp
> > pin -- you'll need a 22KOhm resistor in
> > that case.
> >
> > It looks like you exactly understand what
> > SEROUT is doing -- the gotcha is that
> > 'Invert' mode, and whether you REALLY
> > need it or not. I suspect not.
> >
> > --- In basicstamps@yahoogroups.com, "newbiesda" <newbiesda@y...>
> > wrote:
> > > In the code below, there are 2 SEROUT statements.
> > >
> > > 1st SEROUT statement:
> > > What exactly is sent by 1st SEROUT statement?
> > > Is 20 sent as %00010100 and BL sent as %01111101?
> > >
> > > 2nd SEROUT statement:
> > > Does it send out %00001100, then ASCII equivalent
> of "T", "h", "e"
> > > etc.?
> > >
> > > I'm trying to write to a serial LCD on pin 0. The LCD wants
data
> > at
> > > 9600 bps, inverted.
> > >
> > > Thanks for help.
> > >
> > >
> > >
> > > '{$STAMP BS2}
> > > '{$PBASIC 2.5}
> > >
> > > Baud CON 16468 'inverted, 9600 bps
> > > TX CON 0
> > > BackLite CON 20
> > > BL CON 125
> > > ClearLCD CON 12
> > > SetCursor CON 17
> > >
> > > PAUSE 500
> > > SEROUT TX, Baud, [noparse][[/noparse]BackLite, BL]
> > > SEROUT TX, Baud, [noparse][[/noparse]ClearLCD, "The Basic Stamp"]
> > >
> > > END
Suppose I have:
Baud CON 16468 'inverted 9600 bps
data1 VAR Byte
data1 = %11100001
SEROUT 0, Baud, [noparse][[/noparse]data1]
What does the above SEROUT send exactly?
Since Baud of 16468 is 9600 bps inverted (according to BS2 manual),
I assume that BS2 sends out starting with LSB first, 0,1,1,1,1,0,0,0
(which is same as data1 inverted, LSB first).
Is my assumption correct?
Thank you.
--- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
wrote:
> CHR(20) is old PC Basic syntax, for the
> ascii character whose code is '20' (ie the
> 'space' character). I like that syntax
> because it is relatively un-ambiguous.
>
> If I say 'output 20', have I said to
> output the two characters '2' and '0', or
> the single byte '20'. And if it IS the
> single byte '20', is that hexadecimal
> '20' or decimal '20'.
>
> Saying 'output CHR(20)' says the single
> byte represented by the decimal value 20.
>
> You'll need an ASCII character table to
> get more translations -- though I suspect
> the codes you're sending out are defined
> by the LCD vendor to do 'special things'
> with its LCD -- move cursor, blank screen,
> etc.
>
> --- In basicstamps@yahoogroups.com, "newbiesda" <newbiesda@y...>
> wrote:
> > Actually, the code is working. I get what I expect on the serial
> LCD.
> > The problem is that when I try to use another "counterfeit
Stamp",
> it
> > does not work.
> > So, what I want to know is what exactly is the BS2 sending out
with
> > SEROUT 0, Baud, [noparse][[/noparse]20, 125]?
> >
> > What exactly does CHR(20) and CHR(125) equate to?
> > Where can I find a chart that translates decimal number to
> equivalent
> > ASCII code?
> >
> > Thanks.
> >
> >
> >
> > --- In basicstamps@yahoogroups.com, "Allan Lane"
<allan.lane@h...>
> > wrote:
> > > Why yes, I believe you have it exactly correct.
> > >
> > > '20' is sent as CHR(20), aka CHR($14),
> > > aka %00010100 (as a single BYTE).
> > >
> > > Then the single byte CHR(125), aka CHR($7D)
> > > is sent.
> > >
> > > Then CHR(12) (CHR($0C)), Then
> > > "T","h","e"...
> > >
> > > Problems:
> > > 1. You are sending out pin 0. Pin 0 does
> > > NOT have a 232 driver on it. Does the LCD
> > > WANT a 232 driver? Typically, 'Invert' mode
> > > is used WITH a 232 driver. You either need
> > > to add a 232 driver to the Stamp side, or
> > > disable the jumper on the LCD side so it uses
> > > 0..5Volt signaling. THEN, you have to test
> > > if the 'Invert' is still appropriate. Note
> > > you can't damage anything by using the wrong
> > > 'Invert' mode -- so try it both ways and see
> > > what works.
> > >
> > > Note you CAN damage things by tying the
> > > output of a 232 driver directly to a Stamp
> > > pin -- you'll need a 22KOhm resistor in
> > > that case.
> > >
> > > It looks like you exactly understand what
> > > SEROUT is doing -- the gotcha is that
> > > 'Invert' mode, and whether you REALLY
> > > need it or not. I suspect not.
> > >
> > > --- In basicstamps@yahoogroups.com, "newbiesda"
<newbiesda@y...>
> > > wrote:
> > > > In the code below, there are 2 SEROUT statements.
> > > >
> > > > 1st SEROUT statement:
> > > > What exactly is sent by 1st SEROUT statement?
> > > > Is 20 sent as %00010100 and BL sent as %01111101?
> > > >
> > > > 2nd SEROUT statement:
> > > > Does it send out %00001100, then ASCII equivalent
> > of "T", "h", "e"
> > > > etc.?
> > > >
> > > > I'm trying to write to a serial LCD on pin 0. The LCD wants
> data
> > > at
> > > > 9600 bps, inverted.
> > > >
> > > > Thanks for help.
> > > >
> > > >
> > > >
> > > > '{$STAMP BS2}
> > > > '{$PBASIC 2.5}
> > > >
> > > > Baud CON 16468 'inverted, 9600 bps
> > > > TX CON 0
> > > > BackLite CON 20
> > > > BL CON 125
> > > > ClearLCD CON 12
> > > > SetCursor CON 17
> > > >
> > > > PAUSE 500
> > > > SEROUT TX, Baud, [noparse][[/noparse]BackLite, BL]
> > > > SEROUT TX, Baud, [noparse][[/noparse]ClearLCD, "The Basic Stamp"]
> > > >
> > > > END
came with sample code for a bs2 and i need it for a bsx2. the serout
is says "serout 14, 32" i am not sure the translation to bsx2. if
anyone has an idea please let me know.
thanks!
k
>i am using a motor controller from pololu. the problem is that it
>came with sample code for a bs2 and i need it for a bsx2. the serout
>is says "serout 14, 32" i am not sure the translation to bsx2. if
>anyone has an idea please let me know.
>thanks!
>k
Kirsten -
The general formula for BAUDMODE on the BS-2 is:
INT(1,000,000/baud rate)-20 thus (1,000,000/19,200)-20 = 32
The sample program provided uses a BAUDMODE of 32 which equals 19,200 BPS.
The general formula for BAUDMODE for the BS-2SX is:
INT(2,500,000/baud rate)-20 thus (2,500,000/19,200)-20 = 110
Substitution of 110 where you find 32 in the SEROUT statements, will alter
the program appropriately.
There are other factors to consider under some circumstances, as indicated in
the Stamp PBASIC Manual, but none apply in this example. These factors include
parity, and TRUE or INVERTED formats.
Personally, I would use a format like this:
BAUDMODE CON 110
SEROUT 14, BAUDMODE, [noparse][[/noparse]$80,0,0,speed]
This would make any future changes to BAUDMODE real easy, by merely
changing the value of BAUDMODE once at the beginning of the program. No
variable space is
used by CON values. As far as I am aware, "BAUDMODE" is not a reserved word.
Regards,
Bruce Bates
In the help file you'll find an equation for calcuating the baud
parameter for any baud rate:
BS2sx, BS2p : INT(2,500,00 / baud) - 20
In your case, then, the baud parameter becomes 110. With new features
of the BASIC Stamp IDE you can use conditional compilation to make
switching Stamps easier. Here's a bit of code that I've been using
lately:
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T9600 CON 84
T192K CON 32
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T9600 CON 240
T192K CON 110
#ENDSELECT
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: kirsten [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=IhRZDEkysm6gU1G1B9e98w1-7Eg-pUsw7DY7WUFO7jfaKeZNz0OjixmkSfiCJ1DaRNFcKuLg8OqkaTiM3fc]kirsten@p...[/url
Sent: Sunday, November 30, 2003 7:14 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] serout question
i am using a motor controller from pololu. the problem is that it
came with sample code for a bs2 and i need it for a bsx2. the serout
is says "serout 14, 32" i am not sure the translation to bsx2. if
anyone has an idea please let me know.
thanks!
k
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
This message has been scanned by WebShield. Please report SPAM to
abuse@p....