Shop OBEX P1 Docs P2 Docs Learn Events
Setting/Resetting multiple Port Bits — Parallax Forums

Setting/Resetting multiple Port Bits

MonotobaMonotoba Posts: 9
edited 2012-10-08 16:50 in Propeller 1
Hi all,

Does the OUTA command in propgcc allow for multiple bits to be set all at once?

For example, I see demo code that sets a single bit like this:

DIRA |= (1 << pin10);

OUTA |= (1 << pin) //Set pin (hi);

OUTA &= ~(1<< pin) // Reset pin (lo);


But is it possible to do something like this?:

void write_byte(unsigned char value) {
#define PORT_MASK = (255 < 10);

unsigned int tmp;
tmp = (value<<10); // Shift value into proper position

DIRA |= PORT_MASK; // Set port to output

OUTA &= ~PORT_MASK; // Reset all port pins
OUTA |= (~(PORT_MASK) | tmp) // Now set only the needed port pins to store value, without changing other pins....

}

Or must I write a function/method to write each pin value of the data port separately?

Comments

  • jac_goudsmitjac_goudsmit Posts: 418
    edited 2012-10-08 05:04
    OUTA, DIRA and the other pseudo-registers are nothing but 32-bit memory locations, you can set and reset as many bits as you want, in the same way as you would set or reset bits in an integer variable. You don't strictly need to write a function/method to change DIRA/OUTA but it might be a useful thing to do to make your program readable, and easier to maintain.

    In other words: all the code in your posting will work as expected.

    ===Jac
  • MonotobaMonotoba Posts: 9
    edited 2012-10-08 16:50
    Thanks for the explanation. I'm planning on writing a graphics and touch screen libraries in C/C++ for the Adafruit #335 TFTLCD-w/Touch Screen. I hope to be able to produce a simple GUI for use in programmable intervalometer project. But my C/C++ skills are very rusty.

    I had written a function to write the byte value to the port but was getting weird results. It turned out to be an issue in another function over writing my data on the port. But having you confirm what I suspected to be the case made it plain something else was wrong.

    Thanks again!


    OUTA, DIRA and the other pseudo-registers are nothing but 32-bit memory locations, you can set and reset as many bits as you want, in the same way as you would set or reset bits in an integer variable. You don't strictly need to write a function/method to change DIRA/OUTA but it might be a useful thing to do to make your program readable, and easier to maintain.

    In other words: all the code in your posting will work as expected.

    ===Jac
Sign In or Register to comment.