AVR has four ports.
- Port A, Port B, Port C, Port D.
- AVR is a 8bit.
- Port pins can be access by.
- Bit instruction.
- Byte instruction.
- In bit instruction each port pins value assigned individually.
- Example: In port0 3rd pin should keep high and 4th pin should keep low it can be done in this way.
- P0_3=1; (High) // Port0 3rd pin
- P0_4=0; (Low) // Port0 4th pin
- In byte instruction we can access entire port pins.
- In port0 all pin should keep low.
- P0 = 0x00;
0x 0 | 0 = 0x00.
- In port 0 MSB should keep high and LSB should keep low.
0x F | 0 = 0xF0.
- P0 = 0x00;
- AVR Digital I/O ports is associated with three (3) I/O register.
- They are.
1. Data Direction Register (DDRx).
2. Port X Input Pins Register (PINx).
3. Port Register (PORTx).
Data Direction Register (DDRx)
- DDRx is an 8-bit register.
- It is used to set the pin as an input or output
1. if DDRX is set to 1 it acts as an output pin,
2. if DDRX is set to 0 it acts as an input pin,
Port A 0th pin act as input.
Port X Input Pins Register (PINx)
- PINx is an 8-bit register.
- It stores the logic value, the current state of the physical pins on Portx.
- To read the values on the pins of Portx.
- Must read the values that are in its PIN register.
Port Register (PORTx)
- PORTx is an 8-bit register.
- It stores the logic value, the current state of the Portx.