What exactly does the Z80 PIO do?
It is just a digital parallel I/O port. You can configure the individual port pins as digital inputs or outputs and then use them for whatever you want. If you were to configure a pin as output and connect a LED to it (with proper buffering) the Z80 would be able to turn the LED on and off. If you were to configure a pin as input and connect a push button and appropriate pull-up resistor to it the Z80 would be able to read the state of the push button.

The A/B input selects between either PortA or PortB and the C/D input selects between either the control register or the data register. The control registers are used to configure the ports and the data registers are used to read/write the actual data. So there are 4 possible combinations:


Control register for PORTA
Data register for PORTA
Control Register for PORTB
Data register for PORTB


By connecting these to A0 and A1 one can access the desired register using the address bus by accessing a appropriate memory address. If the least significant bit of the memory address (A0) is 0 then PORTB is selected, if it is 1 then PORTA is selected.
If bit A1 of the memory address is 0 then the data register is selected, otherwise the control register is selected. The other bits of the memory address play no role (although one should take care not to create conflicts with other devices on the memory bus).