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 Mouse for SBCMON
You may download either the source code or the ready-to-use Intel-Hex version of the mouse demonstration program. 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 SBCMON work.
-
SBCMON PS/2 Mouse Program Source (ps2mouse.asm)
SBCMON PS/2 Mouse Intel HEX (ps2mouse.hex)
NOTE: This demo program requires SBCMON monitor program to run. Be sure to download SBCMON first, install on your SBC, and then run this demo from within SBCMON itself. This program may require additional modification in order to run without SBCMON.
This program allows a standard PS/2-style mouse to be connected to the SBC. Movements of the mouse and mouse clicks are detected by the program and the information is displayed to the terminal.
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:
- Communicating with mouse using clock and bidirectional data line.
- Utilizing the mouse's communication protocol.
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
The routines used in this example program can best be summarized as follows:
-
PS2_MouseInit: Initializes the mouse.
PS2_GetByte: This reads a single byte from the mouse. If the mouse has no data pending, it clears the carry which indicates no data was read. If the mouse has data pending, it is returned in the accumulator and the carry bit is set. Note that this will return one byte and that a single mouse movement generates three bytes of data.
PS2_GetMouse: Like PS2_GetByte, this routine will clear the carry if there is no data waiting and set the carry flag if data was returned by the mouse. However, while PS2_GetByte will return a single byte (which is not all the data required to process a single mouse movement), PS2_GetMouse will read three bytes of data as necessary to obtain a full data packet from the mouse.
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.