title: AVR Basics date: 2021-01-13 categories: [cheatsheets, embedded]
This register is used to tell if a output PIN is used as input or output.
The register looks like this
| Bit No. | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Name | DDx7 | DDx6 | DDx5 | DDx4 | DDx3 | DDx2 | DDx1 | DDx0 |
| Init. | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
The register can be set like this:
// E.g. for Port C
DDRC = (1<<DDC0)|(1<<DDC4)|(1<<DDC5)|(1<<DDC7);
// the same as
DDRC = 0x1B;
// in Binary: 0b10110001
That means:
PINs marked as Input Pins have the capability to read the voltage-level at that PIN. In contrast, PINs marked as Output Pins can be set to either HIGH or LOW.
This Register determines whether the output of the corresponding output pins should be HIGH or LOW.
The register looks like this
| Bit No. | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Name | Px7 | Px6 | Px5 | Px4 | Px3 | Px2 | Px1 | Px0 |
| Init. | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Set the PINS:
PORTC = (1<<PD0)|(1<<PD3)|(1<<PD6);
Info: PORTx
can only modify the PINS that are marked as output pins with DDRx
.
In contrast to the PORTx
register, this register is used to read the state of the corresponding pin x
.
```
| Bit No. | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | Name | Px7 | Px6 | Px5 | Px4 | Px3 | Px2 | Px1 | Px0 | | Init. | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
To read the PINS state:
```C
if (PINC == 0b01000000)
PORTC = 0x0B;
else
PORTC = 0x00
Info: As already noted aboved, PINx
can only read the PINS that are marked as input pins with DDRx
.