Port 5 is a general I/O port also functioning as an I2C bus interface I/O pin, an A/D trigger input pin, and wakeup interrupt input pin.
The register setting of the I2C bus interface register has priority for functions of the pins P57/SCL and P56/SDA. Since the output buffer for pins P56 and P57 has the NMOS push-pull structure, it differs from an output buffer with the CMOS structure in the high-level output characteristics. The H8/3664N does not have P57 and P56.
PIN | Alternate Function | |
P50 | WKP0 | |
P51 | WKP1 | |
P52 | WKP2 | |
P53 | WKP3 | |
P54 | WKP4 | |
P55 | WKP5/ADTRG | |
P56 | SDA | |
P57 | SCL |
The WKPx and ADTRG functions are active low
Four registers control its functions:
• Port mode register 5 (PMR5)
• Port control register 5 (PCR5)
• Port data register 5 (PDR5)
• Port pull-up control register 5 (PUCR5)
PMR5 determines whether a pin is to me used as a general-purpose IO pin or for one of its alternative functions. Setting a bit in PMR5 to zero configures the corresponding pin to be an IO pin. If the bit is a 1, then the pin is used for its alternative function. Pins P56 and P57 are configured with the IIC settings in register ICCR - not in this register.
PCR5 determines the direction of the pin. If a pin is designated as an IO pin in PMR5, setting a bit in PCR5 to 1 makes the corresponding pin an output, setting it to zero makes the corresponding pin an input.
PDR5 simply holds the output data at the port 5 pins if the pin is configured as an output. Reading a pin while it is configured as an input reads the value at the pin regardless of the value in the PDR5 register.
PUCR5 is used to turn on and off the internal pullups when a pin is configured as an input. Pins configured as outputs have no pullups. Pins P56 and P57 do not have pullups as they use push-pull outputs.
After a reset, this port is configured as all general purpose input pins with no pullups.
Using the header files provided with the GNUH8 toolchain, port 5 and its registers are found in the IO address space and can be accessed using statements like these:
int data; IO.PCR5 = 0x0F; // set P50,P51 and P52 as outputs IO.PUCR5.BYTE = 0x0F; // and turn on the pull ups IO.PDR5.BIT.B5 = 1; // set P55 to 1 data = IO.PDR5.BIT.B2; // read a single bit into an integer variable
You should note that the final statement may not really read the individual bit - it simply reads the whole of PDR5 into data if the optimisation level is anything other than none. Thus you should treat the answer with a little care. The compiler can be trusted to a degree since the optimiser will mask subsequent access to the variable to ensure that the required bit is used.