Is it possible to use an AVR port as a variable?

Is it possible to use an AVR port as a variable?

Is it possible to use an AVR port as a variable which can be passed around? I would like to make LED be able to take any PORT / Pin combination, so I would rather not hard code it in.

How to pass a port as a variable in C + +?

However, the compiler will not generate the most efficient code this way — it will use indirect addressing instead of direct writes. This is what I do instead, using avrlib. Then you can use the led_pin typedef, e.g.

Can you assume DDR # will always be & port-1?

This would involve finding the relative DDR# register for the Given PORT#. Can I assume &DDR# will always be &PORT#-1? The register macros are basically pointers to the memory location, where the appropriate register resides, so yes, you can use uint8_t volatile *.

How does Porta resolve the dereferencing of a pointer?

PORTA resolves, as you already mentioned, to the dereferencing of a pointer: Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers.

How to access input / output ports in Atmel AVR?

2.1 Blink LED on PB0 at a rate of 1Hz. 2.2 Blink LEDs on PB with different patterns according to given input. NOTE : I will frequently refer to ‘configuring pin’ or simply ‘pin’. Remember, a port has multiple pins. Thus in order to change setting for one port, you have to change setting for all port pins of that port.

Which is the best tutorial for AVR microcontroller?

To get quick background about AVR microcontrollers, refer to Intoduction to AVR Tutorial on this blog. 2 Hands on … 2.1 Blink LED on PB0 at a rate of 1Hz. 2.2 Blink LEDs on PB with different patterns according to given input.

How does DDRx read data from port pins?

Writing 0 to a bit in DDRx makes corresponding port pin as input, while writing 1 to a bit in DDRx makes corresponding port pin as output. PINx (Port IN) used to read data from port pins. In order to read the data from port pin, first you have to change port’s data direction to input. This is done by setting bits in DDRx to zero.