Shop OBEX P1 Docs P2 Docs Learn Events
Assigning bit values from a nibble value to an output pin — Parallax Forums

Assigning bit values from a nibble value to an output pin

Gerry ShandGerry Shand Posts: 45
edited 2012-12-19 19:55 in BASIC Stamp
Hi All:

Trying to do some control here where I have four pins as outputs. The output values (0 or 1) are based on the value of the nibble which is changed by the program code. Here is what I have tried without any success:

'
'DEFINE PINS
'

Column3 = OUT14 'COLUMN D BIT (OP)
Column2 = OUT13 'COLUMN C BIT (OP)
Column1 = OUT12 'COLUMN B BIT (OP)
Column0 = OUT11 'COLUMN A BIT (OP)


'
'DEFINE VARIABLES
'

Column VAR Nib 'NIBBLE VALUE FOR COLUMN

Column3 VAR Column.BIT3
Column2 VAR Column.BIT2
Column1 VAR Column.BIT1
Column0 VAR Column.BIT0

'
'INITIALIZATION
'

DIRS=%1111111111000000 '1 = OUTPUT
PAUSE 100 '100 MS PAUSE TO WAIT FOR THINGS TO SETTLE DOWN

No luck. Tried a few other things and no success. Any tips?

Thanks. Normally I don't get stumped by the Stamp but in this case I have.

Regards,

Gerry

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-19 19:19
    Can't provide tips without some information about what you're trying to accomplish, what you mean by success, and what happens when you do something. Otherwise, we're just guessing. A real program would be helpful as well as what you've got connected to the relevant I/O pins.
  • Gerry ShandGerry Shand Posts: 45
    edited 2012-12-19 19:28
    The program changes the value of the nibble between 0 - 15. That value gets translated to a binary value between 0000 and 1111. When one of these bits is 1, the corresponding pin output should go high and turn on a light. When that same bit goes to zero, that pin output will go low and the light will go off. In this case, the lights are LEDs so we do not have a current deficit on the power supply. I am pulling less than 1 mA per output pin using a transistor based driver. So far, the values in the program do not translate to pin outputs on the stamp based on my debug functions.

    So somehow the bit values in the nibble are not getting through to the pins assigned as outputs via the DIRS register.

    Hope this provides the additional information you need.

    Thanks,

    Gerry
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-19 19:55
    I see a couple of things:

    1) You have a section labelled DEFINE PINS. It may say that, but it doesn't do it. Look up the PIN declaration in the Basic Stamp Syntax and Reference Manual.

    2) You have DIRS=%1111111111000000 '1 = OUTPUT in the INITIALIZATION section. This sets I/O pins 6-15 to output mode which includes I/O pins 11-14. Good!

    3) Nowhere do you set OUTS or individual I/O pins 11-14 to high to turn on the LEDs.

    4) Look at the "memory architecture" section of the Reference Manual. You'll see that there are pre-defined nibbles for groups of 4 I/O pins. They're all aligned on 4-bit multiples and that doesn't fit what you have so you'll have to deal with one I/O pin at a time. You could use shifts and bit logical operations (&, |, !) to take a 4-bit nibble and copy it into the proper spot in OUTS (bits 11-14), but it might be easier to just change to use I/O pins 12-15 and use OUTD.

    As you'll learn when you read the Reference Manual, I/O consists of 3 different registers. One is INS which represents the current state of the 16 I/O pins as a 16-bit word. The next is DIRS which specifies the mode of the 16 I/O pins as input or output. The last is OUTS which holds the output state of the 16 I/O pins should they be put into output mode. There is a whole bunch of aliases for portions of these registers as single bits, 4-bit nibbles, and 8-bit bytes.
Sign In or Register to comment.