18.3.2.1 Basic Functions
Each pin group x has its own set of PORT registers. I/O pin Pxn can be controlled by the registers in PORTx.
To use pin number n as an output, write bit n of the PORTx.DIR register to
‘1
’. This can be done by writing bit n in the PORTx.DIRSET register to
‘1
’, which will avoid disturbing the configuration of other pins in
that group. The nth bit in the PORTx.OUT register must be written to the desired
output value.
Similarly, writing a PORTx.OUTSET bit to ‘1
’ will set the
corresponding bit in the PORTx.OUT register to ‘1
’. Writing a bit in
PORTx.OUTCLR to ‘1
’ will clear that bit in PORTx.OUT to
‘0
’. Writing a bit in PORTx.OUTTGL or PORTx.IN to ‘1
’
will toggle that bit in PORTx.OUT.
To use pin n as an input, bit n in the PORTx.DIR register must be written to
‘0
’ to disable the output driver. This can be done by writing bit n in
the PORTx.DIRCLR register to ‘1
’, which will avoid disturbing the
configuration of other pins in that group. The input value can be read from bit n in the
PORTx.IN register as long as the ISC bit is not set to INPUT_DISABLE.
Writing a bit to ‘1
’ in PORTx.DIRTGL will toggle that bit in
PORTx.DIR and toggle the direction of the corresponding pin.