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 » #define BUT_UP PORTB5

June 16, 2010
by n3ueaEMTP
n3ueaEMTP's Avatar

Quick Question & I think I know the answer but I want to make sure. Does #define BUT_UP PORTB5 mean that I can use BUT_UP in place of PB5 in if statements? For Example, when using the #define statement is:

if (PINB & ((1<<BUT_UP) == 0)

the same as

if (PINB & ((1<<PB5) == 0)

Thanks in advance for an help.

Chris B. n3ueaEMTP

June 16, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Chris,

I think the answer to your question is yes. The #define is a preprocessor directive. Which means that if I do

#define FOO bar

It will take your C code and replace all occurrences of FOO in your code with bar, literally without interpreting either FOO or bar. Your example is not quite right because you said #define BUT_UP PORTB5, but I think you meant #define BUT_UP PB5, which would be correct.

Humberto

June 16, 2010
by n3ueaEMTP
n3ueaEMTP's Avatar

Humberto, thanks for the information. I "borrowed" that code from the internet for a project. I decided to repalce the BUT_UP with PC5. That's what is in the NK guidebook so I just stuck with what I know.

Thanks for the response!

Chris B

Post a Reply

Please log in to post a reply.

Did you know that essentially all power supplies' voltages drop when current is drawn from them? Learn more...