Shop OBEX P1 Docs P2 Docs Learn Events
Bs2 and/or/xor logic — Parallax Forums

Bs2 and/or/xor logic

ArchiverArchiver Posts: 46,084
edited 2000-07-16 07:21 in General Discussion
Hello group,

I am trying to use AND and XOR logic expressions and am having some
difficulty. I've used the following code on another type of micro
but it doesn't want to work with the BS2. Can some one take a look
at this and tell me the BS2 equilvalent. I know its got to be
something simple that I am missing.

'SET I/O PINS (1=OUPUT,0=INPUT)
'THER ARE 8 OUTPUTS AND 8 INPUTS

DIRS = $FF00

'SET PIN CONSTANTS

PIN0 CON $0001
PIN1 CON $0002
PIN2 CON $0004
PIN3 CON $0008
PIN4 CON $0010
PIN5 CON $0020
PIN6 CON $0040
PIN7 CON $0080
PIN8 CON $0100
PIN9 CON $0200
PIN10 CON $0400
PIN11 CON $0800
PIN12 CON $1000
PIN13 CON $2000
PIN14 CON $4000
PIN15 CON $8000

pause 100

'MAIN PROGRAM LOOP

BEGIN:

'CODE FOR 1ST OUTPUT (PIN8)

FIRST_OUTPUT:

W0=INL 'READ THE 8 INPUTS
W1=W0 AND PIN0 'IS INPUT 0 ON, MASK ALL OTHERS
IF W1=0 THEN FIRST_OFF 'IF NO INPUT TURN OFF OUTPUT, ELSE
'CONTINUE CHECKING FOR THIS OUTPUT

W1=W0 AND PIN4 'IS INPUT 4 ON, MASK ALL OTHERS
W1=W1 XOR PIN4 'IF INPUT 4 IS ON, MAKE IT LOOK OFF
IF W1=0 THEN FIRST_ON 'IF INPUT IS ON TURN ON OUTPUT, ELSE
'CONTINUE CHECKING FOR THIS OUTPUT

W1=W0 AND PIN6 'IS INPUT 6 ON
IF W1=0 THEN FIRST_OFF 'IF NO INPUT TURN OFF OUTPUT, ELSE
'TURN OUTPUT ON

FIRST_ON:

OUT8=1 'TURN ON PIN 8 OUTPUT
GOTO SECOND_OUTPUT

FIRST_OFF:

OUT8=0 'TURN OFF PIN 8 OUTPUT

SECOND_OUTPUT:
'
'
'

GOTO BEGIN

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-07-16 07:06
    The AND/OR/ etc work fine for single bits or logical evaluations,
    such as IF (IN5=0) AND (IN2=1) THEN ....

    But they are not bitwise operators. For masking bits you need to use
    & for AND
    | for OR
    ^ for XOR

    such as w0 = w0 ^ %1111

    Good luck,
    -Martin Hebel
    SelmaWare Solutions
    www.selmaware.com

    Southern Illinois University Carbondale
    Electronics Management
    www.siu.edu/~imsasa/elm

    --- In basicstamps@egroups.com, "steve tatum" <swt@p...> wrote:
    > Hello group,
    >
    > I am trying to use AND and XOR logic expressions and am having some
    > difficulty. I've used the following code on another type of micro
    > but it doesn't want to work with the BS2. Can some one take a look
    > at this and tell me the BS2 equilvalent. I know its got to be
    > something simple that I am missing.
    >
    > 'SET I/O PINS (1=OUPUT,0=INPUT)
    > 'THER ARE 8 OUTPUTS AND 8 INPUTS
    >
    > DIRS = $FF00
    >
    > 'SET PIN CONSTANTS
    >
    > PIN0 CON $0001
    > PIN1 CON $0002
    > PIN2 CON $0004
    > PIN3 CON $0008
    > PIN4 CON $0010
    > PIN5 CON $0020
    > PIN6 CON $0040
    > PIN7 CON $0080
    > PIN8 CON $0100
    > PIN9 CON $0200
    > PIN10 CON $0400
    > PIN11 CON $0800
    > PIN12 CON $1000
    > PIN13 CON $2000
    > PIN14 CON $4000
    > PIN15 CON $8000
    >
    > pause 100
    >
    > 'MAIN PROGRAM LOOP
    >
    > BEGIN:
    >
    > 'CODE FOR 1ST OUTPUT (PIN8)
    >
    > FIRST_OUTPUT:
    >
    > W0=INL 'READ THE 8 INPUTS
    > W1=W0 AND PIN0 'IS INPUT 0 ON, MASK ALL OTHERS
    > IF W1=0 THEN FIRST_OFF 'IF NO INPUT TURN OFF OUTPUT, ELSE
    > 'CONTINUE CHECKING FOR THIS OUTPUT
    >
    > W1=W0 AND PIN4 'IS INPUT 4 ON, MASK ALL OTHERS
    > W1=W1 XOR PIN4 'IF INPUT 4 IS ON, MAKE IT LOOK OFF
    > IF W1=0 THEN FIRST_ON 'IF INPUT IS ON TURN ON OUTPUT, ELSE
    > 'CONTINUE CHECKING FOR THIS OUTPUT
    >
    > W1=W0 AND PIN6 'IS INPUT 6 ON
    > IF W1=0 THEN FIRST_OFF 'IF NO INPUT TURN OFF OUTPUT, ELSE
    > 'TURN OUTPUT ON
    >
    > FIRST_ON:
    >
    > OUT8=1 'TURN ON PIN 8 OUTPUT
    > GOTO SECOND_OUTPUT
    >
    > FIRST_OFF:
    >
    > OUT8=0 'TURN OFF PIN 8 OUTPUT
    >
    > SECOND_OUTPUT:
    > '
    > '
    > '
    >
    > GOTO BEGIN
  • ArchiverArchiver Posts: 46,084
    edited 2000-07-16 07:21
    marin hebel,
    thankx for the help it worked like a charm.

    Original Message
    From: Martin Hebel [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=GDoT3NetPY7G9ErEHoZRppzReHX4MBV80aX3Xjr8-_4PvRcl1vQOIoJHcYGmnaL96zwuwVO-tLkROMQfBFE]martin@s...[/url
    Sent: Sunday, July 16, 2000 1:06 AM
    To: basicstamps@egroups.com
    Subject: [noparse][[/noparse]basicstamps] Re: BS2 AND/OR/XOR LOGIC


    The AND/OR/ etc work fine for single bits or logical evaluations,
    such as IF (IN5=0) AND (IN2=1) THEN ....

    But they are not bitwise operators. For masking bits you need to use
    & for AND
    | for OR
    ^ for XOR

    such as w0 = w0 ^ %1111

    Good luck,
    -Martin Hebel
    SelmaWare Solutions
    www.selmaware.com

    Southern Illinois University Carbondale
    Electronics Management
    www.siu.edu/~imsasa/elm

    --- In basicstamps@egroups.com, "steve tatum" <swt@p...> wrote:
    > Hello group,
    >
    > I am trying to use AND and XOR logic expressions and am having some
    > difficulty. I've used the following code on another type of micro
    > but it doesn't want to work with the BS2. Can some one take a look
    > at this and tell me the BS2 equilvalent. I know its got to be
    > something simple that I am missing.
    >
    > 'SET I/O PINS (1=OUPUT,0=INPUT)
    > 'THER ARE 8 OUTPUTS AND 8 INPUTS
    >
    > DIRS = $FF00
    >
    > 'SET PIN CONSTANTS
    >
    > PIN0 CON $0001
    > PIN1 CON $0002
    > PIN2 CON $0004
    > PIN3 CON $0008
    > PIN4 CON $0010
    > PIN5 CON $0020
    > PIN6 CON $0040
    > PIN7 CON $0080
    > PIN8 CON $0100
    > PIN9 CON $0200
    > PIN10 CON $0400
    > PIN11 CON $0800
    > PIN12 CON $1000
    > PIN13 CON $2000
    > PIN14 CON $4000
    > PIN15 CON $8000
    >
    > pause 100
    >
    > 'MAIN PROGRAM LOOP
    >
    > BEGIN:
    >
    > 'CODE FOR 1ST OUTPUT (PIN8)
    >
    > FIRST_OUTPUT:
    >
    > W0=INL 'READ THE 8 INPUTS
    > W1=W0 AND PIN0 'IS INPUT 0 ON, MASK ALL OTHERS
    > IF W1=0 THEN FIRST_OFF 'IF NO INPUT TURN OFF OUTPUT, ELSE
    > 'CONTINUE CHECKING FOR THIS OUTPUT
    >
    > W1=W0 AND PIN4 'IS INPUT 4 ON, MASK ALL OTHERS
    > W1=W1 XOR PIN4 'IF INPUT 4 IS ON, MAKE IT LOOK OFF
    > IF W1=0 THEN FIRST_ON 'IF INPUT IS ON TURN ON OUTPUT, ELSE
    > 'CONTINUE CHECKING FOR THIS OUTPUT
    >
    > W1=W0 AND PIN6 'IS INPUT 6 ON
    > IF W1=0 THEN FIRST_OFF 'IF NO INPUT TURN OFF OUTPUT, ELSE
    > 'TURN OUTPUT ON
    >
    > FIRST_ON:
    >
    > OUT8=1 'TURN ON PIN 8 OUTPUT
    > GOTO SECOND_OUTPUT
    >
    > FIRST_OFF:
    >
    > OUT8=0 'TURN OFF PIN 8 OUTPUT
    >
    > SECOND_OUTPUT:
    > '
    > '
    > '
    >
    > GOTO BEGIN
Sign In or Register to comment.