[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] efficiency of assigning bits

From: E. Weddington
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Thu, 17 Mar 2005 15:22:24 -0700
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

Jamie Morken wrote:

To clear bit 0 and set bits 1,2,3 without disturbing the other bits:

PORTD = (PORTD & ~(_BV(0))) | (_BV(1)|_BV(2)|_BV(3));

Thanks that is working!

Great! (*phew* I didn't test it beforehand.)

I noticed this in the avr-libc usermanual FAQ:


So would it be a good idea (for saving uC time) to convert that above line to 

PORTD = (PORTD & (unsigned char)~(_BV(0))) | (unsigned 
True. Technically one should do that. I wrote the above line rather quickly.

One could also use the <stdint.h> header and do this:

PORTD = (PORTD & (uint8_t)~(_BV(0))) | (uint8_t)(_BV(1)|_BV(2)|_BV(3)));

At least the type names are a little shorter. Note the extra parentheses around 
the 3 bits on the far right.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]