Declare port twice

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What it happens when i declare a port direction twice?

for example:

 

DDRB = (1<<PB1)|(1<<PB2)|(1<<PB3)

DDRB |= (1<<PB4)

 

i tried and PB4 not working.

if i declare at the first with or too. for example:

 

DDRB |= (1<<PB1)|(1<<PB2)|(1<<PB3)

DDRB |= (1<<PB4)

 

in second case PB4 works fine.

i think the or operator makes much more sense in second part. but i dont understand what's effect takes in first part.

 

 

 

Last Edited: Tue. Dec 16, 2014 - 11:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think we need more context.  Show a complete test program that demonstrates the behavior.  Tell AVR model, toolchain, version, and optimization settings.  Tell how you are testing.  Ideally, show the generated code for the problem area.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the code is really just those two lines in that order (with the proper semicolons), then the first should work just fine. As Lee said, you have to show real code.

 

By the way, you are not "declaring" anything in those lines of code.

Regards,
Steve A.

The Board helps those that help themselves.

Last Edited: Wed. Dec 17, 2014 - 01:15 AM