[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-chat] HELP! mega128 USART receive restarts execution
From: |
David Kelly |
Subject: |
Re: [avr-chat] HELP! mega128 USART receive restarts execution |
Date: |
Sun, 12 Feb 2006 12:46:06 -0600 |
On Feb 12, 2006, at 11:35 AM, Rick Mann wrote:
On Feb 12, 2006, at 7:10 AM, Larry Barello wrote:
You don't want to use '!' to negate a bit mask; That isn't doing
what you
think it is. You want to use '~'
I must disagree with you here. '!' results in a non-zero byte
becoming 0. '~' (bitwise complement) results in all the 0 bits
becoming 1 and all the 1 bits becoming 0. If I used '~', then I'd
end up with all the bits in the result set ('1').
copied from earlier message:
UCSR0B = _BV(RXCIE0)
| !_BV(TXCIE0)
| !_BV(UDRIE0)
| _BV(RXEN0)
| _BV(TXEN0)
| !_BV(UCSZ02);
in avr/sfr_defs.h:
#define _BV(bit) (1 << (bit))
in avr/iom128.h:
#define TXCIE0 6
So !_BV(TXCIE0) is !(1<<6) which is usually nonsense and why Larry
got tripped on it.
If I were writing the code, first off I would NOT use _BV(). Its a
crutch which hides what is really being done and anyone worth their
salt will instantly recognize (1<<TXCIE0).
The other thing is that I'd either list all the bits on separate
lines as above, but comment out the 0's. Or I'd only list the bits
I'm setting:
UCSR0B = (1<<RXCIE0) | (1<<RXEN0) | (1<<TXEN0);
Another thing I sometimes do to make it positively obvious that I
want a zero in a particular bit, while leaving it easy to toggle that
bit in the future:
UCSR0B = (1<<RXCIE0) | (0<<TXCIE0) | (0<<UDRIE0)
| (1<<RXEN0) | (1<<TXEN0) | (0<<UCSZ02);
If starting from scratch I usually write something like this:
#define TXCIE0_b (6)
#define TXCIE0_m (1<<TXCIE0_b)
--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.