Email: Password: Remember Me | Create Account (Free)
PS/2 Communication Monitor for SBCMON
SBC Hardware: Main | SBC Schematic/Parts List | Technical Details | All pages in PDF format
SBC In-System Programming: Information | VisISP-52 ISP Application
SBCMON Monitor/Operating System: Main Page | Manual
SBCMON-based Software: SBCMON Monitor | Keypad Demo | LCD Echo Demo | Hardware Clock | Software Clock
SBCMON-based PS/2 Software: PS/2 Comm Monitor | PS/2 Keyboard | PS/2 Mouse
ORDER 8052.com SBC: PCB, KIT OR BUILT SBC AVAILABLE FOR PURCHASE

Download PS/2 Communication Monitor for SBCMON

You may download either the source code or the ready-to-use Intel-Hex version of the PS/2 communication monitor. The Intel-Hex version may be loaded into SBCMON's memory using the L or Q commands. Download the source ASM program if you'd like to see the code that makes the program work.

What Does this Program Do?

This program allows a standard PS/2-style keyboard or mouse to be connected to the SBC. All data that is returned by the keyboard or mouse is displayed to the terminal in the form of hexadecimal values. Absolutely no interpretation or modification to the data is made by the program so the data that is displayed is the "raw" data as returned by the keyboard or mouse.

You may press any key in the PC's terminal program in order to exit the program and return to SBCMON.

Concepts Demonstrated by Program

This program demonstrates the following concepts:

  1. Communicating with keyboard or mouse using clock and bidirectional data line.
  2. Utilizing the PS/2 communication protocol.
Additional Required Hardware

This program requires a PS/2 keyboard or mouse to be connected to the SBC. The keyboard requires a +5V power supply, ground, and the program assumes that the keyboard data line is attached to P1.3 and the clock line is attached to P1.2.

I would recommend using an external board to mount a DIN-6 keyboard connector (Digikey part #275-1043-ND). On this board, mount two 8-pin SIP headers. The first SIP header will allow you to attach a ribbon cable from port 1 (J7 on the SBC) and the second SIP header will allow you to attach a ribbon cable from the EX connector (J11). The J7 connector will expose P1.2 and P1.3 while the J11 connector will provide +5V and ground.

Connecting the PS/2 Connector

The PS/2 connector is a female DIN-6 connector. The pinout is pictured to the right. The top graphic shows the pinout when looking at the PS/2 female connector. The bottom portion of the graphic shows the normal pinout of the pins that are connected at a right angle to the PCB. The pins use 0.1" spacing so are very appropriate for a thru-hole circuit board.

Theory of Operation

This program operates on the basis that both the PS/2 keyboard and the PS/2 mouse use the same communication protocol--the only difference is the format of the data returned by the device.

Additionally, the absolute minimum initialization code necessary to make both the keyboard and the mouse work is exactly the same: The 0xFF initialization command must be sent followed by the 0xF4 command which enables reporting from the device. When these two commands are sent to either a PS/2 keyboard or mouse, the device will immediately start returning data via the PS/2 protocol.

As a result, this program simply sends this absolutely minimal initialization sequence and then displays all data that is returned. The program need not know or care whether the device is a keyboard or a mouse since it is only interested in displaying the raw data.

Credits

This example program was based on Gabriel Lour's "keyboard routine" code which was contributed to the 8052.com code library. Modifications were made to his code to make the example program more closely conform to the style of the other SBC example programs. Additionally, the routines were modified so as not to require any specific addresses in internal RAM. Rather, "R" registers are used for temporary variable storage.

Additionally, Gabriel's code deals with the keyboard's scan codes. This example program, on the other hand, takes the 1-3 byte keyboard scan codes and converts them to a a single-byte unique scan code. This makes it much easier to deal with the resulting data in an assembly language program.

Information on the PS/2 connector pin-out and the keyboard scan codes returned by the keyboard were obtained from Adam Chapweske's site.