Port 1 is a general I/O port also functioning as IRQ interrupt input pins, a timer A output pin, and a timer V input pin.
Notice that P13 is missing, on the shrink-DIP part, P11 and P12 are also missing
Four registers control its functions:
• Port mode register 1 (PMR1)
• Port control register 1 (PCR1)
• Port data register 1 (PDR1)
• Port pull-up control register 1 (PUCR1)
PMR1 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 PMR1 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.
PCR1 determins the direction of the pin. If a pin is designated as an IO pin in PMR1, setting a bit in PCR1 to 1 makes the corresponding pin an output, setting it to zero makes the corresponding pin an input.
PDR1 simply holds the output data at the port 1 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 PDR1 register.
PUCR1 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.
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 1 and its registers are found in the IO address space and can be accessed using statements like these:
int data; IO.PCR1 = 0x0F; // set P10,P11 and P12 as outputs IO.PUCR1.BYTE = 0x0F; // and turn on the pull ups IO.PDR1.BIT.B5 = 1; // set P15 to 1 data = IO.PDR1.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 PDR1 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.