You are here

Using GPIO as a CPU controlled output | Cypress Semiconductor

Using GPIO as a CPU controlled output

Last Updated:

January 31, 2013

In the device editor, configure the GPIO as StdCPU and drive mode other than HighZ or HighZ Analog.  Now the GPIO can be controlled by writing to the appropriate Port Data Register, PRTxDR and by using masking operations.  For example, to control P2[3], the data register is PRT2DR and the mask is 0x08:

In C:
PRT2DR |= 0x08;   // Set P2[3]
PRT2DR &= ~0x08; // Clear P2[3]
PRT2DR ^= 0x08;  // Toggle P2[3]

In Assembly:
or reg[PRT2DR], 0x08         ; Set P2[3]
and reg[PRT2DR],~0x08      ; Clear P2[3]
xor reg[PRT2DR], 0x08    ; Toggle P2[3]

If the port that you control also has input pins configured as Pull Up or Pull Down usage of shadow registers is advised.  Refer to the KB article

Read Modify Write Instructions and Shadow Registers?