Verilog-based PS/2 interface control program

1. Main Content of the Example

This example demonstrates how to control the keyboard, LCD, and RS-232 interface on the Red Hurricane II Xilinx development board using Verilog programming. The input from the keyboard is displayed on the LCD or sent via the RS-232 port to a PC, where it appears in HyperTerminal. This project provides hands-on experience with interfacing peripheral devices using hardware description language.

2. Example Objectives

Through this example, readers should be able to:

  • Understand the PS/2 interface protocol.
  • Grasp the working mechanism of a keyboard.
  • Write a Verilog program to read keyboard input through the PS/2 interface.
Principle Introduction

The PS/2 keyboard uses a two-way synchronous serial communication protocol. Data is transferred one bit at a time over the data line, synchronized by pulses on the clock line. While the keyboard can send data to the host, the host always has priority and can interrupt communication by pulling the clock line low.

To implement this in Verilog, it’s essential to understand the structure and pin definitions of the PS/2 interface, as shown in Table 1.

Table 1: PS/2 Port Structure and Pin Definition

Table 1 PS/2 port structure and pin definition

As seen, the PS/2 interface has only one data line. To identify which key is pressed, the keyboard's processor continuously scans the key matrix. When a key is pressed, released, or held, it sends a scan code to the computer.

There are two types of scan codes: "make codes" for key presses and "break codes" for key releases. Each key has a unique make and break code. Additionally, some keys are extended, and their scan codes are prefixed with "E0". When released, these keys send "E0F0" before the actual code.

The signal transmission follows a specific timing sequence. The keyboard checks if both the data and clock lines are high before sending data. Data is read on the falling edge of the clock signal.

Each frame consists of 11 bits: a start bit (0), 8 data bits (LSB to MSB), a parity bit, and a stop bit (1). A timing diagram of this protocol is shown in Figure 2.

Figure 2 keyboard serial protocol

Figure 2: Keyboard Serial Protocol

Detailed Example

Here are the main steps to implement the project:

  1. Launch the ISE software.
  2. Create a new project.
  3. Implement the PS/2 serial protocol in Verilog based on the timing diagram in Figure 2.
  4. Add the design to the project and connect the interface logic with the system.
  5. Set device and pin constraints according to the development board specifications.
  6. Download the design to the board and test it.

After downloading the program, connect the keyboard to the development board. You should see the characters typed on the LCD display. This real-time feedback helps verify that the Verilog code is correctly capturing and processing keyboard input.

This example not only enhances understanding of digital communication protocols but also provides practical experience in designing and testing embedded systems using FPGAs.

Solar Engergy System

Solar energy system, off gird pv system, grid pv system, solar power system, Solar Panel system, on grid solar system, grid tied solar system,20kw solar system


Solar energy system include Solar photovoltaic system: 1. Off grid photovoltaic system mainly consists of solar modules, controllers, and batteries. To supply power to AC loads, it is also necessary to configure an AC inverter. 2. Grid connected photovoltaic power generation system. 3. Distributed photovoltaic power generation system. Distributed power generation or distributed energy supply.


solar cell type mono crystalline, half cut cell
solar energy pv system include on grid system, off grid system, hybrid system
solar configuration solar panel, inverter, battery, bracket cabels, mc4 connector



Product details and pic

Complete Off Grid Solar SystemOff Gird System 1 Jpg


Solar Engergy System,Gird Solar Power System,Pv System For Carport,Energy System Off Grid Solar System

PLIER(Suzhou) Photovoltaic Technology Co., Ltd. , https://www.pliersolar.com