Microchip® Advanced Software Framework

Advanced use case doing port access

In this case we will read out the pins from one whole port and write the read value to another port.

Setup steps

Example code

#define IN_PORT IOPORT_PORTA
#define OUT_PORT IOPORT_PORTB
#define MASK 0x00000060

Workflow

  1. It's useful to give the ports symbolic names:
    • #define IN_PORT IOPORT_PORTA
      #define OUT_PORT IOPORT_PORTB
    • Note
      The port names differ between architectures:
      • MEGA_RF, MEGA and XMEGA: There are predefined names for ports: IOPORT_PORTA, IOPORT_PORTB ...
      • UC3: Use the index value of the different IO blocks: 0, 1 ...
      • SAM: There are predefined names for ports: IOPORT_PIOA, IOPORT_PIOB ...
  2. Also useful to define a mask for the bits to work with:
    • #define MASK 0x00000060
  3. Initialize the ioport service. This typically enables the IO module if needed.
  4. Set one of the ports as input:
  5. Set the other port as output:

Usage steps

Example code

value = ioport_get_port_level(IN_PORT, MASK);
ioport_set_port_level(OUT_PORT, MASK, value);

Workflow

  1. Define a variable for port date storage:
  2. Read out from one port:
  3. Put the read data out on the other port: