While we're on this topic, I'll add in my own "grievance".
>> #define setbit(ADDRESS,BIT) ((ADDRESS) |= (1<<(BIT)))
>> #define clrbit(ADDRESS,BIT) ((ADDRESS) &= ~(1<<(BIT)))
I use sbi() and cbi() for this, pretty much the same thing as the setbit()
and clrbit() described by Svenn. I think sbi & cbi are built into
avr-gcc, but I'm not sure if they're deprecated or what not. Either way,
they work fine for me.
The thing I dont like is having a separate command (function, macro,
whatever) for setting and clearing. So in my code there's lots of things
like...
<code>
if (turn_motor_on) {
setbit(MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN);
} else {
clrbit(MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN);
}
</code>
Personally, I would prefer something like.....
<code>
write_bit(turn_motor_on, MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN);
</code>
And that magic command "write_bit()" will use the proper sbi or cbi based
upon the value of the "turn_motor_on" flag.
Is there something easily usable to achieve this functionality?
Ethan
www.bufbotics.orgMessage
Re: [AVR-Chat] accessing bits (e.g. of ports)
2005-01-31 by ethan@bufbotics.org
Attachments
- No local attachments were found for this message.