keyboard’s data output connects to port 3, bit 0 (noted as
P3.0) and the keyboard clock signal connects to port 3, bit
1 (P3.1). A UART output connects to port 12, bit 7
(P12.7), which routes the signal to another MCU on the
small programmer section of the prototyping board.
This MCU communicates with a host PC via the male
programming USB connector. I chose the Parallax Serial
Terminal (PST) software for debugging and testing.
A PS- 2 keyboard has four connections with a
computer: two wires for +5V and ground; and two wires
to transmit a serial key code and a synchronizing clock
signal (Figure 7). This view looks into the pin (male) end
of a PS- 2 keyboard connector, or at the solder contacts on
a mating female connector. The PSoC 5LP Prototyping Kit
Guide includes a table of pin names, signals, and
descriptions for the PSoC board. Table 1 lists the
keyboard-to-prototyping kit connections you need for this
Software Builds the Project and
Creates the Files
When the PSoC Creator “builds” a project, it creates
and uses many files which at first can seem overwhelming.
Figure 8 shows a portion of the Workspace Explorer area
on the left side of the PSoC Creator window. Because this
project does not use interrupts, all my software went into
the main.c file. Before I wrote any code, I had to decide
how to process the keyboard data and how to handle the
key release code and the shift keys.
July/August 2018 69
FIGURE 5. This SPI_Slave Configure window
appears after a double-click on the SPI function
shown in Figure 4. You may choose the type of
signals for the SPI port, the number of data bits,
and whether the MSB or LSB shifts in first.
FIGURE 6. The SPI advanced configuration window lets you set
the SPI buffer memory size, choose a clock, and set interrupts
if any. The clock refers to a PSoC internal synchronizing clock,
not the clock signal from a PS- 2 keyboard.
Table 1. Keyboard and PSoC Prototyping Kit Connections.
Keyboard Signals PSoC Signals
Name Connector Pin Name Signal Pin Name
+5V In 4 VDD +5V Power J2_01
GND In 3 GND Ground J2_02
Clock Out 5 P3.1 GPIO J2_ 24
Keyboard Data Out 1 P3.0 GPIO J2_ 25
FIGURE 7. The pin connections for a PS- 2 keyboard.
(Viewed looking into the male pins.)
FIGURE 8. Don't
let the list of PSoC
files and folders
You'll only work
with the main.c
file unless you use
an SPI interrupt,
for an ISR.