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:
DDRB.0=0;
PORTB.0=1;
-
\$\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– Olin Lathrop2013年07月29日 11:07:58 +00:00Commented Jul 29, 2013 at 11:07
-
\$\begingroup\$ What introductory material? \$\endgroup\$Rozeh Tiyan– Rozeh Tiyan2013年07月29日 16:20:47 +00:00Commented Jul 29, 2013 at 16:20
-
\$\begingroup\$ Exactly. ------ \$\endgroup\$Olin Lathrop– Olin Lathrop2013年07月29日 18:15:17 +00:00Commented 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.