Assigning bit values from a nibble value to an output pin
Gerry Shand
Posts: 45
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
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
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
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.