Shop OBEX P1 Docs P2 Docs Learn Events
Easiest approach to binary counting on three output pins? — Parallax Forums

Easiest approach to binary counting on three output pins?

clayexiclayexi Posts: 3
edited 2008-08-04 05:35 in BASIC Stamp
What is the most efficient way to code·three parallel output pins·to count from 000 to 111 (in my case, to drive a·4051 multiplexer and 4028 decoder)?

The way I'm getting this done now seems wasteful.

Low·· mpxA
High·· mpxB
Low·· mpxC
Pause 50

...and then incrementing, and so on.

There has to be a better way, thanks.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-31 23:16
    The Stamps have the ability to access groups of I/O pins as numeric values.· The Stamp Manual gives all the details in the section on memory usage, but OUTA, OUTB, OUTC, OUTD are the four 4-bit groups.· If you use the low order 3 of 4 I/O pins of a group, you can assign a value from 0 to 7 to that group.· For example, if you use I/O pins 8, 9, 10 for your 3 bit value with 8 the least significant bit, you'd just need to say "OUTC = 5" to set all 3 bits at the same time with pin 8 = 1, pin 9 = 0, and pin 10 = 1.

    Somewhere earlier, you'd have to set the direction of the pins.· If you want to keep pin 11 as an input, you could just say "DIRC = %1010".· I think I have that right (0 = output, 1 = input).
  • clayexiclayexi Posts: 3
    edited 2008-08-01 03:23
    Thanks, Mike.

    I have quite a bit of wiring to change, but it will be worth it.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-08-01 16:08
    @Mike it's 1 for output and 0 for input for the BS2 which can be confusing as some other Parallax products use the opposite format.

    Hi Clayexi, using the DIR , OUT and IN registers (under Memory and Variables in the help files) is one of the most powerful set of instructions the BS2 has IMO but seems a little hidden and sparcely documented for the beginner, or maybe I was just slow to latch on.

    Good luck

    Jeff T.
  • clayexiclayexi Posts: 3
    edited 2008-08-04 05:35
    I found more information on DIRS, DIRB, OUTB and others in my Basic Stamp Manual.·During initialization and the subroutines,·they all worked perfect.·My code is cleaning-up good.

    Thanks again, Clayexi
Sign In or Register to comment.