BS2p-40 CONstants
On 10 Sep 01 at 5:52, Pence Bob wrote:
> The Stamp does not have an IN(x) function for reading
> a single input directly based on a variable I/O pin,
> so let's create the function.
Well...we do have the array approach: IN0 = IN0(0), IN1 =
IN0(1),,, IN15 = IN0(15). Example:
'{$STAMP BS2p}
in_pin VAR IN0
i VAR NIB
FOR i = 15 TO 0
DEBUG BIN1 in_pin(i)
NEXT
This displays the values of IN15, IN14,..., IN1, IN0.
Regarding the original question, the thing to keep in mind is we
refer to I/O pins in different contexts. Sometimes the reference is
by I/O pin number only, such as "LOW 1". In this case, a CON is
commonly used in place of the number.
Other times an operation and number are rolled together in a
variable, such as "IN1" which combines an input operation and I/O
pin selection. You can assign an alias to IN1 (or _any_ other
variable) by a VAR statement.
Three things which may help:
- Ask yourself: "Should I use a constant ('1') or variable ('IN1')
for this instruction?"
- The INS, OUTS and DIRS (and their respective subsets) are
variables in every sense. You can use them wherever a variable
works.
- When your IF statements aren't working like you'd expect, make
sure you're not testing for "IF 1 = 1" because you did something
like:
pin1 CON 1
IF pin1 = 1...
Regards,
Steve
> The Stamp does not have an IN(x) function for reading
> a single input directly based on a variable I/O pin,
> so let's create the function.
Well...we do have the array approach: IN0 = IN0(0), IN1 =
IN0(1),,, IN15 = IN0(15). Example:
'{$STAMP BS2p}
in_pin VAR IN0
i VAR NIB
FOR i = 15 TO 0
DEBUG BIN1 in_pin(i)
NEXT
This displays the values of IN15, IN14,..., IN1, IN0.
Regarding the original question, the thing to keep in mind is we
refer to I/O pins in different contexts. Sometimes the reference is
by I/O pin number only, such as "LOW 1". In this case, a CON is
commonly used in place of the number.
Other times an operation and number are rolled together in a
variable, such as "IN1" which combines an input operation and I/O
pin selection. You can assign an alias to IN1 (or _any_ other
variable) by a VAR statement.
Three things which may help:
- Ask yourself: "Should I use a constant ('1') or variable ('IN1')
for this instruction?"
- The INS, OUTS and DIRS (and their respective subsets) are
variables in every sense. You can use them wherever a variable
works.
- When your IF statements aren't working like you'd expect, make
sure you're not testing for "IF 1 = 1" because you did something
like:
pin1 CON 1
IF pin1 = 1...
Regards,
Steve
Comments
Is there a way of assigning constants to the I/O pins?
At the moment I do...
IO1 CON 1
IO2 CON 2
for MAINIO and,
IO16 CON 0
IO17 CON 1
etc.
AUXIO: IF IO16=1 THEN do something
The above line doesn't work. The only reason is, I think, is that
the IF THEN doesn't know the IO16 refers to an I/P pin.
Is there a way of setting my constant to know 1, which IO bank to use
and 2, that the number does relate to an I/O pin?
Thanks
JON
Yo assign a var to a pin use:
pin1 var in1
pin2 var in2
etc.
greetings peter
Oorspronkelijk bericht
Van: Jon [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=W1mqzzCNX1fDHBtxQ1a0VANV2JikNVsq6bDhNGj6-y7qO75Lf3CmvSsb-RHMIaeNgpze3J6uN6kdZ6w]jonm@p...[/url
Verzonden: maandag 10 september 2001 07:14
Aan: basicstamps@yahoogroups.com
Onderwerp: [noparse][[/noparse]basicstamps] BS2p-40 CONstants
Morning all,
Is there a way of assigning constants to the I/O pins?
At the moment I do...
IO1 CON 1
IO2 CON 2
for MAINIO and,
IO16 CON 0
IO17 CON 1
etc.
AUXIO: IF IO16=1 THEN do something
The above line doesn't work. The only reason is, I think, is that
the IF THEN doesn't know the IO16 refers to an I/P pin.
Is there a way of setting my constant to know 1, which IO bank to use
and 2, that the number does relate to an I/O pin?
Thanks
JON
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/
Change your definition from CON to VAR and point it at the corresponding bit
in the Ins regsiters. Like this:
IO1 VAR In1
IO2 VAR In2
IO16 VAR In1
IO17 VAR In2
-- Jon Williams
-- Applications Engineer, Parallax
In a message dated 9/10/01 1:15:10 AM Central Daylight Time, jonm@p...
writes:
> Is there a way of assigning constants to the I/O pins?
>
> At the moment I do...
>
> IO1 CON 1
> IO2 CON 2
>
> for MAINIO and,
>
> IO16 CON 0
> IO17 CON 1
>
> etc.
>
>
> AUXIO: IF IO16=1 THEN do something
>
> The above line doesn't work. The only reason is, I think, is that
> the IF THEN doesn't know the IO16 refers to an I/P pin.
>
> Is there a way of setting my constant to know 1, which IO bank to use
> and 2, that the number does relate to an I/O pin?
>
[noparse][[/noparse]Non-text portions of this message have been removed]
Using constants is ideal, but the examples you gave
have no advantage over hard-coding IN1, IN2, etc. If
you are using some math to figure out which I/O pin
you want to deal with at a certain point, that's
different.
You could trick the Stamp by using SHIFTIN for 1 bit,
with your I/O pin as the Dpin value, but that requires
a dummy Cpin clock pin on each of the I/O terminals,
MAINIO and AUXIO.
The Stamp does not have an IN(x) function for reading
a single input directly based on a variable I/O pin,
so let's create the function. Taking your convention
of numbering AUXIO pins on the BS2p40 as 16 to 31,
here is how I would do it:
' GetIn subroutine
' Precondition: I/O pin number in i
' Postcondition: Value of input i in j
GETIN:
IOTERM = i / 16 ' AUXIO if i > 15, else MAINIO
j = INS >> i // 2
RETURN
The IOTERM line can be dropped when not using the
BS2p40. INS is not changed by the shift right (>>)
operation.
Bob Pence
--- Jon <jonm@p...> wrote:
> Morning all,
>
> Is there a way of assigning constants to the I/O
> pins?
>
> At the moment I do...
>
> IO1 CON 1
> IO2 CON 2
>
> for MAINIO and,
>
> IO16 CON 0
> IO17 CON 1
>
> etc.
>
>
> AUXIO: IF IO16=1 THEN do something
>
> The above line doesn't work. The only reason is, I
> think, is that
> the IF THEN doesn't know the IO16 refers to an I/P
> pin.
>
> Is there a way of setting my constant to know 1,
> which IO bank to use
> and 2, that the number does relate to an I/O pin?
>
> Thanks
>
> JON
>
>
> 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/
>
>
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
AUXIO being read as 0. Let me try again:
' For BS2p40:
GETIN:
IOTERM = i / 16 ' AUXIO if i > 15, else MAINIO
j = INS >> (i//16) // 2
RETURN
' For all BS2 with 24 pins:
GETIN:
j = INS >> i // 2
RETURN
--- Pence Bob <bobpence_2000@y...> wrote:
> Jon -
>
> Using constants is ideal, but the examples you gave
> have no advantage over hard-coding IN1, IN2, etc. If
> you are using some math to figure out which I/O pin
> you want to deal with at a certain point, that's
> different.
>
> You could trick the Stamp by using SHIFTIN for 1
> bit,
> with your I/O pin as the Dpin value, but that
> requires
> a dummy Cpin clock pin on each of the I/O terminals,
> MAINIO and AUXIO.
>
> The Stamp does not have an IN(x) function for
> reading
> a single input directly based on a variable I/O pin,
> so let's create the function. Taking your convention
> of numbering AUXIO pins on the BS2p40 as 16 to 31,
> here is how I would do it:
>
> ' GetIn subroutine
> ' Precondition: I/O pin number in i
> ' Postcondition: Value of input i in j
> GETIN:
> IOTERM = i / 16 ' AUXIO if i > 15, else MAINIO
> j = INS >> i // 2
> RETURN
>
> The IOTERM line can be dropped when not using the
> BS2p40. INS is not changed by the shift right (>>)
> operation.
>
> Bob Pence
>
>
>
> --- Jon <jonm@p...> wrote:
> > Morning all,
> >
> > Is there a way of assigning constants to the I/O
> > pins?
> >
> > At the moment I do...
> >
> > IO1 CON 1
> > IO2 CON 2
> >
> > for MAINIO and,
> >
> > IO16 CON 0
> > IO17 CON 1
> >
> > etc.
> >
> >
> > AUXIO: IF IO16=1 THEN do something
> >
> > The above line doesn't work. The only reason is,
> I
> > think, is that
> > the IF THEN doesn't know the IO16 refers to an I/P
> > pin.
> >
> > Is there a way of setting my constant to know 1,
> > which IO bank to use
> > and 2, that the number does relate to an I/O pin?
> >
> > Thanks
> >
> > JON
> >
> >
> > 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/
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email alerts & NEW webcam video instant
> messaging with Yahoo! Messenger
> http://im.yahoo.com
>
> 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/
>
>
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
bobpence_2000@y... writes:
> You could trick the Stamp by using SHIFTIN for 1 bit,
> with your I/O pin as the Dpin value, but that requires
> a dummy Cpin clock pin on each of the I/O terminals,
> MAINIO and AUXIO.
And this consumes a lot of extra code space and is less obvious to code.
> The Stamp does not have an IN(x) function for reading
> a single input directly based on a variable I/O pin,
> so let's create the function. Taking your convention
> of numbering AUXIO pins on the BS2p40 as 16 to 31,
>
The Stamp doesn't have an IN(x) funtion, but the I/O pin register, Ins, can
be read as an array. So if your code requres a pin-by-pin scan, you can do
something like this:
FOR thePin = 0 TO 31
IOTERM thePin / 16
someVariable = Ins(thePin // 16)
' other code here
NEXT
-- Jon Williams
-- Applications Engineer, Parallax
[noparse][[/noparse]Non-text portions of this message have been removed]