Setting/Resetting multiple Port Bits
Monotoba
Posts: 9
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?
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
In other words: all the code in your posting will work as expected.
===Jac
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!