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\$ – Olin Lathrop Jul 29 '13 at 11:07
  • \$\begingroup\$ What introductory material? \$\endgroup\$ – Rozeh Tiyan Jul 29 '13 at 16:20
  • \$\begingroup\$ Exactly. ------ \$\endgroup\$ – Olin Lathrop Jul 29 '13 at 18:15

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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