I have a question related to AVR microcontrollers using AVR-GCC and CodeVision:
Normally we set the port related registers inside the main function using DDRx/PORTx registers, for example like this:

DDRB = 0x00;
PORTB = 0x00;

How can I change the content of these registers in other places of the program?

And another question, is it wise to set DDRx and PORTx registers using the following way:

  • \$\begingroup\$ This question would take too much introductory material to explain since you don't even understand this is a processor-specific question. \$\endgroup\$ Jul 29, 2013 at 11:07
  • \$\begingroup\$ What introductory material? \$\endgroup\$ Jul 29, 2013 at 16:20
  • \$\begingroup\$ Exactly. ------ \$\endgroup\$ Jul 29, 2013 at 18:15

1 Answer 1


Exactly the same way; there is no intrinsic difference between performing the assignment at any point in your code.

I have no experience with Codevision, but I can't imagine that performing a bitfield assignment that way would not be translated to the appropriate opcodes, the same way as if one were to perform a bitwise operation against the entire register in C.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.