Macro_definitions_for_Digital_Port - renesas/Arduino GitHub Wiki
Macro definitions for Digital Port can be used to control the Digital Port of the RL78 board.
-
Returns the port number corresponding to the specified pin.
- Example : If argument = 0, returns 0 for P03.
-
- pin : Pin number of RL78
-
- The port number corresponding to the specified pin
β» If a pin other than the available pins is specified, 255 is returned.
- The port number corresponding to the specified pin
-
- Obtain the port number of pin 0.
uint8_t port; port = digitalPinToPort(0);
-
Returns the bitmask corresponding to the specified pin.
- Example : If argument = 0, returns 0x08, the bit mask value of P03.
-
- pin : Pin number of RL78
-
- The bitmask corresponding to the specified pin
β» If a pin other than the available pins is specified, 255 is returned.
- The bitmask corresponding to the specified pin
-
- Obtain the bit mask value of pin 0.
uint8_t mask; mask = digitalPinToBitMask(0);
-
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.
-
- port : Port of RL78
-
- 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.
- The address of the Port Register (Pxx) corresponding to the specified port
-
- Obtain the address of the port register (P00).
uint8_t * reg; reg = portOutputRegister(0);
-
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.
-
- port : Port of RL78
-
- 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.
- The address of the Port Register (Pxx) corresponding to the specified port
-
- Obtain the address of the port register (P00).
uint8_t * reg; reg = portInputRegister(0);
-
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.
-
- port : Port of RL78
-
- 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.
- The address of the Port Mode Register (PMxx) corresponding to the specified port
-
-
- Obtain the address of the port mode register of port 0.
uint8_t * reg; reg = portModeRegister(0);
-
- 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);
-
-
- 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 }