Macro_definitions_for_Digital_Port - renesas/Arduino GitHub Wiki

Macro definitions for Digital Port

Macro definitions for Digital Port can be used to control the Digital Port of the RL78 board.

Methods

digitalPinToPort(pin)

  • Returns the port number corresponding to the specified pin.

    • Example : If argument = 0, returns 0 for P03.
  • Parameters

    • pin : Pin number of RL78
  • returns

    • The port number corresponding to the specified pin
      β€» If a pin other than the available pins is specified, 255 is returned.
  • Example

    • Obtain the port number of pin 0.
    uint8_t port;
    port = digitalPinToPort(0);

digitalPinToBitMask(pin)

  • Returns the bitmask corresponding to the specified pin.

    • Example : If argument = 0, returns 0x08, the bit mask value of P03.
  • Parameters

    • pin : Pin number of RL78
  • returns

    • The bitmask corresponding to the specified pin
      β€» If a pin other than the available pins is specified, 255 is returned.
  • Example

    • Obtain the bit mask value of pin 0.
    uint8_t mask;
    mask = digitalPinToBitMask(0);

portOutputRegister(port)

  • Returns the address of the Port Register (Pxx) corresponding to the specified port.

  • The port register is an 8-bit register that sets the output of the pin for each bit and outputs a HIGH level when set to 1 and a LOW level when set to 0.

  • When using this macro, it must be set to digital output mode by portModeRegister() or pinMode() in advance.

  • Parameters

    • port : Port of RL78
  • returns

    • The address of the Port Register (Pxx) corresponding to the specified port
      β€» If a port other than the available ports is specified, NULL is returned.
  • Example

    • Obtain the address of the port register (P00).
    uint8_t * reg;
    reg = portOutputRegister(0);

portInputRegister(port)

  • Returns the address of the Port Register (Pxx) corresponding to the specified port.

  • The port register is an 8-bit register that allows the input value of the pin to be read out bit by bit. If the value read is 1, the level is HIGH; if the value is 0, the level is LOW.

  • When using this macro, it must be set to digital input mode by portModeRegister() or pinMode() in advance.

  • Parameters

    • port : Port of RL78
  • returns

    • The address of the Port Register (Pxx) corresponding to the specified port
      β€» If a port other than the available ports is specified, NULL is returned.
  • Example

    • Obtain the address of the port register (P00).
    uint8_t * reg;
    reg = portInputRegister(0);

portModeRegister(port)

  • Returns the address of the Port Mode Register (PMxx) corresponding to the specified port.

  • The port mode register sets the input/output mode of the pin in 1-bit increments; setting 0 sets the pin to output mode and setting 1 sets the pin to input mode.

  • Some pins have analog or other functions enabled at reset, so settings using this macro will be invalid. To correctly set them to digital I/O mode, pinMode() should be used.

  • Parameters

    • port : Port of RL78
  • returns

    • The address of the Port Mode Register (PMxx) corresponding to the specified port
      β€» If a port other than the available ports is specified, NULL is returned.
  • Example

      1. Obtain the address of the port mode register of port 0.
    uint8_t * reg;
    reg = portModeRegister(0);
      1. Output HIGH/LOW on pin 2 in output mode.
    uint8_t pin = 2;
    uint8_t port;
    uint8_t mask;
    
    port = digitalPinToPort(pin);
    mask = digitalPinToBitMask(pin);
    
    *portModeRegister(port) &= ~(mask); // or pinMode(pin, OUTPUT);  //Output Mode
    *portOutputRegister(port) |= mask; // Output High Level
    delay(1000);
    *portOutputRegister(port) &= ~(mask); // Output Low Level
    delay(1000);
    1. Input mode for pin 3 and read out the input status of the pin.
    uint8_t pin = 3;
    uint8_t port;
    uint8_t mask;
    uint8_t level;
    
    port = digitalPinToPort(pin);
    mask = digitalPinToBitMask(pin);
    
    *portModeRegister(port) |= mask; // or pinMode(pin, INPUT);  //Input Mode
    level = *portInputRegister(port) & mask; // Input pin
    if(level == 0)
    {
      // Low Level
    }
    else
    {
      // High Level
    }
⚠️ **GitHub.com Fallback** ⚠️