Accessing AVR microcontroller ports with AVR GCC

All AVR ports have Read-modify-write functionality when used for general I/O functionality. Direction of each separate port pin can be changed. Each pin buffer has symmetric capability with ability to drive and sink source. Pin driver is strong enough to drive LED directly, but it is not recommended to drive even small loads without using proper driver circuit such as transistors. All port pins have internal selectable pull-up resistors. And finally all pins have protection diodes to both VCC and GND rails. Each port of AVR consists of three registers DDRx, PORTx and PINx (where x means port letter). DDRx register selects direction of port pins. If logic one is written to DDRx then port is configured to be as output. Zero means that port is configured as input. If DDRx is written zero and PORTx is written logic “1” then port is configured as input with internal pull-up resistor. Otherwise if PORTx is written to zero, then port is configured as input but pins are set to tri-state and you might need to connect external pull-up resistors. If PORTx is written to logic “1” and DDRx is set to “1”, then port pin is driven high. And if PORTx=0,…

Continue reading