Configure the ports PA, PB, PC, PD and PE of FX2LP as General-Purpose I/O

Question: How to configure the ports PA, PB, PC, PD and PE of FX2LP as general-purpose I/O?

 

Answer:

The EZ-USB FX2LP (CY7C68013A) has up to five eight-pin bidirectional I/O ports Px[0..7], where x is the port (A, B, C, D, or E). When using Ports mode, the bit 0 and 1 of the IFCONFIG register has to be configured to “0”. In Ports mode, all the IO pins are general-purpose I/O ports.  The registers which are important to control and configure the IO ports are the OEx , IOx and the PORTxCFG. Here, x can be A,B,C,D,and E.

An OEx register (where x is A, B, C, D, or E), which sets the input/output direction of each of the 8 pins (0 = input, 1 = output).
An IOx register (where x is A, B, C, D, or E). Values written to IOx appear on the pins which are configured as outputs; values read from IOx indicate the states of the 8 pins, regardless of input/output configuration.
 
Example 1, set IOB to toggle PB0 pin which can be observed using one LED.
   IFCONFIG = 0x00;     // set the ports as general-purpose I/O
   OEB |= 0xFF;           // set PORT B as outputs
   IOB |= 0x01;            // set PB0 high
   EZUSB_Delay(2000); // delay for ~2000 ms
   IOB &= 0x00;           // set PB0 low
 
Example 2, set PA0 pin as high output.
   IFCONFIG = 0x00;     // set the ports as general-purpose I/O
PORTACFG &= 0x00; // set the bit0 of PORTACFG register to “0” as GPIO
   OEA |= 0x01;          // set PA0 as output
   IOA |= 0x01;          // set PA0 high
 
 
The PORTxCFG register selects alternate functions for the I/O pins. Most I/O pins have alternate functions which may be selected using Ports configuration registers (see Table 13-1 through Table 13-9 in the EZ-USB Technical Reference Manual). For more details about the I/O pins of FX2LP, please review the chapter 13 of EZ-USB Technical Reference Manual.