NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » PORTD|=_BV(1);

June 06, 2011
by Snoogie2563
Snoogie2563's Avatar

Hi all,

Can someone explain to me what the line of code I have placed in the subject line means. Specifically, what I don't understand is the _BV().

Thanks for any and all helpwith this.

Respectfully,

Chuck Reel

June 06, 2011
by Ralphxyz
Ralphxyz's Avatar

Hi Chuck, the _BV is referencing a "macro" you can do a Google search for "C Macros" and you can search the Nerdkits forum for "_BV"

to see a lot of discussions.

Ralph

June 06, 2011
by Rick_S
Rick_S's Avatar

That stands for bit value and is the same as saying PORTD |= (1<<1); if it was _BV(4) it would be (1<<4) etc... Just a shortcut that is sometimes used for code compatability or ease of writing or personal preference. I know one of our friends here (Noter) uses this method often. He may be able to explain it better than I. BigGrin

HERE IS A LINK to the avr-libc doc for that.

Rick

June 06, 2011
by Snoogie2563
Snoogie2563's Avatar

Thanks Guys, I saw it used in several code examples I saw in various places, but I never really saw a clear explanation of what it meant.

Post a Reply

Please log in to post a reply.

Did you know that our USB NerdKit works on Windows, Linux, and Mac OS X? Learn more...